diff --git a/homeassistant/components/zha/api.py b/homeassistant/components/zha/api.py index c42384682da1e7..faf8ccc5053211 100644 --- a/homeassistant/components/zha/api.py +++ b/homeassistant/components/zha/api.py @@ -232,7 +232,7 @@ def _cv_cluster_binding(value: dict[str, Any]) -> ClusterBinding: vol.Schema( { vol.Required(ATTR_IEEE): IEEE_SCHEMA, - vol.Required(ATTR_ENDPOINT_ID): int, + vol.Required(ATTR_ENDPOINT_ID): vol.Coerce(int), } ), _cv_group_member, @@ -244,8 +244,8 @@ def _cv_cluster_binding(value: dict[str, Any]) -> ClusterBinding: { vol.Required(ATTR_NAME): cv.string, vol.Required(ATTR_TYPE): cv.string, - vol.Required(ATTR_ID): int, - vol.Required(ATTR_ENDPOINT_ID): int, + vol.Required(ATTR_ID): vol.Coerce(int), + vol.Required(ATTR_ENDPOINT_ID): vol.Coerce(int), } ), _cv_cluster_binding, diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index e80a0725cc1275..41d90b48869d72 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -661,7 +661,11 @@ async def issue_cluster_command( async def async_add_to_group(self, group_id: int) -> None: """Add this device to the provided zigbee group.""" try: - await self._zigpy_device.add_to_group(group_id) + # A group name is required. However, the spec also explicitly states that + # the group name can be ignored by the receiving device if a device cannot + # store it, so we cannot rely on it existing after being written. This is + # only done to make the ZCL command valid. + await self._zigpy_device.add_to_group(group_id, name=f"0x{group_id:04X}") except (zigpy.exceptions.ZigbeeException, asyncio.TimeoutError) as ex: self.debug( "Failed to add device '%s' to group: 0x%04x ex: %s", @@ -687,7 +691,9 @@ async def async_add_endpoint_to_group( ) -> None: """Add the device endpoint to the provided zigbee group.""" try: - await self._zigpy_device.endpoints[endpoint_id].add_to_group(group_id) + await self._zigpy_device.endpoints[endpoint_id].add_to_group( + group_id, name=f"0x{group_id:04X}" + ) except (zigpy.exceptions.ZigbeeException, asyncio.TimeoutError) as ex: self.debug( "Failed to add endpoint: %s for device: '%s' to group: 0x%04x ex: %s", diff --git a/homeassistant/components/zha/core/group.py b/homeassistant/components/zha/core/group.py index af17f28e622e8d..1392041c4d4134 100644 --- a/homeassistant/components/zha/core/group.py +++ b/homeassistant/components/zha/core/group.py @@ -2,7 +2,6 @@ from __future__ import annotations import asyncio -import collections import logging from typing import TYPE_CHECKING, Any, NamedTuple @@ -30,9 +29,12 @@ class GroupMember(NamedTuple): endpoint_id: int -GroupEntityReference = collections.namedtuple( - "GroupEntityReference", "name original_name entity_id" -) +class GroupEntityReference(NamedTuple): + """Reference to a group entity.""" + + name: str + original_name: str + entity_id: int class ZHAGroupMember(LogMixin):