diff --git a/src/data/zha.ts b/src/data/zha.ts index e57df4078a..64abb74087 100644 --- a/src/data/zha.ts +++ b/src/data/zha.ts @@ -1,4 +1,5 @@ import { HassEntity } from "home-assistant-js-websocket"; +import { HaFormSchema } from "../components/ha-form/ha-form"; import { HomeAssistant } from "../types"; export interface ZHAEntityReference extends HassEntity { @@ -75,6 +76,11 @@ export interface ZHAGroup { members: ZHADeviceEndpoint[]; } +export interface ZHAConfiguration { + data: Record>; + schemas: Record; +} + export interface ZHAGroupMember { ieee: string; endpoint_id: string; @@ -282,6 +288,22 @@ export const addGroup = ( members: membersToAdd, }); +export const fetchZHAConfiguration = ( + hass: HomeAssistant +): Promise => + hass.callWS({ + type: "zha/configuration", + }); + +export const updateZHAConfiguration = ( + hass: HomeAssistant, + data: any +): Promise => + hass.callWS({ + type: "zha/configuration/update", + data: data, + }); + export const INITIALIZED = "INITIALIZED"; export const INTERVIEW_COMPLETE = "INTERVIEW_COMPLETE"; export const CONFIGURED = "CONFIGURED"; diff --git a/src/panels/config/integrations/integration-panels/zha/zha-config-dashboard.ts b/src/panels/config/integrations/integration-panels/zha/zha-config-dashboard.ts index a1fcbf1bbf..5fc0a889f9 100644 --- a/src/panels/config/integrations/integration-panels/zha/zha-config-dashboard.ts +++ b/src/panels/config/integrations/integration-panels/zha/zha-config-dashboard.ts @@ -9,6 +9,7 @@ import { html, LitElement, property, + PropertyValues, TemplateResult, } from "lit-element"; import { computeRTL } from "../../../../../common/util/compute_rtl"; @@ -20,6 +21,12 @@ import type { PageNavigation } from "../../../../../layouts/hass-tabs-subpage"; import { haStyle } from "../../../../../resources/styles"; import type { HomeAssistant, Route } from "../../../../../types"; import "../../../ha-config-section"; +import "../../../../../components/ha-form/ha-form"; +import { + fetchZHAConfiguration, + updateZHAConfiguration, + ZHAConfiguration, +} from "../../../../../data/zha"; export const zhaTabs: PageNavigation[] = [ { @@ -51,6 +58,15 @@ class ZHAConfigDashboard extends LitElement { @property() public configEntryId?: string; + @property() private _configuration?: ZHAConfiguration; + + protected firstUpdated(changedProperties: PropertyValues): void { + super.firstUpdated(changedProperties); + if (this.hass) { + this._fetchConfiguration(); + } + } + protected render(): TemplateResult { return html` - -
- In the future you can change network settings for ZHA here. -
+ ${this.configEntryId ? html`
` : ""} + ${this._configuration + ? Object.entries(this._configuration.schemas).map( + ([section, schema]) => html` +
+ +
+
` + ) + : ""} + +
+ + ${this.hass.localize( + "ui.panel.config.zha.configuration_page.update_button" + )} + +
+
+
{ + this._configuration = await fetchZHAConfiguration(this.hass!); + } + + private _dataChanged(ev) { + this._configuration!.data[ev.currentTarget!.section] = ev.detail.value; + } + + private async _updateConfiguration(): Promise { + await updateZHAConfiguration(this.hass!, this._configuration!.data); + } + + private _computeLabelCallback(localize, section: string) { + // Returns a callback for ha-form to calculate labels per schema object + return (schema) => + localize( + `ui.panel.config.zha.configuration_page.${section}.${schema.name}` + ) || schema.name; + } + static get styles(): CSSResultArray { return [ haStyle, diff --git a/src/translations/en.json b/src/translations/en.json index b69f874f60..3edb0f751e 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2386,6 +2386,15 @@ "manufacturer_code_override": "Manufacturer Code Override", "value": "Value" }, + "configuration_page": { + "shortcuts_title": "Shortcuts", + "update_button": "Update Configuration", + "zha_options": { + "title": "Global Options", + "enable_identify_on_join": "Enable identify effect when devices join the network", + "default_light_transition": "Default light transition time (seconds)" + } + }, "add_device_page": { "spinner": "Searching for ZHA Zigbee devices...", "pairing_mode": "Make sure your devices are in pairing mode. Check the instructions of your device on how to do this.",