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
This commit is contained in:
Philip Allgaier 2022-05-24 01:18:08 +02:00 committed by GitHub
parent b71b230bfd
commit 49c018c000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View File

@ -367,9 +367,24 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
@selected=${this._switchAsChanged}
@closed=${stopPropagation}
>
<mwc-list-item value="switch" selected>
${domainToName(this.hass.localize, "switch")}</mwc-list-item
<mwc-list-item
value="switch"
.selected=${!this._deviceClass ||
this._deviceClass === "switch"}
>
${this.hass.localize(
"ui.dialogs.entity_registry.editor.device_classes.switch.switch"
)}
</mwc-list-item>
<mwc-list-item
value="outlet"
.selected=${!this._deviceClass ||
this._deviceClass === "outlet"}
>
${this.hass.localize(
"ui.dialogs.entity_registry.editor.device_classes.switch.outlet"
)}
</mwc-list-item>
<li divider role="separator"></li>
${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) {

View File

@ -853,6 +853,10 @@
"curtain": "Curtain",
"damper": "Damper",
"shutter": "Shutter"
},
"switch": {
"outlet": "Outlet",
"switch": "Switch"
}
},
"unavailable": "This entity is unavailable.",