mirror of
https://github.com/home-assistant/frontend.git
synced 2026-07-07 06:25:09 +01:00
Add associated zone option for device trackers (#52211)
This commit is contained in:
@@ -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<string, unknown>;
|
||||
"cloud.alexa"?: Record<string, unknown>;
|
||||
@@ -197,7 +202,8 @@ export interface EntityRegistryEntryUpdateParams {
|
||||
| LightEntityOptions
|
||||
| CoverEntityOptions
|
||||
| ValveEntityOptions
|
||||
| VacuumEntityOptions;
|
||||
| VacuumEntityOptions
|
||||
| DeviceTrackerEntityOptions;
|
||||
aliases?: (string | null)[];
|
||||
labels?: string[];
|
||||
categories?: Record<string, string | null>;
|
||||
|
||||
@@ -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 {
|
||||
></ha-color-picker>
|
||||
`
|
||||
: nothing}
|
||||
${domain === "device_tracker" &&
|
||||
SCANNER_SOURCE_TYPES.includes(stateObj?.attributes?.source_type)
|
||||
? html`
|
||||
<ha-entity-picker
|
||||
.hass=${this.hass}
|
||||
.value=${this._associatedZone}
|
||||
.label=${this.hass.localize(
|
||||
"ui.dialogs.entity_registry.editor.associated_zone"
|
||||
)}
|
||||
.includeDomains=${ZONE_DOMAINS}
|
||||
.disabled=${this.disabled}
|
||||
@value-changed=${this._associatedZoneChanged}
|
||||
></ha-entity-picker>
|
||||
`
|
||||
: 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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user