From 01da25d2d6eba3ee848865f9af5866a3f1f473ae Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 19 Aug 2019 23:59:32 -0700 Subject: [PATCH] Allow disabling entity in entity registry (#3496) * Allow disabling entitiy in entity registry * Make strings translatable * Update dialog-entity-registry-detail.ts * Change to enabled --- src/data/entity_registry.ts | 7 +- .../dialog-entity-registry-detail.ts | 73 ++++++++++++++----- .../ha-config-entity-registry.ts | 30 ++++++-- src/translations/en.json | 13 +++- 4 files changed, 95 insertions(+), 28 deletions(-) diff --git a/src/data/entity_registry.ts b/src/data/entity_registry.ts index f6549ee53..a3037e45c 100644 --- a/src/data/entity_registry.ts +++ b/src/data/entity_registry.ts @@ -9,12 +9,13 @@ export interface EntityRegistryEntry { platform: string; config_entry_id?: string; device_id?: string; - disabled_by?: string; + disabled_by: string | null; } export interface EntityRegistryEntryUpdateParams { - name: string | null; - new_entity_id: string; + name?: string | null; + disabled_by?: string | null; + new_entity_id?: string; } export const computeEntityRegistryName = ( diff --git a/src/panels/config/entity_registry/dialog-entity-registry-detail.ts b/src/panels/config/entity_registry/dialog-entity-registry-detail.ts index 391e72d16..2a6ac0553 100644 --- a/src/panels/config/entity_registry/dialog-entity-registry-detail.ts +++ b/src/panels/config/entity_registry/dialog-entity-registry-detail.ts @@ -2,12 +2,13 @@ import { LitElement, html, css, - PropertyDeclarations, CSSResult, TemplateResult, + property, } from "lit-element"; import "@polymer/paper-dialog-scrollable/paper-dialog-scrollable"; import "@polymer/paper-input/paper-input"; +import "@polymer/paper-toggle-button/paper-toggle-button"; import "../../../components/dialog/ha-paper-dialog"; @@ -20,21 +21,13 @@ import { HassEntity } from "home-assistant-js-websocket"; import computeStateName from "../../../common/entity/compute_state_name"; class DialogEntityRegistryDetail extends LitElement { - public hass!: HomeAssistant; - private _name!: string; - private _entityId!: string; - private _error?: string; - private _params?: EntityRegistryDetailDialogParams; - private _submitting?: boolean; - - static get properties(): PropertyDeclarations { - return { - _error: {}, - _name: {}, - _entityId: {}, - _params: {}, - }; - } + @property() public hass!: HomeAssistant; + @property() private _name!: string; + @property() private _entityId!: string; + @property() private _disabledBy!: string | null; + @property() private _error?: string; + @property() private _params?: EntityRegistryDetailDialogParams; + @property() private _submitting?: boolean; public async showDialog( params: EntityRegistryDetailDialogParams @@ -43,6 +36,7 @@ class DialogEntityRegistryDetail extends LitElement { this._error = undefined; this._name = this._params.entry.name || ""; this._entityId = this._params.entry.entity_id; + this._disabledBy = this._params.entry.disabled_by; await this.updateComplete; } @@ -62,7 +56,11 @@ class DialogEntityRegistryDetail extends LitElement { opened @opened-changed="${this._openedChanged}" > -

${entry.entity_id}

+

+ ${stateObj + ? computeStateName(stateObj) + : entry.name || entry.entity_id} +

${!stateObj ? html` @@ -96,6 +94,35 @@ class DialogEntityRegistryDetail extends LitElement { .invalid=${invalidDomainUpdate} .disabled=${this._submitting} > +
+ +
+
+ ${this.hass.localize( + "ui.panel.config.entity_registry.editor.enabled_label" + )} +
+
+ ${this._disabledBy && this._disabledBy !== "user" + ? this.hass.localize( + "ui.panel.config.entity_registry.editor.enabled_cause", + "cause", + this.hass.localize( + `config_entry.disabled_by.${this._disabledBy}` + ) + ) + : ""} + ${this.hass.localize( + "ui.panel.config.entity_registry.editor.enabled_description" + )} +
Note: this might not work yet with all integrations. +
+
+
+
@@ -136,6 +163,7 @@ class DialogEntityRegistryDetail extends LitElement { try { await this._params!.updateEntry({ name: this._name.trim() || null, + disabled_by: this._disabledBy, new_entity_id: this._entityId.trim(), }); this._params = undefined; @@ -162,6 +190,9 @@ class DialogEntityRegistryDetail extends LitElement { this._params = undefined; } } + private _disabledByChanged(ev: PolymerChangedEvent): void { + this._disabledBy = ev.detail.value ? null : "user"; + } static get styles(): CSSResult[] { return [ @@ -169,6 +200,7 @@ class DialogEntityRegistryDetail extends LitElement { css` ha-paper-dialog { min-width: 400px; + max-width: 450px; } .form { padding-bottom: 24px; @@ -179,6 +211,13 @@ class DialogEntityRegistryDetail extends LitElement { .error { color: var(--google-red-500); } + .row { + margin-top: 8px; + color: var(--primary-text-color); + } + .secondary { + color: var(--secondary-text-color); + } `, ]; } diff --git a/src/panels/config/entity_registry/ha-config-entity-registry.ts b/src/panels/config/entity_registry/ha-config-entity-registry.ts index 776e41e1a..8e5abfc3b 100644 --- a/src/panels/config/entity_registry/ha-config-entity-registry.ts +++ b/src/panels/config/entity_registry/ha-config-entity-registry.ts @@ -31,6 +31,7 @@ import { } from "./show-dialog-entity-registry-detail"; import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { compare } from "../../../common/string/compare"; +import { classMap } from "lit-html/directives/class-map"; class HaConfigEntityRegistry extends LitElement { @property() public hass!: HomeAssistant; @@ -82,7 +83,11 @@ class HaConfigEntityRegistry extends LitElement { ${this._entities.map((entry) => { const state = this.hass!.states[entry.entity_id]; return html` - +
${computeEntityRegistryName(this.hass!, entry) || - this.hass!.localize( - "ui.panel.config.entity_registry.picker.unavailable" - )} + `(${this.hass!.localize("state.default.unavailable")})`}
${entry.entity_id}
-
${entry.platform}
+
+ ${entry.platform} + ${entry.disabled_by + ? html` +
(disabled) + ` + : ""} +
`; })} @@ -171,15 +181,23 @@ Deleting an entry will not remove the entity from Home Assistant. To do this, yo color: var(--primary-color); } ha-card { + margin-bottom: 24px; direction: ltr; - overflow: hidden; } paper-icon-item { cursor: pointer; + color: var(--primary-text-color); } ha-icon { margin-left: 8px; } + .platform { + text-align: right; + margin: 0 0 0 8px; + } + .disabled-entry { + color: var(--secondary-text-color); + } `; } } diff --git a/src/translations/en.json b/src/translations/en.json index 777963dc3..4e3fe4486 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -367,6 +367,13 @@ "system-users": "Users", "system-read-only": "Read-Only Users" }, + "config_entry": { + "disabled_by": { + "user": "User", + "integration": "Integration", + "config_entry": "Config Entry" + } + }, "ui": { "auth_store": { "ask": "Do you want to save this login?", @@ -847,12 +854,14 @@ "header": "Entity Registry", "introduction": "Home Assistant keeps a registry of every entity it has ever seen that can be uniquely identified. Each of these entities will have an entity ID assigned which will be reserved for just this entity.", "introduction2": "Use the entity registry to override the name, change the entity ID or remove the entry from Home Assistant. Note, removing the entity registry entry won't remove the entity. To do that, follow the link below and remove it from the integrations page.", - "integrations_page": "Integrations page", - "unavailable": "(unavailable)" + "integrations_page": "Integrations page" }, "editor": { "unavailable": "This entity is not currently available.", "default_name": "New Area", + "enabled_label": "Enable entity", + "enabled_cause": "Disabled by {cause}.", + "enabled_description": "Disabled entities will not be added to Home Assistant.", "delete": "DELETE", "update": "UPDATE" }