From 0a0294e5ffdd1e7078a5ea6c62693fd858ba82f9 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Fri, 5 Apr 2024 12:39:45 -0400 Subject: [PATCH] Fix group entity name attribute (#42) * Fix entity name attribute * only do this for groups * just group name to match existing fuctionality * tests --- tests/common.py | 2 +- tests/test_fan.py | 2 +- tests/test_gateway.py | 2 +- tests/test_light.py | 1 + tests/test_switch.py | 1 + zha/application/platforms/__init__.py | 6 +++--- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/common.py b/tests/common.py index e966cc86..a35196a5 100644 --- a/tests/common.py +++ b/tests/common.py @@ -245,7 +245,7 @@ def find_entity_ids( def async_find_group_entity_id(domain: str, group: Group) -> Optional[str]: """Find the group entity id under test.""" - entity_id = f"{domain}.{group.name.lower().replace(' ','_')}_0x{group.group_id:04x}" + entity_id = f"{domain}.{group.name.lower().replace(' ','_')}" entity_ids = [ f"{entity.PLATFORM}.{slugify(entity.name, separator='_')}" diff --git a/tests/test_fan.py b/tests/test_fan.py index 269c3e31..86744b4b 100644 --- a/tests/test_fan.py +++ b/tests/test_fan.py @@ -308,8 +308,8 @@ async def test_zha_group_fan_entity( assert entity is not None assert entity.group_id == zha_group.group_id - assert isinstance(entity, GroupEntity) + assert entity.name == zha_group.name group_fan_cluster = zha_group.zigpy_group.endpoint[hvac.Fan.cluster_id] diff --git a/tests/test_gateway.py b/tests/test_gateway.py index 61e337c6..a1ea9ae7 100644 --- a/tests/test_gateway.py +++ b/tests/test_gateway.py @@ -224,7 +224,7 @@ async def test_gateway_group_methods( assert info.class_name == "LightGroup" assert info.platform == Platform.LIGHT assert info.unique_id == "light_zha_group_0x0002" - assert info.name == "Test Group_0x0002" + assert info.name == "Test Group" assert info.group_id == zha_group.group_id assert info.supported_features == LightEntityFeature.TRANSITION assert info.min_mireds == 153 diff --git a/tests/test_light.py b/tests/test_light.py index 09c8daeb..eb48bc94 100644 --- a/tests/test_light.py +++ b/tests/test_light.py @@ -742,6 +742,7 @@ async def test_zha_group_light_entity( assert isinstance(entity, GroupEntity) assert entity.group_id == zha_group.group_id + assert entity.name == zha_group.name device_1_entity_id = find_entity_id(Platform.LIGHT, device_light_1) assert device_1_entity_id is not None diff --git a/tests/test_switch.py b/tests/test_switch.py index d161648e..212e10ca 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -273,6 +273,7 @@ async def test_zha_group_switch_entity( assert isinstance(entity, GroupEntity) assert entity.group_id == zha_group.group_id + assert entity.name == zha_group.name group_cluster_on_off = zha_group.zigpy_group.endpoint[general.OnOff.cluster_id] dev1_cluster_on_off = device_switch_1.device.endpoints[1].on_off diff --git a/zha/application/platforms/__init__.py b/zha/application/platforms/__init__.py index e16a90e2..bdb49cf5 100644 --- a/zha/application/platforms/__init__.py +++ b/zha/application/platforms/__init__.py @@ -332,7 +332,7 @@ def __init__( ) -> None: """Initialize a group.""" super().__init__(f"{self.PLATFORM}_zha_group_0x{group.group_id:04x}") - self._name: str = f"{group.name}_0x{group.group_id:04x}" + self._attr_name: str = group.name self._group: Group = group self._group.register_group_entity(self) @@ -352,14 +352,14 @@ def info_object(self) -> GroupEntityInfo: unique_id=self._unique_id, platform=self.PLATFORM, class_name=self.__class__.__name__, - name=self._name, + name=self._attr_name, group_id=self.group_id, ) @property def name(self) -> str: """Return the name of the group entity.""" - return self._name + return self._attr_name @property def group_id(self) -> int: