diff --git a/src/data/entity_registry.ts b/src/data/entity_registry.ts index 791f95ac8b..5b015d9adb 100644 --- a/src/data/entity_registry.ts +++ b/src/data/entity_registry.ts @@ -102,6 +102,7 @@ export interface WeatherEntityOptions { export interface SwitchAsXEntityOptions { entity_id: string; + invert: boolean; } export interface EntityRegistryOptions { diff --git a/src/panels/config/entities/entity-registry-settings-editor.ts b/src/panels/config/entities/entity-registry-settings-editor.ts index d5d24967bf..f9c52f6517 100644 --- a/src/panels/config/entities/entity-registry-settings-editor.ts +++ b/src/panels/config/entities/entity-registry-settings-editor.ts @@ -52,6 +52,10 @@ import { createConfigFlow, handleConfigFlowStep, } from "../../../data/config_flow"; +import { + createOptionsFlow, + handleOptionsFlowStep, +} from "../../../data/options_flow"; import { DataEntryFlowStepCreateEntry } from "../../../data/data_entry_flow"; import { DeviceRegistryEntry, @@ -126,6 +130,7 @@ const OVERRIDE_DEVICE_CLASSES = { }; const SWITCH_AS_DOMAINS = ["cover", "fan", "light", "lock", "siren", "valve"]; +const SWITCH_AS_DOMAINS_INVERT = ["cover", "lock", "valve"]; const PRECISIONS = [0, 1, 2, 3, 4, 5, 6]; @@ -151,7 +156,9 @@ export class EntityRegistrySettingsEditor extends LitElement { @state() private _deviceClass?: string; - @state() private _switchAs = "switch"; + @state() private _switchAsDomain = "switch"; + + @state() private _switchAsInvert = false; @state() private _areaId?: string | null; @@ -214,6 +221,7 @@ export class EntityRegistrySettingsEditor extends LitElement { this._device = this.entry.device_id ? this.hass.devices[this.entry.device_id] : undefined; + this._switchAsInvert = this.entry.options?.switch_as_x?.invert === true; const domain = computeDomain(this.entry.entity_id); @@ -333,9 +341,10 @@ export class EntityRegistrySettingsEditor extends LitElement { } if (changedProps.has("helperConfigEntry")) { if (this.helperConfigEntry?.domain === "switch_as_x") { - this._switchAs = computeDomain(this.entry.entity_id); + this._switchAsDomain = computeDomain(this.entry.entity_id); } else { - this._switchAs = "switch"; + this._switchAsDomain = "switch"; + this._switchAsInvert = false; } } } @@ -404,7 +413,7 @@ export class EntityRegistrySettingsEditor extends LitElement { )} naturalMenuWidth fixedMenuPosition - @selected=${this._switchAsChanged} + @selected=${this._switchAsDomainChanged} @closed=${stopPropagation} > ` : this.helperConfigEntry?.domain === "switch_as_x" ? html` - - ${domainToName(this.hass.localize, "switch")} - - - ${domainToName(this.hass.localize, domain)} - -
  • - ${this._switchAsDomainsSorted( - SWITCH_AS_DOMAINS, - this.hass.localize - ).map((entry) => - domain === entry.domain - ? nothing - : html` - - ${entry.label} - - ` - )} -
    ` + .label=${this.hass.localize( + "ui.dialogs.entity_registry.editor.switch_as_x" + )} + .value=${this._switchAsDomain} + naturalMenuWidth + fixedMenuPosition + @selected=${this._switchAsDomainChanged} + @closed=${stopPropagation} + > + + ${domainToName(this.hass.localize, "switch")} + + + ${domainToName(this.hass.localize, domain)} + +
  • + ${this._switchAsDomainsSorted( + SWITCH_AS_DOMAINS, + this.hass.localize + ).map((entry) => + domain === entry.domain + ? nothing + : html` + + ${entry.label} + + ` + )} + + ${SWITCH_AS_DOMAINS_INVERT.includes(this._switchAsDomain) + ? html` + + ${this.hass.localize( + "ui.dialogs.entity_registry.editor.invert.label" + )} + ${this.hass.localize( + `ui.dialogs.entity_registry.editor.invert.descriptions.${this._switchAsDomain}` + )} + + + ` + : nothing} ` : nothing} ${this._deviceClassOptions ? html` @@ -784,7 +813,9 @@ export class EntityRegistrySettingsEditor extends LitElement { ` : ""} - ${this.helperConfigEntry && this.helperConfigEntry.supports_options + ${this.helperConfigEntry && + this.helperConfigEntry.supports_options && + this.helperConfigEntry.domain !== "switch_as_x" ? html`