Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ZHA group creation #69629

Merged
merged 2 commits into from Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/zha/api.py
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions homeassistant/components/zha/core/device.py
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions homeassistant/components/zha/core/group.py
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

import asyncio
import collections
import logging
from typing import TYPE_CHECKING, Any, NamedTuple

Expand Down Expand Up @@ -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):
Expand Down