Skip to content

Commit

Permalink
Create a ZHAGateway.coordinator_ieee shortcut property
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Jul 8, 2022
1 parent cc2b46f commit 7c86758
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
11 changes: 2 additions & 9 deletions homeassistant/components/zha/__init__.py
Expand Up @@ -109,15 +109,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
device_registry = dr.async_get(hass)
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={
(
dr.CONNECTION_ZIGBEE,
str(zha_gateway.application_controller.state.node_info.ieee),
)
},
identifiers={
(DOMAIN, str(zha_gateway.application_controller.state.node_info.ieee))
},
connections={(dr.CONNECTION_ZIGBEE, str(zha_gateway.coordinator_ieee))},
identifiers={(DOMAIN, str(zha_gateway.coordinator_ieee))},
name="Zigbee Coordinator",
manufacturer="ZHA",
model=zha_gateway.radio_description,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zha/core/device.py
Expand Up @@ -265,7 +265,7 @@ def is_active_coordinator(self) -> bool:
if not self.is_coordinator:
return False

return self.ieee == self.gateway.application_controller.state.node_info.ieee
return self.ieee == self.gateway.coordinator_ieee

@property
def is_end_device(self) -> bool | None:
Expand Down
11 changes: 7 additions & 4 deletions homeassistant/components/zha/core/gateway.py
Expand Up @@ -183,9 +183,7 @@ async def async_initialize(self) -> None:
self.application_controller.add_listener(self)
self.application_controller.groups.add_listener(self)
self._hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] = self
self._hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID] = str(
self.application_controller.state.node_info.ieee
)
self._hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID] = str(self.coordinator_ieee)
self.async_load_devices()
self.async_load_groups()

Expand All @@ -194,7 +192,7 @@ def async_load_devices(self) -> None:
"""Restore ZHA devices from zigpy application state."""
for zigpy_device in self.application_controller.devices.values():
zha_device = self._async_get_or_create_device(zigpy_device, restored=True)
if zha_device.ieee == self.application_controller.state.node_info.ieee:
if zha_device.ieee == self.coordinator_ieee:
self.coordinator_zha_device = zha_device
zha_dev_entry = self.zha_storage.devices.get(str(zigpy_device.ieee))
delta_msg = "not known"
Expand Down Expand Up @@ -448,6 +446,11 @@ def _cleanup_group_entity_registry_entries(
)
self.ha_entity_registry.async_remove(entry.entity_id)

@property
def coordinator_ieee(self) -> EUI64:
"""Return the active coordinator's IEEE address."""
return self.application_controller.state.node_info.ieee

@property
def devices(self) -> dict[EUI64, ZHADevice]:
"""Return devices."""
Expand Down

0 comments on commit 7c86758

Please sign in to comment.