Update ZHA manage device dialog to use a form for cluster command arguments (#14052)

This commit is contained in:
David F. Mulcahey 2022-10-26 07:19:48 -04:00 committed by GitHub
parent c12e6662dd
commit 16bd1f5883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 3 deletions

View File

@ -14,6 +14,7 @@ class HaCallServiceButton extends EventsMixin(PolymerElement) {
<ha-progress-button <ha-progress-button
id="progress" id="progress"
progress="[[progress]]" progress="[[progress]]"
disabled="[[disabled]]"
on-click="buttonTapped" on-click="buttonTapped"
tabindex="0" tabindex="0"
><slot></slot ><slot></slot
@ -48,6 +49,10 @@ class HaCallServiceButton extends EventsMixin(PolymerElement) {
confirmation: { confirmation: {
type: String, type: String,
}, },
disabled: {
type: Boolean,
},
}; };
} }

View File

@ -106,6 +106,7 @@ export interface Command {
name: string; name: string;
id: number; id: number;
type: string; type: string;
schema: HaFormSchema[];
} }
export interface ReadAttributeServiceData { export interface ReadAttributeServiceData {

View File

@ -35,6 +35,7 @@ export interface IssueCommandServiceData {
cluster_type: string; cluster_type: string;
command: number; command: number;
command_type: string; command_type: string;
params?: any;
} }
export interface ZHADeviceSelectedParams { export interface ZHADeviceSelectedParams {

View File

@ -13,6 +13,7 @@ import { stopPropagation } from "../../../../../common/dom/stop_propagation";
import "../../../../../components/buttons/ha-call-service-button"; import "../../../../../components/buttons/ha-call-service-button";
import "../../../../../components/ha-card"; import "../../../../../components/ha-card";
import "../../../../../components/ha-select"; import "../../../../../components/ha-select";
import "../../../../../components/ha-form/ha-form";
import { import {
Cluster, Cluster,
Command, Command,
@ -42,6 +43,12 @@ export class ZHAClusterCommands extends LitElement {
@state() @state()
private _issueClusterCommandServiceData?: IssueCommandServiceData; private _issueClusterCommandServiceData?: IssueCommandServiceData;
@state()
private _canIssueCommand = false;
@state()
private _commandData: Record<string, any> = {};
protected updated(changedProperties: PropertyValues): void { protected updated(changedProperties: PropertyValues): void {
if (changedProperties.has("selectedCluster")) { if (changedProperties.has("selectedCluster")) {
this._commands = undefined; this._commands = undefined;
@ -93,12 +100,23 @@ export class ZHAClusterCommands extends LitElement {
)} )}
></paper-input> ></paper-input>
</div> </div>
<div class="command-form">
<ha-form
.hass=${this.hass}
.schema=${this._commands.find(
(command) => command.id === this._selectedCommandId
)!.schema}
@value-changed=${this._commandDataChanged}
.data=${this._commandData}
></ha-form>
</div>
<div class="card-actions"> <div class="card-actions">
<ha-call-service-button <ha-call-service-button
.hass=${this.hass} .hass=${this.hass}
domain="zha" domain="zha"
service="issue_zigbee_cluster_command" service="issue_zigbee_cluster_command"
.serviceData=${this._issueClusterCommandServiceData} .serviceData=${this._issueClusterCommandServiceData}
.disabled=${!this._canIssueCommand}
> >
${this.hass!.localize( ${this.hass!.localize(
"ui.panel.config.zha.cluster_commands.issue_zigbee_command" "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) { if (!this.device || !this.selectedCluster || !this._commands) {
return undefined; 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 { return {
ieee: this.device!.ieee, ieee: this.device!.ieee,
endpoint_id: this.selectedCluster!.endpoint_id, endpoint_id: this.selectedCluster!.endpoint_id,
cluster_id: this.selectedCluster!.id, cluster_id: this.selectedCluster!.id,
cluster_type: this.selectedCluster!.type, cluster_type: this.selectedCluster!.type,
command: this._selectedCommandId!, command: this._selectedCommandId!,
command_type: this._commands.find( command_type: selectedCommand!.type,
(command) => command.id === this._selectedCommandId params: this._commandData,
)!.type,
}; };
} }
private async _commandDataChanged(ev: CustomEvent): Promise<void> {
this._commandData = ev.detail.value;
this._issueClusterCommandServiceData =
this._computeIssueClusterCommandServiceData();
}
private _onManufacturerCodeOverrideChanged(value: ChangeEvent): void { private _onManufacturerCodeOverrideChanged(value: ChangeEvent): void {
this._manufacturerCodeOverride = value.detail!.value; this._manufacturerCodeOverride = value.detail!.value;
this._issueClusterCommandServiceData = this._issueClusterCommandServiceData =
@ -185,6 +220,12 @@ export class ZHAClusterCommands extends LitElement {
padding-bottom: 10px; padding-bottom: 10px;
} }
.command-form {
padding-left: 28px;
padding-right: 28px;
padding-bottom: 10px;
}
.header { .header {
flex-grow: 1; flex-grow: 1;
} }