diff --git a/src/data/entity/entity_registry.ts b/src/data/entity/entity_registry.ts index daf4247dae..68b556c693 100644 --- a/src/data/entity/entity_registry.ts +++ b/src/data/entity/entity_registry.ts @@ -161,6 +161,10 @@ export interface VacuumEntityOptions { last_seen_segments?: Segment[]; } +export interface DeviceTrackerEntityOptions { + associated_zone?: string | null; +} + export interface EntityRegistryOptions { number?: NumberEntityOptions; sensor?: SensorEntityOptions; @@ -172,6 +176,7 @@ export interface EntityRegistryOptions { cover?: CoverEntityOptions; valve?: ValveEntityOptions; vacuum?: VacuumEntityOptions; + device_tracker?: DeviceTrackerEntityOptions; switch_as_x?: SwitchAsXEntityOptions; conversation?: Record; "cloud.alexa"?: Record; @@ -197,7 +202,8 @@ export interface EntityRegistryEntryUpdateParams { | LightEntityOptions | CoverEntityOptions | ValveEntityOptions - | VacuumEntityOptions; + | VacuumEntityOptions + | DeviceTrackerEntityOptions; aliases?: (string | null)[]; labels?: string[]; categories?: Record; diff --git a/src/panels/config/entities/entity-registry-settings-editor.ts b/src/panels/config/entities/entity-registry-settings-editor.ts index be45a15f75..45ef5053e3 100644 --- a/src/panels/config/entities/entity-registry-settings-editor.ts +++ b/src/panels/config/entities/entity-registry-settings-editor.ts @@ -23,6 +23,7 @@ import "../../../components/ha-alert"; import "../../../components/ha-area-picker"; import "../../../components/ha-color-picker"; import "../../../components/ha-dropdown-item"; +import "../../../components/entity/ha-entity-picker"; import "../../../components/ha-icon"; import "../../../components/ha-icon-button-next"; import "../../../components/ha-icon-picker"; @@ -56,6 +57,7 @@ import { updateDeviceRegistryEntry } from "../../../data/device/device_registry" import type { AlarmControlPanelEntityOptions, CalendarEntityOptions, + DeviceTrackerEntityOptions, EntityRegistryEntry, EntityRegistryEntryUpdateParams, ExtEntityRegistryEntry, @@ -138,6 +140,10 @@ const SWITCH_AS_DOMAINS_INVERT = ["cover", "lock", "valve"]; const PRECISIONS = [0, 1, 2, 3, 4, 5, 6]; +const SCANNER_SOURCE_TYPES = ["router", "bluetooth", "bluetooth_le"]; + +const ZONE_DOMAINS = ["zone"]; + @customElement("entity-registry-settings-editor") export class EntityRegistrySettingsEditor extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -202,6 +208,8 @@ export class EntityRegistrySettingsEditor extends LitElement { @state() private _calendarColor?: string | null; + @state() private _associatedZone?: string; + @state() private _noDeviceArea?: boolean; private _origEntityId!: string; @@ -292,6 +300,11 @@ export class EntityRegistrySettingsEditor extends LitElement { this._calendarColor = this.entry.options?.calendar?.color; } + if (domain === "device_tracker") { + this._associatedZone = + this.entry.options?.device_tracker?.associated_zone ?? "zone.home"; + } + if (domain === "weather") { const stateObj: HassEntity | undefined = this.hass.states[this.entry.entity_id]; @@ -713,6 +726,21 @@ export class EntityRegistrySettingsEditor extends LitElement { > ` : nothing} + ${domain === "device_tracker" && + SCANNER_SOURCE_TYPES.includes(stateObj?.attributes?.source_type) + ? html` + + ` + : nothing} ${domain === "sensor" && this._deviceClass && stateObj?.attributes.unit_of_measurement && @@ -1208,6 +1236,17 @@ export class EntityRegistrySettingsEditor extends LitElement { (params.options as CalendarEntityOptions).color = this._calendarColor; } } + if ( + domain === "device_tracker" && + this._associatedZone !== undefined && + (this.entry.options?.device_tracker?.associated_zone ?? "zone.home") !== + this._associatedZone + ) { + params.options_domain = "device_tracker"; + params.options = { + associated_zone: this._associatedZone, + } as DeviceTrackerEntityOptions; + } if ( domain === "weather" && (stateObj?.attributes?.precipitation_unit !== this._precipitation_unit || @@ -1447,6 +1486,11 @@ export class EntityRegistrySettingsEditor extends LitElement { this._calendarColor = ev.detail.value || null; } + private _associatedZoneChanged(ev: CustomEvent): void { + fireEvent(this, "change"); + this._associatedZone = ev.detail.value || "zone.home"; + } + private _precipitationUnitChanged(ev: HaSelectSelectEvent): void { fireEvent(this, "change"); this._precipitation_unit = ev.detail.value; diff --git a/src/translations/en.json b/src/translations/en.json index f999d059c1..8064f53513 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1891,6 +1891,7 @@ "default_code": "Default code", "default_code_error": "Code does not match code format", "calendar_color": "Calendar color", + "associated_zone": "Associated zone", "entity_id": "Entity ID", "unit_of_measurement": "Unit of measurement", "precipitation_unit": "Precipitation unit",