Make the radius of the home zone configurable (#21096)

This commit is contained in:
Franck Nijhof 2024-06-15 14:41:09 +02:00 committed by GitHub
parent bb3e8ae33d
commit 8759ed740a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 11 deletions

View File

@ -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;

View File

@ -14,6 +14,7 @@ export interface Zone {
export interface HomeZoneMutableParams {
latitude: number;
longitude: number;
radius: number;
}
export interface ZoneMutableParams {

View File

@ -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}
></ha-form>
<p>
${this.hass!.localize(
"ui.panel.config.zone.detail.no_edit_home_zone_radius"
)}
</p>
</div>
<mwc-button
slot="primaryAction"
@ -95,7 +91,7 @@ class DialogHomeZoneDetail extends LitElement {
location: {
latitude: data.latitude,
longitude: data.longitude,
radius: this.hass.states["zone.home"]?.attributes?.radius || 100,
radius: data.radius || 100,
},
}));
@ -104,6 +100,7 @@ class DialogHomeZoneDetail extends LitElement {
const value = { ...ev.detail.value };
value.latitude = value.location.latitude;
value.longitude = value.location.longitude;
value.radius = value.location.radius;
delete value.location;
this._data = value;
}

View File

@ -101,7 +101,8 @@ export class HaConfigZone extends SubscribeMixin(LitElement) {
: zoneRadiusColor,
location_editable:
entityState.entity_id === "zone.home" && this._canEditCore,
radius_editable: false,
radius_editable:
entityState.entity_id === "zone.home" && this._canEditCore,
})
);
const storageLocations: MarkerLocation[] = storageItems.map((zone) => ({
@ -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");
}

View File

@ -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"
},