Skip to content

Commit

Permalink
Add possibility to define group id manually for ZHA (#18932)
Browse files Browse the repository at this point in the history
Co-authored-by: Bram Kragten <[email protected]>
  • Loading branch information
tsydd and bramkragten authored Dec 18, 2023
1 parent 325ad6f commit d77ce72
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/data/zha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,13 @@ export const removeMembersFromGroup = (
export const addGroup = (
hass: HomeAssistant,
groupName: string,
groupId?: number,
membersToAdd?: ZHAGroupMember[]
): Promise<ZHAGroup> =>
hass.callWS({
type: "zha/group/add",
group_name: groupName,
group_id: groupId,
members: membersToAdd,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -74,6 +76,15 @@ export class ZHAAddGroupPage extends LitElement {
)}
></ha-textfield>
<ha-textfield
type="number"
.value=${this._groupId}
@change=${this._handleGroupIdChange}
.placeholder=${this.hass!.localize(
"ui.panel.config.zha.groups.group_id_placeholder"
)}
></ha-textfield>
<div class="header">
${this.hass.localize("ui.panel.config.zha.groups.add_members")}
</div>
Expand Down Expand Up @@ -130,14 +141,26 @@ 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 = "";
this._zhaDevicesDataTable.clearSelection();
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 || "";
}
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d77ce72

Please sign in to comment.