From 8759ed740a9a2578abff370634bee34d87862a50 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 15 Jun 2024 14:41:09 +0200 Subject: [PATCH] Make the radius of the home zone configurable (#21096) --- src/data/core.ts | 1 + src/data/zone.ts | 1 + src/panels/config/zone/dialog-home-zone-detail.ts | 11 ++++------- src/panels/config/zone/ha-config-zone.ts | 12 ++++++++++-- src/translations/en.json | 3 +-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/data/core.ts b/src/data/core.ts index 889db332a8..60dbf556f9 100644 --- a/src/data/core.ts +++ b/src/data/core.ts @@ -6,6 +6,7 @@ export interface ConfigUpdateValues { latitude: number; longitude: number; elevation: number; + radius: number; unit_system: "metric" | "us_customary"; time_zone: string; external_url?: string | null; diff --git a/src/data/zone.ts b/src/data/zone.ts index d59e33e87f..5f0ccb4102 100644 --- a/src/data/zone.ts +++ b/src/data/zone.ts @@ -14,6 +14,7 @@ export interface Zone { export interface HomeZoneMutableParams { latitude: number; longitude: number; + radius: number; } export interface ZoneMutableParams { diff --git a/src/panels/config/zone/dialog-home-zone-detail.ts b/src/panels/config/zone/dialog-home-zone-detail.ts index 2786cca3cb..fd0d1edd49 100644 --- a/src/panels/config/zone/dialog-home-zone-detail.ts +++ b/src/panels/config/zone/dialog-home-zone-detail.ts @@ -14,7 +14,7 @@ const SCHEMA = [ { name: "location", required: true, - selector: { location: { radius: true, radius_readonly: true } }, + selector: { location: { radius: true } }, }, ]; @@ -35,6 +35,7 @@ class DialogHomeZoneDetail extends LitElement { this._data = { latitude: this.hass.config.latitude, longitude: this.hass.config.longitude, + radius: this.hass.config.radius, }; } @@ -73,11 +74,6 @@ class DialogHomeZoneDetail extends LitElement { .computeLabel=${this._computeLabel} @value-changed=${this._valueChanged} > -

- ${this.hass!.localize( - "ui.panel.config.zone.detail.no_edit_home_zone_radius" - )} -

({ @@ -381,8 +382,14 @@ export class HaConfigZone extends SubscribeMixin(LitElement) { }); } - private _radiusUpdated(ev: CustomEvent) { + private async _radiusUpdated(ev: CustomEvent) { this._activeEntry = ev.detail.id; + if (ev.detail.id === "zone.home" && this._canEditCore) { + await saveCoreConfig(this.hass, { + radius: Math.round(ev.detail.radius), + }); + return; + } const entry = this._storageItems!.find((item) => item.id === ev.detail.id); if (!entry) { return; @@ -478,6 +485,7 @@ export class HaConfigZone extends SubscribeMixin(LitElement) { await saveCoreConfig(this.hass, { latitude: values.latitude, longitude: values.longitude, + radius: values.radius, }); this._zoomZone("zone.home"); } diff --git a/src/translations/en.json b/src/translations/en.json index 69bf915d71..94bff52f7d 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4168,8 +4168,7 @@ "required_error_msg": "This field is required", "delete": "Delete", "create": "Add", - "update": "Update", - "no_edit_home_zone_radius": "The radius of the home zone is not editable in the UI." + "update": "Update" }, "core_location_dialog": "Home Assistant location" },