From 16bd1f5883a567171e0d922c6e6d61bf9c4d05fc Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Wed, 26 Oct 2022 07:19:48 -0400 Subject: [PATCH] Update ZHA manage device dialog to use a form for cluster command arguments (#14052) --- .../buttons/ha-call-service-button.js | 5 ++ src/data/zha.ts | 1 + .../integration-panels/zha/types.ts | 1 + .../zha/zha-cluster-commands.ts | 47 +++++++++++++++++-- 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/components/buttons/ha-call-service-button.js b/src/components/buttons/ha-call-service-button.js index 6695ea7b0d..aa53eec5ac 100644 --- a/src/components/buttons/ha-call-service-button.js +++ b/src/components/buttons/ha-call-service-button.js @@ -14,6 +14,7 @@ class HaCallServiceButton extends EventsMixin(PolymerElement) { = {}; + protected updated(changedProperties: PropertyValues): void { if (changedProperties.has("selectedCluster")) { this._commands = undefined; @@ -93,12 +100,23 @@ export class ZHAClusterCommands extends LitElement { )} > +
+ command.id === this._selectedCommandId + )!.schema} + @value-changed=${this._commandDataChanged} + .data=${this._commandData} + > +
${this.hass!.localize( "ui.panel.config.zha.cluster_commands.issue_zigbee_command" @@ -133,18 +151,35 @@ export class ZHAClusterCommands extends LitElement { if (!this.device || !this.selectedCluster || !this._commands) { return undefined; } + const selectedCommand = this._commands.find( + (command) => command.id === this._selectedCommandId + ); + + this._canIssueCommand = + this._commandData && + selectedCommand!.schema.every( + (field) => + !field.required || + !["", undefined].includes(this._commandData![field.name]) + ); + return { ieee: this.device!.ieee, endpoint_id: this.selectedCluster!.endpoint_id, cluster_id: this.selectedCluster!.id, cluster_type: this.selectedCluster!.type, command: this._selectedCommandId!, - command_type: this._commands.find( - (command) => command.id === this._selectedCommandId - )!.type, + command_type: selectedCommand!.type, + params: this._commandData, }; } + private async _commandDataChanged(ev: CustomEvent): Promise { + this._commandData = ev.detail.value; + this._issueClusterCommandServiceData = + this._computeIssueClusterCommandServiceData(); + } + private _onManufacturerCodeOverrideChanged(value: ChangeEvent): void { this._manufacturerCodeOverride = value.detail!.value; this._issueClusterCommandServiceData = @@ -185,6 +220,12 @@ export class ZHAClusterCommands extends LitElement { padding-bottom: 10px; } + .command-form { + padding-left: 28px; + padding-right: 28px; + padding-bottom: 10px; + } + .header { flex-grow: 1; }