From 49c018c000eee7fe7649ff2948da715822043356 Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Tue, 24 May 2022 01:18:08 +0200 Subject: [PATCH] Allow setting `device_class` "outlet" again through entity settings (#12669) * Allow setting `device_class` "outlet" again through UI * Fixes * Null check deviceClass and adjust used translation --- .../entities/entity-registry-settings.ts | 29 +++++++++++++++++-- src/translations/en.json | 4 +++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index e8125074d9..6c46903632 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -367,9 +367,24 @@ 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.switch" + )} + + + ${this.hass.localize( + "ui.dialogs.entity_registry.editor.device_classes.switch.outlet" + )} +
  • ${this._switchAsDomainsSorted( SWITCH_AS_DOMAINS, @@ -617,7 +632,15 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { if (ev.target.value === "") { return; } - this._switchAs = ev.target.value; + + // If value is "outlet" that means the user kept the "switch" domain, but actually changed + // the device_class of the switch to "outlet". + 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; + } } private _areaPicked(ev: CustomEvent) { diff --git a/src/translations/en.json b/src/translations/en.json index 824a63d04e..02daa046d6 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -853,6 +853,10 @@ "curtain": "Curtain", "damper": "Damper", "shutter": "Shutter" + }, + "switch": { + "outlet": "Outlet", + "switch": "Switch" } }, "unavailable": "This entity is unavailable.",