add to basic editor and update advanced style

This commit is contained in:
Zack 2022-03-16 17:25:08 -05:00
parent 29119db5ce
commit 94ebb63589
3 changed files with 132 additions and 40 deletions

View File

@ -1,3 +1,5 @@
import "../../../components/ha-expansion-panel";
import "@material/mwc-formfield/mwc-formfield";
import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { css, html, LitElement, PropertyValues, TemplateResult } from "lit"; import { css, html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
@ -5,6 +7,7 @@ import { computeDomain } from "../../../common/entity/compute_domain";
import "../../../components/ha-area-picker"; import "../../../components/ha-area-picker";
import "../../../components/ha-switch"; import "../../../components/ha-switch";
import "../../../components/ha-textfield"; import "../../../components/ha-textfield";
import "../../../components/ha-radio";
import type { HaSwitch } from "../../../components/ha-switch"; import type { HaSwitch } from "../../../components/ha-switch";
import { import {
DeviceRegistryEntry, DeviceRegistryEntry,
@ -33,6 +36,8 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
@state() private _disabledBy!: string | null; @state() private _disabledBy!: string | null;
@state() private _hiddenBy!: string | null;
private _deviceLookup?: Record<string, DeviceRegistryEntry>; private _deviceLookup?: Record<string, DeviceRegistryEntry>;
@state() private _device?: DeviceRegistryEntry; @state() private _device?: DeviceRegistryEntry;
@ -51,6 +56,12 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
) { ) {
params.disabled_by = this._disabledBy; params.disabled_by = this._disabledBy;
} }
if (
this.entry.hidden_by !== this._hiddenBy &&
(this._hiddenBy === null || this._hiddenBy === "user")
) {
params.hidden_by = this._hiddenBy;
}
try { try {
const result = await updateEntityRegistryEntry( const result = await updateEntityRegistryEntry(
this.hass!, this.hass!,
@ -101,6 +112,7 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
this._origEntityId = this.entry.entity_id; this._origEntityId = this.entry.entity_id;
this._entityId = this.entry.entity_id; this._entityId = this.entry.entity_id;
this._disabledBy = this.entry.disabled_by; this._disabledBy = this.entry.disabled_by;
this._hiddenBy = this.entry.hidden_by;
this._areaId = this.entry.area_id; this._areaId = this.entry.area_id;
this._device = this._device =
this.entry.device_id && this._deviceLookup this.entry.device_id && this._deviceLookup
@ -138,37 +150,95 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
.placeholder=${this._device?.area_id} .placeholder=${this._device?.area_id}
@value-changed=${this._areaPicked} @value-changed=${this._areaPicked}
></ha-area-picker> ></ha-area-picker>
<div class="row">
<ha-switch <ha-expansion-panel
.checked=${!this._disabledBy} .header=${this.hass.localize(
@change=${this._disabledByChanged} "ui.dialogs.entity_registry.editor.advanced"
> )}
</ha-switch> outlined
<div> >
<div> <div class="label">
${this.hass.localize( ${this.hass.localize(
"ui.dialogs.entity_registry.editor.view_status"
)}:
</div>
<div class="secondary">
${this._disabledBy && this._disabledBy !== "user"
? this.hass.localize(
"ui.dialogs.entity_registry.editor.enabled_cause",
"cause",
this.hass.localize(
`config_entry.disabled_by.${this._disabledBy}`
)
)
: ""}
</div>
<div class="row">
<mwc-formfield
.label=${this.hass.localize(
"ui.dialogs.entity_registry.editor.enabled_label" "ui.dialogs.entity_registry.editor.enabled_label"
)} )}
</div> >
<div class="secondary"> <ha-radio
${this._disabledBy && this._disabledBy !== "user" name="hiddendisabled"
? this.hass.localize( value="enabled"
"ui.dialogs.entity_registry.editor.enabled_cause", .checked=${!this._hiddenBy && !this._disabledBy}
"cause", .disabled=${(this._hiddenBy && this._hiddenBy !== "user") ||
this.hass.localize( this._device?.disabled_by ||
`config_entry.disabled_by.${this._disabledBy}` (this._disabledBy && this._disabledBy !== "user")}
) @change=${this._viewStatusChanged}
) ></ha-radio>
: ""} </mwc-formfield>
${this.hass.localize( <mwc-formfield
"ui.dialogs.entity_registry.editor.enabled_description" .label=${this.hass.localize(
"ui.dialogs.entity_registry.editor.hidden_label"
)} )}
<br />${this.hass.localize( >
"ui.dialogs.entity_registry.editor.note" <ha-radio
name="hiddendisabled"
value="hidden"
.checked=${this._hiddenBy !== null}
.disabled=${(this._hiddenBy && this._hiddenBy !== "user") ||
Boolean(this._device?.disabled_by) ||
(this._disabledBy && this._disabledBy !== "user")}
@change=${this._viewStatusChanged}
></ha-radio>
</mwc-formfield>
<mwc-formfield
.label=${this.hass.localize(
"ui.dialogs.entity_registry.editor.disabled_label"
)} )}
</div> >
<ha-radio
name="hiddendisabled"
value="disabled"
.checked=${this._disabledBy !== null}
.disabled=${(this._hiddenBy && this._hiddenBy !== "user") ||
Boolean(this._device?.disabled_by) ||
(this._disabledBy && this._disabledBy !== "user")}
@change=${this._viewStatusChanged}
></ha-radio>
</mwc-formfield>
</div> </div>
</div>
${this._disabledBy !== null
? html`
<div class="secondary">
${this.hass.localize(
"ui.dialogs.entity_registry.editor.enabled_description"
)}
</div>
`
: this._hiddenBy !== null
? html`
<div class="secondary">
${this.hass.localize(
"ui.dialogs.entity_registry.editor.hidden_description"
)}
</div>
`
: ""}
</ha-expansion-panel>
`; `;
} }
@ -184,6 +254,23 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
this._disabledBy = (ev.target as HaSwitch).checked ? null : "user"; this._disabledBy = (ev.target as HaSwitch).checked ? null : "user";
} }
private _viewStatusChanged(ev: CustomEvent): void {
switch ((ev.target as any).value) {
case "enabled":
this._disabledBy = null;
this._hiddenBy = null;
break;
case "disabled":
this._disabledBy = "user";
this._hiddenBy = null;
break;
case "hidden":
this._hiddenBy = "user";
this._disabledBy = null;
break;
}
}
static get styles() { static get styles() {
return css` return css`
ha-switch { ha-switch {
@ -202,6 +289,9 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) {
display: block; display: block;
margin-bottom: 8px; margin-bottom: 8px;
} }
ha-expansion-panel {
margin-top: 8px;
}
`; `;
} }
} }

View File

@ -304,6 +304,11 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
: ""} : ""}
${this.entry.device_id ${this.entry.device_id
? html` ? html`
<div class="label">
${this.hass.localize(
"ui.dialogs.entity_registry.editor.change_area"
)}:
</div>
<ha-area-picker <ha-area-picker
.hass=${this.hass} .hass=${this.hass}
.value=${this._areaId} .value=${this._areaId}
@ -317,20 +322,16 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
${this.hass.localize( ${this.hass.localize(
"ui.dialogs.entity_registry.editor.area_note" "ui.dialogs.entity_registry.editor.area_note"
)} )}
${this._device
? html`
<button class="link" @click=${this._openDeviceSettings}>
${this.hass.localize(
"ui.dialogs.entity_registry.editor.change_device_area"
)}
</button>
`
: ""}
</div> </div>
${this._areaId
? html`<mwc-button @click=${this._clearArea}
>${this.hass.localize(
"ui.dialogs.entity_registry.editor.follow_device_area"
)}</mwc-button
>`
: this._device
? html`<mwc-button @click=${this._openDeviceSettings}
>${this.hass.localize(
"ui.dialogs.entity_registry.editor.change_device_area"
)}</mwc-button
>`
: ""}
` `
: ""} : ""}
</ha-expansion-panel> </ha-expansion-panel>
@ -530,7 +531,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
align-items: center; align-items: center;
} }
.label { .label {
margin-top: 8px; margin-top: 16px;
} }
.secondary { .secondary {
margin: 8px 0; margin: 8px 0;

View File

@ -790,6 +790,7 @@
}, },
"unavailable": "This entity is unavailable.", "unavailable": "This entity is unavailable.",
"view_status": "Entity view status", "view_status": "Entity view status",
"change_area": "Change Area",
"enabled_label": "Enabled", "enabled_label": "Enabled",
"disabled_label": "Disabled", "disabled_label": "Disabled",
"enabled_cause": "Cannot change view status. Disabled by {cause}.", "enabled_cause": "Cannot change view status. Disabled by {cause}.",