From 653db1452104156c8cf026fe8f729ef1ff161aa6 Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Thu, 12 May 2022 09:48:14 +0200 Subject: [PATCH 1/3] Allow setting `device_class` "outlet" again through UI --- .../entities/entity-registry-settings.ts | 24 +++++++++++++++++-- src/translations/en.json | 4 ++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index 0c6ff704df46..d76095e79481 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -340,9 +340,20 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { @selected=${this._switchAsChanged} @closed=${stopPropagation} > - + ${domainToName(this.hass.localize, "switch")} + + ${this.hass.localize( + `ui.dialogs.entity_registry.editor.device_classes.switch.outlet` + )}
  • ${this._switchAsDomainsSorted( SWITCH_AS_DOMAINS, @@ -570,7 +581,16 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { if (ev.target.value === "") { return; } - this._switchAs = ev.target.value; + + // If value is "outlet" that means we kept the "switch" domain, but actually changed + // the device_class of the switch to "outlet". + if (ev.target.value !== "outlet") { + this._switchAs = ev.target.value; + } + + if (ev.target.value === "outlet" || ev.target.value === "switch") { + this._deviceClass = ev.target.value; + } } private _areaPicked(ev: CustomEvent) { diff --git a/src/translations/en.json b/src/translations/en.json index 2db7accc834b..9594a5b6fddf 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -844,6 +844,10 @@ "curtain": "Curtain", "damper": "Damper", "shutter": "Shutter" + }, + "switch": { + "outlet": "Outlet", + "switch": "Switch" } }, "unavailable": "This entity is unavailable.", From 41d26a2b8a70afafc557c62aa99938268c8652a1 Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Thu, 12 May 2022 09:59:42 +0200 Subject: [PATCH 2/3] Fixes --- src/panels/config/entities/entity-registry-settings.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index d76095e79481..3a45e893104f 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -582,11 +582,10 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { return; } - // If value is "outlet" that means we kept the "switch" domain, but actually changed + // If value is "outlet" that means the user kept the "switch" domain, but actually changed // the device_class of the switch to "outlet". - if (ev.target.value !== "outlet") { - this._switchAs = ev.target.value; - } + const switchAs = ev.target.value === "outlet" ? "switch" : ev.target.value; + this._switchAs = switchAs; if (ev.target.value === "outlet" || ev.target.value === "switch") { this._deviceClass = ev.target.value; From b712bdddbf95bb9dbd8379a9f49ff868bb0efb8d Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Tue, 24 May 2022 00:17:22 +0200 Subject: [PATCH 3/3] Null check deviceClass and adjust used translation --- .../entities/entity-registry-settings.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index 3a45e893104f..db9de78d53b1 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -342,18 +342,22 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { > - ${domainToName(this.hass.localize, "switch")} + ${this.hass.localize( + "ui.dialogs.entity_registry.editor.device_classes.switch.switch" + )} +
    ${this.hass.localize( - `ui.dialogs.entity_registry.editor.device_classes.switch.outlet` - )} + "ui.dialogs.entity_registry.editor.device_classes.switch.outlet" + )} +
  • ${this._switchAsDomainsSorted( SWITCH_AS_DOMAINS,