From 94ebb63589457708ba90c6cb99092a33ae9b4530 Mon Sep 17 00:00:00 2001 From: Zack Date: Wed, 16 Mar 2022 17:25:08 -0500 Subject: [PATCH] add to basic editor and update advanced style --- .../entities/entity-registry-basic-editor.ts | 142 ++++++++++++++---- .../entities/entity-registry-settings.ts | 29 ++-- src/translations/en.json | 1 + 3 files changed, 132 insertions(+), 40 deletions(-) diff --git a/src/panels/config/entities/entity-registry-basic-editor.ts b/src/panels/config/entities/entity-registry-basic-editor.ts index 52240794b3..fcf2e7883e 100644 --- a/src/panels/config/entities/entity-registry-basic-editor.ts +++ b/src/panels/config/entities/entity-registry-basic-editor.ts @@ -1,3 +1,5 @@ +import "../../../components/ha-expansion-panel"; +import "@material/mwc-formfield/mwc-formfield"; import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { css, html, LitElement, PropertyValues, TemplateResult } from "lit"; 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-switch"; import "../../../components/ha-textfield"; +import "../../../components/ha-radio"; import type { HaSwitch } from "../../../components/ha-switch"; import { DeviceRegistryEntry, @@ -33,6 +36,8 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) { @state() private _disabledBy!: string | null; + @state() private _hiddenBy!: string | null; + private _deviceLookup?: Record; @state() private _device?: DeviceRegistryEntry; @@ -51,6 +56,12 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) { ) { params.disabled_by = this._disabledBy; } + if ( + this.entry.hidden_by !== this._hiddenBy && + (this._hiddenBy === null || this._hiddenBy === "user") + ) { + params.hidden_by = this._hiddenBy; + } try { const result = await updateEntityRegistryEntry( this.hass!, @@ -101,6 +112,7 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) { this._origEntityId = this.entry.entity_id; this._entityId = this.entry.entity_id; this._disabledBy = this.entry.disabled_by; + this._hiddenBy = this.entry.hidden_by; this._areaId = this.entry.area_id; this._device = this.entry.device_id && this._deviceLookup @@ -138,37 +150,95 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) { .placeholder=${this._device?.area_id} @value-changed=${this._areaPicked} > -
- - -
-
- ${this.hass.localize( + + +
+ ${this.hass.localize( + "ui.dialogs.entity_registry.editor.view_status" + )}: +
+
+ ${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}` + ) + ) + : ""} +
+
+ -
- ${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}` - ) - ) - : ""} - ${this.hass.localize( - "ui.dialogs.entity_registry.editor.enabled_description" + > + + + ${this.hass.localize( - "ui.dialogs.entity_registry.editor.note" + > + + + + > + +
-
+ + ${this._disabledBy !== null + ? html` +
+ ${this.hass.localize( + "ui.dialogs.entity_registry.editor.enabled_description" + )} +
+ ` + : this._hiddenBy !== null + ? html` +
+ ${this.hass.localize( + "ui.dialogs.entity_registry.editor.hidden_description" + )} +
+ ` + : ""} +
`; } @@ -184,6 +254,23 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) { 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() { return css` ha-switch { @@ -202,6 +289,9 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) { display: block; margin-bottom: 8px; } + ha-expansion-panel { + margin-top: 8px; + } `; } } diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index a11803f6db..76948c4851 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -304,6 +304,11 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { : ""} ${this.entry.device_id ? html` +
+ ${this.hass.localize( + "ui.dialogs.entity_registry.editor.change_area" + )}: +
+ ${this.hass.localize( + "ui.dialogs.entity_registry.editor.change_device_area" + )} + + ` + : ""}
- ${this._areaId - ? html`${this.hass.localize( - "ui.dialogs.entity_registry.editor.follow_device_area" - )}` - : this._device - ? html`${this.hass.localize( - "ui.dialogs.entity_registry.editor.change_device_area" - )}` - : ""} ` : ""} @@ -530,7 +531,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { align-items: center; } .label { - margin-top: 8px; + margin-top: 16px; } .secondary { margin: 8px 0; diff --git a/src/translations/en.json b/src/translations/en.json index a24a506548..23290720f0 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -790,6 +790,7 @@ }, "unavailable": "This entity is unavailable.", "view_status": "Entity view status", + "change_area": "Change Area", "enabled_label": "Enabled", "disabled_label": "Disabled", "enabled_cause": "Cannot change view status. Disabled by {cause}.",