From e01cb3ca829b5d19cb65e382844da47b6f1b1785 Mon Sep 17 00:00:00 2001 From: Zack Date: Mon, 14 Mar 2022 14:22:45 -0500 Subject: [PATCH 01/12] Utilize Hide Hidden Entities --- src/data/entity_registry.ts | 2 + .../device-detail/ha-device-entities-card.ts | 124 +++++++++--------- .../config/devices/ha-config-device-page.ts | 2 +- .../entities/entity-registry-settings.ts | 111 +++++++++++----- .../config/entities/ha-config-entities.ts | 27 ++++ .../common/generate-lovelace-config.ts | 5 +- src/translations/en.json | 14 +- 7 files changed, 186 insertions(+), 99 deletions(-) diff --git a/src/data/entity_registry.ts b/src/data/entity_registry.ts index 83fcc601b5..eaefcee6e3 100644 --- a/src/data/entity_registry.ts +++ b/src/data/entity_registry.ts @@ -14,6 +14,7 @@ export interface EntityRegistryEntry { device_id: string | null; area_id: string | null; disabled_by: string | null; + hidden_by: string | null; entity_category: "config" | "diagnostic" | null; } @@ -38,6 +39,7 @@ export interface EntityRegistryEntryUpdateParams { device_class?: string | null; area_id?: string | null; disabled_by?: string | null; + hidden_by: string | null; new_entity_id?: string; } diff --git a/src/panels/config/devices/device-detail/ha-device-entities-card.ts b/src/panels/config/devices/device-detail/ha-device-entities-card.ts index ebfbd159dd..4c352d3c21 100644 --- a/src/panels/config/devices/device-detail/ha-device-entities-card.ts +++ b/src/panels/config/devices/device-detail/ha-device-entities-card.ts @@ -40,7 +40,7 @@ export class HaDeviceEntitiesCard extends LitElement { @property() public entities!: EntityRegistryStateEntry[]; - @property() public showDisabled = false; + @property() public showHidden = false; @state() private _extDisabledEntityEntries?: Record< string, @@ -60,77 +60,75 @@ export class HaDeviceEntitiesCard extends LitElement { } protected render(): TemplateResult { - const disabledEntities: EntityRegistryStateEntry[] = []; + if (!this.entities.length) { + return html` +
+ ${this.hass.localize("ui.panel.config.devices.entities.none")} +
+ `; + } + + const shownEntities: EntityRegistryStateEntry[] = []; + const hiddenEntities: EntityRegistryStateEntry[] = []; this._entityRows = []; + + this.entities.forEach((entry) => { + if (entry.disabled_by || entry.hidden_by) { + if (this._extDisabledEntityEntries) { + hiddenEntities.push( + this._extDisabledEntityEntries[entry.entity_id] || entry + ); + } else { + hiddenEntities.push(entry); + } + } else { + shownEntities.push(entry); + } + }); + return html` - ${this.entities.length - ? html` -
- ${this.entities.map((entry: EntityRegistryStateEntry) => { - if (entry.disabled_by) { - if (this._extDisabledEntityEntries) { - disabledEntities.push( - this._extDisabledEntityEntries[entry.entity_id] || entry - ); - } else { - disabledEntities.push(entry); - } - return ""; - } - return this.hass.states[entry.entity_id] - ? this._renderEntity(entry) - : this._renderEntry(entry); - })} -
- ${disabledEntities.length - ? !this.showDisabled - ? html` - - ` - : html` - ${disabledEntities.map((entry) => - this._renderEntry(entry) - )} - - ` - : ""} -
- +
+ ${shownEntities.map((entry) => + this.hass.states[entry.entity_id] + ? this._renderEntity(entry) + : this._renderEntry(entry) + )} +
+ ${hiddenEntities.length + ? !this.showHidden + ? html` +
- ` - : html` -
- ${this.hass.localize("ui.panel.config.devices.entities.none")} -
- `} + + ` + : html` + ${hiddenEntities.map((entry) => this._renderEntry(entry))} + + ` + : ""} +
+ + ${this.hass.localize( + "ui.panel.config.devices.entities.add_entities_lovelace" + )} + +
`; } - private _toggleShowDisabled() { - this.showDisabled = !this.showDisabled; - if (!this.showDisabled || this._extDisabledEntityEntries !== undefined) { + private _toggleShowHidden() { + this.showHidden = !this.showHidden; + if (!this.showHidden || this._extDisabledEntityEntries !== undefined) { return; } this._extDisabledEntityEntries = {}; diff --git a/src/panels/config/devices/ha-config-device-page.ts b/src/panels/config/devices/ha-config-device-page.ts index 7512b3067f..54d926b978 100644 --- a/src/panels/config/devices/ha-config-device-page.ts +++ b/src/panels/config/devices/ha-config-device-page.ts @@ -557,7 +557,7 @@ export class HaConfigDevicePage extends LitElement { )} .deviceName=${deviceName} .entities=${entitiesByCategory[category]} - .showDisabled=${device.disabled_by !== null} + .showHidden=${device.disabled_by !== null} > ` diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index 542a730d32..d66fb83e23 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -76,6 +76,8 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { @state() private _disabledBy!: string | null; + @state() private _hiddenBy!: string | null; + private _deviceLookup?: Record; @state() private _device?: DeviceRegistryEntry; @@ -112,6 +114,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { this._areaId = this.entry.area_id; this._entityId = this.entry.entity_id; this._disabledBy = this.entry.disabled_by; + this._hiddenBy = this.entry.hidden_by; this._device = this.entry.device_id && this._deviceLookup ? this._deviceLookup[this.entry.device_id] @@ -244,41 +247,75 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { - ${this.entry.device_id - ? html` + + +
+
+ ${this.hass.localize( + "ui.dialogs.entity_registry.editor.hidden_label" )} - outlined - > -

- ${this.hass.localize( - "ui.dialogs.entity_registry.editor.area_note" - )} -

- ${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" - )}` +
+
+ ${this._hiddenBy && this._hiddenBy !== "user" + ? this.hass.localize( + "ui.dialogs.entity_registry.editor.hidden_cause", + "cause", + this.hass.localize( + `config_entry.hidden_by.${this._hiddenBy}` + ) + ) : ""} - ${this.hass.localize( + "ui.dialogs.entity_registry.editor.note" + )} +
+
+ + ${this.entry.device_id + ? html` + ` + outlined + > +

+ ${this.hass.localize( + "ui.dialogs.entity_registry.editor.area_note" + )} +

+ ${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" + )}` + : ""} + +
+ ` : ""}
@@ -354,6 +391,12 @@ export class EntityRegistrySettings 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!, @@ -409,6 +452,10 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { this._disabledBy = (ev.target as HaSwitch).checked ? null : "user"; } + private _hiddenByChanged(ev: Event): void { + this._hiddenBy = (ev.target as HaSwitch).checked ? "user" : null; + } + static get styles(): CSSResultGroup { return [ haStyle, diff --git a/src/panels/config/entities/ha-config-entities.ts b/src/panels/config/entities/ha-config-entities.ts index f93930d2d3..87c9fb2336 100644 --- a/src/panels/config/entities/ha-config-entities.ts +++ b/src/panels/config/entities/ha-config-entities.ts @@ -101,6 +101,8 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) { @state() private _showDisabled = false; + @state() private _showHidden = false; + @state() private _showUnavailable = true; @state() private _showReadOnly = true; @@ -301,6 +303,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) { showDisabled: boolean, showUnavailable: boolean, showReadOnly: boolean, + showHidden: boolean, entries?: ConfigEntry[] ) => { const result: EntityRow[] = []; @@ -362,6 +365,12 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) { ); } + if (!showHidden) { + filteredEntities = filteredEntities.filter( + (entity) => !entity.hidden_by + ); + } + for (const entry of filteredEntities) { const entity = this.hass.states[entry.entity_id]; const unavailable = entity?.state === UNAVAILABLE; @@ -465,6 +474,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) { this._showDisabled, this._showUnavailable, this._showReadOnly, + this._showHidden, this._entries ); @@ -603,6 +613,15 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) { "ui.panel.config.entities.picker.filter.show_disabled" )} + + ${this.hass!.localize( + "ui.panel.config.entities.picker.filter.show_hidden" + )} + ) { + if (ev.detail.source !== "property") { + return; + } + this._showHidden = ev.detail.selected; + } + private _showRestoredChanged(ev: CustomEvent) { if (ev.detail.source !== "property") { return; diff --git a/src/panels/lovelace/common/generate-lovelace-config.ts b/src/panels/lovelace/common/generate-lovelace-config.ts index 0d3fd0cb9a..8ffdd43709 100644 --- a/src/panels/lovelace/common/generate-lovelace-config.ts +++ b/src/panels/lovelace/common/generate-lovelace-config.ts @@ -238,7 +238,10 @@ const computeDefaultViewStates = ( const hiddenEntities = new Set( entityEntries .filter( - (entry) => entry.entity_category || HIDE_PLATFORM.has(entry.platform) + (entry) => + entry.entity_category || + HIDE_PLATFORM.has(entry.platform) || + entry.hidden_by ) .map((entry) => entry.entity_id) ); diff --git a/src/translations/en.json b/src/translations/en.json index 4eaa79d614..7d5e1440ac 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -102,6 +102,12 @@ "integration": "Integration", "config_entry": "Config entry", "device": "Device" + }, + "hidden_by": { + "user": "User", + "integration": "Integration", + "config_entry": "Config entry", + "device": "Device" } }, "ui": { @@ -785,11 +791,14 @@ "unavailable": "This entity is unavailable.", "enabled_label": "Enable entity", "enabled_cause": "Disabled by {cause}.", + "hidden_label": "Hide entity", + "hidden_cause": "Hidden by {cause}.", "device_disabled": "The device of this entity is disabled.", "open_device_settings": "Open device settings", "enabled_description": "Disabled entities will not be added to Home Assistant.", "enabled_delay_confirm": "The enabled entities will be added to Home Assistant in {delay} seconds", "enabled_restart_confirm": "Restart Home Assistant to finish enabling the entities", + "hidden_description": "Hidden entities will not be shown in Home Assistant UI.", "delete": "Delete", "confirm_delete": "Are you sure you want to delete this entity?", "update": "Update", @@ -2364,8 +2373,8 @@ "config": "Configuration", "add_entities_lovelace": "Add to Lovelace", "none": "This device has no entities", - "hide_disabled": "Hide disabled", - "disabled_entities": "+{count} {count, plural,\n one {disabled entity}\n other {disabled entities}\n}" + "hide_disabled": "Hide hidden", + "disabled_entities": "+{count} {count, plural,\n one {hidden entity}\n other {hidden entities}\n}" }, "confirm_rename_entity_ids": "Do you also want to rename the entity IDs of your entities?", "confirm_rename_entity_ids_warning": "This will not change any configuration (like automations, scripts, scenes, dashboards) that is currently using these entities! You will have to update them yourself to use the new entity IDs!", @@ -2405,6 +2414,7 @@ "search": "Search entities", "filter": { "filter": "Filter", + "show_hidden": "Show hidden entities", "show_disabled": "Show disabled entities", "show_unavailable": "Show unavailable entities", "show_readonly": "Show read-only entities", From f1ec479d415ba3d3e1028bfd8488405cfad85f77 Mon Sep 17 00:00:00 2001 From: Zack Date: Mon, 14 Mar 2022 20:37:37 -0500 Subject: [PATCH 02/12] Reviews --- .../device-detail/ha-device-entities-card.ts | 8 +- .../entities/entity-registry-settings.ts | 164 +++++++++--------- src/translations/en.json | 6 +- 3 files changed, 94 insertions(+), 84 deletions(-) diff --git a/src/panels/config/devices/device-detail/ha-device-entities-card.ts b/src/panels/config/devices/device-detail/ha-device-entities-card.ts index 4c352d3c21..488feaf07c 100644 --- a/src/panels/config/devices/device-detail/ha-device-entities-card.ts +++ b/src/panels/config/devices/device-detail/ha-device-entities-card.ts @@ -62,9 +62,11 @@ export class HaDeviceEntitiesCard extends LitElement { protected render(): TemplateResult { if (!this.entities.length) { return html` -
- ${this.hass.localize("ui.panel.config.devices.entities.none")} -
+ +
+ ${this.hass.localize("ui.panel.config.devices.entities.none")} +
+
`; } diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index d66fb83e23..62ab9e3ebb 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -1,3 +1,5 @@ +import "@material/mwc-formfield/mwc-formfield"; +import "../../../components/ha-radio"; import "@material/mwc-button/mwc-button"; import "@material/mwc-list/mwc-list-item"; import { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket"; @@ -20,7 +22,6 @@ import "../../../components/ha-expansion-panel"; import "../../../components/ha-icon-picker"; import "../../../components/ha-select"; import "../../../components/ha-switch"; -import type { HaSwitch } from "../../../components/ha-switch"; import "../../../components/ha-textfield"; import { DeviceRegistryEntry, @@ -214,79 +215,67 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { @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.hass.localize( - "ui.dialogs.entity_registry.editor.enabled_description" - )} -
${this.hass.localize( - "ui.dialogs.entity_registry.editor.note" - )} -
-
-
- -
- - -
-
- ${this.hass.localize( + > + + + -
- ${this._hiddenBy && this._hiddenBy !== "user" - ? this.hass.localize( - "ui.dialogs.entity_registry.editor.hidden_cause", - "cause", - this.hass.localize( - `config_entry.hidden_by.${this._hiddenBy}` - ) - ) - : ""} - ${this.hass.localize( - "ui.dialogs.entity_registry.editor.hidden_description" + > + + + ${this.hass.localize( - "ui.dialogs.entity_registry.editor.note" - )} -
+ > + +
-
- ${this.entry.device_id - ? html` - + + ${this.entry.device_id + ? html`

${this.hass.localize( "ui.dialogs.entity_registry.editor.area_note" @@ -314,9 +303,9 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { )} @value-changed=${this._areaPicked} > - - ` - : ""} + ` + : ""} +

Date: Mon, 14 Mar 2022 20:39:03 -0500 Subject: [PATCH 03/12] add to demo --- gallery/src/pages/misc/integration-card.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/gallery/src/pages/misc/integration-card.ts b/gallery/src/pages/misc/integration-card.ts index 53f16a16b2..aa26eb2c6b 100644 --- a/gallery/src/pages/misc/integration-card.ts +++ b/gallery/src/pages/misc/integration-card.ts @@ -188,6 +188,7 @@ const createEntityRegistryEntries = ( device_id: "mock-device-id", area_id: null, disabled_by: null, + hidden_by: null, entity_category: null, entity_id: "binary_sensor.updater", name: null, From 4e0fc8ee08243ea3e8559b05c4a1d94622b8318b Mon Sep 17 00:00:00 2001 From: Zack Date: Tue, 15 Mar 2022 14:26:21 -0500 Subject: [PATCH 04/12] Update Translations --- .../config/devices/device-detail/ha-device-entities-card.ts | 2 +- src/translations/en.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/panels/config/devices/device-detail/ha-device-entities-card.ts b/src/panels/config/devices/device-detail/ha-device-entities-card.ts index 488feaf07c..19e60da9ee 100644 --- a/src/panels/config/devices/device-detail/ha-device-entities-card.ts +++ b/src/panels/config/devices/device-detail/ha-device-entities-card.ts @@ -102,7 +102,7 @@ export class HaDeviceEntitiesCard extends LitElement { ? html`
+
+ ${(this._disabledBy && this._disabledBy !== "user") || 1 + ? this.hass.localize( + "ui.dialogs.entity_registry.editor.enabled_cause", + "cause", + this.hass.localize( + `config_entry.disabled_by.${this._disabledBy}` + ) + ) + : ""} +
Date: Tue, 15 Mar 2022 14:33:11 -0500 Subject: [PATCH 06/12] remove 1 --- src/panels/config/entities/entity-registry-settings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index 5251e297b5..5a22bec551 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -227,7 +227,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { )}:
- ${(this._disabledBy && this._disabledBy !== "user") || 1 + ${this._disabledBy && this._disabledBy !== "user" ? this.hass.localize( "ui.dialogs.entity_registry.editor.enabled_cause", "cause", From a27dd1e7f12cd9f873ee887a291e21de0a6f2e91 Mon Sep 17 00:00:00 2001 From: Zack Date: Tue, 15 Mar 2022 14:47:15 -0500 Subject: [PATCH 07/12] Add Description of chosen --- .../entities/entity-registry-settings.ts | 41 +++++++++++++------ src/translations/en.json | 1 - 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index 5a22bec551..a11803f6db 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -285,13 +285,39 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
+ ${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" + )} +
+ ` + : ""} ${this.entry.device_id ? html` -

+ +

${this.hass.localize( "ui.dialogs.entity_registry.editor.area_note" )} -

+
${this._areaId ? html`${this.hass.localize( @@ -305,15 +331,6 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { )}` : ""} - ` : ""} @@ -515,7 +532,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { .label { margin-top: 8px; } - p { + .secondary { margin: 8px 0; width: 340px; } diff --git a/src/translations/en.json b/src/translations/en.json index 9a3255711b..fe235befe7 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -106,7 +106,6 @@ "hidden_by": { "user": "User", "integration": "Integration", - "config_entry": "Config entry", "device": "Device" } }, From d5a307f8f48fab0e50f146bd88c038700a5baf73 Mon Sep 17 00:00:00 2001 From: Zack Date: Tue, 15 Mar 2022 15:00:35 -0500 Subject: [PATCH 08/12] Add icons and buttons --- .../config/entities/ha-config-entities.ts | 51 ++++++++++++++++++- src/translations/en.json | 6 +++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/panels/config/entities/ha-config-entities.ts b/src/panels/config/entities/ha-config-entities.ts index 87c9fb2336..4fe64de1a8 100644 --- a/src/panels/config/entities/ha-config-entities.ts +++ b/src/panels/config/entities/ha-config-entities.ts @@ -3,6 +3,7 @@ import { mdiAlertCircle, mdiCancel, mdiDelete, + mdiEyeOff, mdiFilterVariant, mdiPencilOff, mdiPlus, @@ -251,7 +252,10 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) { filterable: true, width: "68px", template: (_status, entity: EntityRow) => - entity.unavailable || entity.disabled_by || entity.readonly + entity.unavailable || + entity.disabled_by || + entity.hidden_by || + entity.readonly ? html`
@@ -282,6 +288,10 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) { ? this.hass.localize( "ui.panel.config.entities.picker.status.disabled" ) + : entity.hidden_by + ? this.hass.localize( + "ui.panel.config.entities.picker.status.hidden" + ) : this.hass.localize( "ui.panel.config.entities.picker.status.readonly" )} @@ -543,6 +553,11 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) { "ui.panel.config.entities.picker.disable_selected.button" )} + ${this.hass.localize( + "ui.panel.config.entities.picker.hide_selected.button" + )} ${this.hass.localize( "ui.panel.config.entities.picker.remove_selected.button" @@ -572,6 +587,17 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) { "ui.panel.config.entities.picker.disable_selected.button" )} + + + ${this.hass.localize( + "ui.panel.config.entities.picker.hide_selected.button" + )} + { + this._selectedEntities.forEach((entity) => + updateEntityRegistryEntry(this.hass, entity, { + hidden_by: "user", + }) + ); + this._clearSelection(); + }, + }); + } + private _removeSelected() { const removeableEntities = this._selectedEntities.filter((entity) => { const stateObj = this.hass.states[entity]; diff --git a/src/translations/en.json b/src/translations/en.json index fe235befe7..c87066ee6c 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -297,6 +297,7 @@ "remove": "Remove", "enable": "Enable", "disable": "Disable", + "hide": "Hide", "close": "Close", "clear": "Clear", "leave": "Leave", @@ -2455,6 +2456,11 @@ "confirm_partly_title": "Only {number} {number, plural,\n one {selected entity}\n other {selected entities}\n} can be removed.", "confirm_text": "You should remove them from your Lovelace config and automations if they contain these entities.", "confirm_partly_text": "You can only remove {removable} of the selected {selected} entities. Entities can only be removed when the integration is no longer providing the entities. Sometimes you have to restart Home Assistant before you can remove the entities of a removed integration. Are you sure you want to remove the removable entities?" + }, + "hide_selected": { + "button": "Hide selected", + "confirm_title": "Do you want to hide {number} {number, plural,\n one {entity}\n other {entities}\n}?", + "confirm_text": "Hidden entities will not be shown on your dashboard. Their history is still tracked and you can still interact with them with services." } } }, From 29119db5ce000627107f44a866310ed4d87fb696 Mon Sep 17 00:00:00 2001 From: Zack Date: Wed, 16 Mar 2022 17:05:52 -0500 Subject: [PATCH 09/12] Add translation --- src/translations/en.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/translations/en.json b/src/translations/en.json index c87066ee6c..a24a506548 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2428,6 +2428,7 @@ "unavailable": "Unavailable", "disabled": "Disabled", "readonly": "Read-only", + "hidden": "Hidden", "ok": "Ok" }, "headers": { From 94ebb63589457708ba90c6cb99092a33ae9b4530 Mon Sep 17 00:00:00 2001 From: Zack Date: Wed, 16 Mar 2022 17:25:08 -0500 Subject: [PATCH 10/12] 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}.", From 01eed225922bcf6c9573bd7293de4bb55d79a59c Mon Sep 17 00:00:00 2001 From: Zack Date: Wed, 16 Mar 2022 17:34:09 -0500 Subject: [PATCH 11/12] clean up --- src/panels/config/entities/entity-registry-basic-editor.ts | 5 ----- src/panels/config/entities/entity-registry-settings.ts | 5 ----- src/translations/en.json | 2 +- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/panels/config/entities/entity-registry-basic-editor.ts b/src/panels/config/entities/entity-registry-basic-editor.ts index fcf2e7883e..53d98571e9 100644 --- a/src/panels/config/entities/entity-registry-basic-editor.ts +++ b/src/panels/config/entities/entity-registry-basic-editor.ts @@ -8,7 +8,6 @@ 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, subscribeDeviceRegistry, @@ -250,10 +249,6 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) { this._entityId = ev.target.value; } - private _disabledByChanged(ev: Event): void { - this._disabledBy = (ev.target as HaSwitch).checked ? null : "user"; - } - private _viewStatusChanged(ev: CustomEvent): void { switch ((ev.target as any).value) { case "enabled": diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index 76948c4851..5f5ea8b835 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -397,11 +397,6 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { } } - private _clearArea() { - this._error = undefined; - this._areaId = null; - } - private _openDeviceSettings() { showDeviceRegistryDetailDialog(this, { device: this._device!, diff --git a/src/translations/en.json b/src/translations/en.json index 23290720f0..9861b3d23b 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -801,7 +801,7 @@ "enabled_description": "Disabled entities will not be added to Home Assistant.", "enabled_delay_confirm": "The enabled entities will be added to Home Assistant in {delay} seconds", "enabled_restart_confirm": "Restart Home Assistant to finish enabling the entities", - "hidden_description": "Hidden entities will not be shown in Home Assistant UI.", + "hidden_description": "Hidden entities will not be shown on your dashboard. Their history is still tracked and you can still interact with them with services.", "delete": "Delete", "confirm_delete": "Are you sure you want to delete this entity?", "update": "Update", From dde1c5e03c1bf18f8045856ad44748aebe65ec0e Mon Sep 17 00:00:00 2001 From: Zack Date: Wed, 16 Mar 2022 17:38:38 -0500 Subject: [PATCH 12/12] Entity Status --- src/panels/config/entities/entity-registry-basic-editor.ts | 5 ++++- src/panels/config/entities/entity-registry-settings.ts | 2 +- src/translations/en.json | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/panels/config/entities/entity-registry-basic-editor.ts b/src/panels/config/entities/entity-registry-basic-editor.ts index 53d98571e9..10d3bdf994 100644 --- a/src/panels/config/entities/entity-registry-basic-editor.ts +++ b/src/panels/config/entities/entity-registry-basic-editor.ts @@ -158,7 +158,7 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) { >
${this.hass.localize( - "ui.dialogs.entity_registry.editor.view_status" + "ui.dialogs.entity_registry.editor.entity_status" )}:
@@ -287,6 +287,9 @@ export class HaEntityRegistryBasicEditor extends SubscribeMixin(LitElement) { ha-expansion-panel { margin-top: 8px; } + .label { + margin-top: 16px; + } `; } } diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index 5f5ea8b835..c4278a7936 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -223,7 +223,7 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { >
${this.hass.localize( - "ui.dialogs.entity_registry.editor.view_status" + "ui.dialogs.entity_registry.editor.entity_status" )}:
diff --git a/src/translations/en.json b/src/translations/en.json index 9861b3d23b..babe137ca5 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -789,11 +789,11 @@ } }, "unavailable": "This entity is unavailable.", - "view_status": "Entity view status", + "entity_status": "Entity status", "change_area": "Change Area", "enabled_label": "Enabled", "disabled_label": "Disabled", - "enabled_cause": "Cannot change view status. Disabled by {cause}.", + "enabled_cause": "Cannot change status. Disabled by {cause}.", "hidden_label": "Hidden", "hidden_cause": "Hidden by {cause}.", "device_disabled": "The device of this entity is disabled.",