Skip to content

Commit

Permalink
Fix group entity name attribute (#42)
Browse files Browse the repository at this point in the history
* Fix entity name attribute

* only do this for groups

* just group name to match existing fuctionality

* tests
  • Loading branch information
dmulcahey committed Apr 5, 2024
1 parent c30c842 commit 0a0294e
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/common.py
Expand Up @@ -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='_')}"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fan.py
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_gateway.py
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_light.py
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_switch.py
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions zha/application/platforms/__init__.py
Expand Up @@ -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)

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

0 comments on commit 0a0294e

Please sign in to comment.