From 1db31fb0f7db517f5fedf3e050f7e99fecd7ed17 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 4 Mar 2020 17:20:16 -0800 Subject: [PATCH] Show entity reg editor for helpers when not editable (#5056) --- .../settings/entity-settings-helper-tab.ts | 80 ++++++++++--------- src/translations/en.json | 4 +- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/panels/config/entities/editor-tabs/settings/entity-settings-helper-tab.ts b/src/panels/config/entities/editor-tabs/settings/entity-settings-helper-tab.ts index 79f330a685..5332e305e4 100644 --- a/src/panels/config/entities/editor-tabs/settings/entity-settings-helper-tab.ts +++ b/src/panels/config/entities/editor-tabs/settings/entity-settings-helper-tab.ts @@ -13,7 +13,10 @@ import { isComponentLoaded } from "../../../../../common/config/is_component_loa import { dynamicElement } from "../../../../../common/dom/dynamic-element-directive"; import { fireEvent } from "../../../../../common/dom/fire_event"; import { HaPaperDialog } from "../../../../../components/dialog/ha-paper-dialog"; -import { ExtEntityRegistryEntry } from "../../../../../data/entity_registry"; +import { + ExtEntityRegistryEntry, + removeEntityRegistryEntry, +} from "../../../../../data/entity_registry"; import { deleteInputBoolean, fetchInputBoolean, @@ -109,23 +112,7 @@ export class EntityRegistrySettingsHelper extends LitElement { if (this._item === undefined) { return html``; } - if (!this._componentLoaded) { - return html` - - The ${this.entry.platform} component is not loaded, please add it your - configuration. Either by adding 'default_config:' or - '${this.entry.platform}:'. - - `; - } - if (this._item === null) { - return html` - - This entity can not be edited from the UI. Only entities setup from - the UI are editable. - - `; - } + const stateObj = this.hass.states[this.entry.entity_id]; return html` ${this._error @@ -134,13 +121,23 @@ export class EntityRegistrySettingsHelper extends LitElement { ` : ""}
-
- ${dynamicElement(`ha-${this.entry.platform}-form`, { - hass: this.hass, - item: this._item, - entry: this.entry, - })} -
+ ${!this._componentLoaded + ? this.hass.localize( + "ui.dialogs.helper_settings.platform_not_loaded", + "platform", + this.entry.platform + ) + : this._item === null + ? this.hass.localize("ui.dialogs.helper_settings.yaml_not_editable") + : html` +
+ ${dynamicElement(`ha-${this.entry.platform}-form`, { + hass: this.hass, + item: this._item, + entry: this.entry, + })} +
+ `} ${this.hass.localize("ui.dialogs.entity_registry.editor.delete")} ${this.hass.localize("ui.dialogs.entity_registry.editor.update")} @@ -178,16 +176,15 @@ export class EntityRegistrySettingsHelper extends LitElement { } private async _updateItem(): Promise { - if (!this._item) { - return; - } this._submitting = true; try { - await HELPERS[this.entry.platform].update( - this.hass!, - this._item.id, - this._item - ); + if (this._componentLoaded && this._item) { + await HELPERS[this.entry.platform].update( + this.hass!, + this._item.id, + this._item + ); + } await this._registryEditor?.updateEntry(); fireEvent(this, "close-dialog"); } catch (err) { @@ -198,9 +195,6 @@ export class EntityRegistrySettingsHelper extends LitElement { } private async _confirmDeleteItem(): Promise { - if (!this._item) { - return; - } if ( !(await showConfirmationDialog(this, { text: this.hass.localize( @@ -214,7 +208,15 @@ export class EntityRegistrySettingsHelper extends LitElement { this._submitting = true; try { - await HELPERS[this.entry.platform].delete(this.hass!, this._item.id); + if (this._componentLoaded && this._item) { + await HELPERS[this.entry.platform].delete(this.hass!, this._item.id); + } else { + const stateObj = this.hass.states[this.entry.entity_id]; + if (!stateObj?.attributes.restored) { + return; + } + await removeEntityRegistryEntry(this.hass!, this.entry.entity_id); + } fireEvent(this, "close-dialog"); } finally { this._submitting = false; diff --git a/src/translations/en.json b/src/translations/en.json index 89696e78fa..a07b13243f 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -659,8 +659,8 @@ } }, "helper_settings": { - "not_editable": "Not editable", - "not_editable_text": "This entity can't be changed from the UI because it is defined in configuration.yaml.", + "platform_not_loaded": "The {platform} component is not loaded, please add it your configuration. Either by adding 'default_config:' or '{platform}:'.", + "yaml_not_editable": "The settings of this entity can not be edited from the UI. Only entities setup from the UI are configurable from the UI.", "required_error_msg": "This field is required", "generic": { "name": "Name",