From d77ce721e36ec12e947b63e1cb0345607038dd91 Mon Sep 17 00:00:00 2001 From: Dmitry Tsydzik Date: Mon, 18 Dec 2023 17:37:57 +0300 Subject: [PATCH] Add possibility to define group id manually for ZHA (#18932) Co-authored-by: Bram Kragten --- src/data/zha.ts | 2 ++ .../zha/zha-add-group-page.ts | 25 ++++++++++++++++++- src/translations/en.json | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/data/zha.ts b/src/data/zha.ts index b3f7b084a708..560538497388 100644 --- a/src/data/zha.ts +++ b/src/data/zha.ts @@ -383,11 +383,13 @@ export const removeMembersFromGroup = ( export const addGroup = ( hass: HomeAssistant, groupName: string, + groupId?: number, membersToAdd?: ZHAGroupMember[] ): Promise => hass.callWS({ type: "zha/group/add", group_name: groupName, + group_id: groupId, members: membersToAdd, }); diff --git a/src/panels/config/integrations/integration-panels/zha/zha-add-group-page.ts b/src/panels/config/integrations/integration-panels/zha/zha-add-group-page.ts index 4581ac7a914a..367485563c1b 100644 --- a/src/panels/config/integrations/integration-panels/zha/zha-add-group-page.ts +++ b/src/panels/config/integrations/integration-panels/zha/zha-add-group-page.ts @@ -30,6 +30,8 @@ export class ZHAAddGroupPage extends LitElement { @state() private _groupName = ""; + @state() private _groupId?: string; + @query("zha-device-endpoint-data-table", true) private _zhaDevicesDataTable!: ZHADeviceEndpointDataTable; @@ -74,6 +76,15 @@ export class ZHAAddGroupPage extends LitElement { )} > + +
${this.hass.localize("ui.panel.config.zha.groups.add_members")}
@@ -130,7 +141,15 @@ export class ZHAAddGroupPage extends LitElement { const memberParts = member.split("_"); return { ieee: memberParts[0], endpoint_id: memberParts[1] }; }); - const group: ZHAGroup = await addGroup(this.hass, this._groupName, members); + const groupId = this._groupId + ? parseInt(this._groupId as string, 10) + : undefined; + const group: ZHAGroup = await addGroup( + this.hass, + this._groupName, + groupId, + members + ); this._selectedDevicesToAdd = []; this._processingAdd = false; this._groupName = ""; @@ -138,6 +157,10 @@ export class ZHAAddGroupPage extends LitElement { navigate(`/config/zha/group/${group.group_id}`, { replace: true }); } + private _handleGroupIdChange(event) { + this._groupId = event.target.value; + } + private _handleNameChange(event) { this._groupName = event.target.value || ""; } diff --git a/src/translations/en.json b/src/translations/en.json index 057f6f37bc26..eda7d0953cb4 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4039,6 +4039,7 @@ "removing_members": "Removing devices", "create_group_details": "Enter the required details to create a new Zigbee group", "group_name_placeholder": "Group name", + "group_id_placeholder": "Group ID (optional)", "create_group": "Create group", "create": "Create group", "creating_group": "Creating group",