From 3c44a1353a848ca09aa63c4aed664aaa12de99cb Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Wed, 22 Jan 2020 09:23:35 -0500 Subject: [PATCH] change group id creation (#31075) --- homeassistant/components/zha/api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/zha/api.py b/homeassistant/components/zha/api.py index 5fb7f6d8fdb..3871a26c9d7 100644 --- a/homeassistant/components/zha/api.py +++ b/homeassistant/components/zha/api.py @@ -317,11 +317,14 @@ async def websocket_add_group(hass, connection, msg): """Add a new ZHA group.""" zha_gateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] ha_device_registry = await async_get_registry(hass) - group_id = len(zha_gateway.application_controller.groups) + 1 group_name = msg[GROUP_NAME] zigpy_group = async_get_group_by_name(zha_gateway, group_name) ret_group = None members = msg.get(ATTR_MEMBERS) + # we start with one to fill any gaps from a user removing existing groups + group_id = 1 + while group_id in zha_gateway.application_controller.groups: + group_id += 1 # guard against group already existing if zigpy_group is None: