Skip to content

Commit

Permalink
Update custom entity name logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 2, 2024
1 parent 36c53d9 commit 3dc3291
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions custom_components/xiaomi_gateway3/core/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
- `led` - control device led light
- `wireless` - change mode from wired to wireless (decoupled)
- `power_on_state` - default state when electricity is supplied
- `contact` - for contact sensor
- `moisture` - for water leak sensor
- `contact` - for door/windor sensor (zigbee2mqtt - contact, hass - door or window)
- `water_leak` - for water leak sensor (zigbee2mqtt - water_leak, hass - moisture)
Nice project with MIoT spec description: https://home.miot-spec.com/
"""
Expand Down
10 changes: 7 additions & 3 deletions custom_components/xiaomi_gateway3/hass/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,20 @@ def __init__(self, device: "XDevice", conv: "BaseConv"):
hw_version=device.extra.get("hw_ver"),
via_device=via_device,
)
# self._attr_entity_registry_enabled_default = conv.enabled in (True, None)
self._attr_has_entity_name = True
self._attr_name = attr_human_name(conv.attr)
self._attr_should_poll = False
self._attr_unique_id = f"{device.uid}_{conv.attr}"

setup_entity_description(self, conv)

entity_name = device.extra.get("entity_name") or device.uid
self.entity_id = f"{conv.domain}.{entity_name}_{conv.attr}"
if entity_name := device.extra.get("entity_name"):
if entity_name.endswith(conv.attr):
self.entity_id = f"{conv.domain}.{entity_name}"
else:
self.entity_id = f"{conv.domain}.{entity_name}_{conv.attr}"
else:
self.entity_id = f"{conv.domain}.{device.uid}_{conv.attr}"

self.on_init()

Expand Down

0 comments on commit 3dc3291

Please sign in to comment.