From 7c867586d89d05c0887dfc53525022e9ddfa44c9 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Fri, 8 Jul 2022 13:38:18 -0400 Subject: [PATCH] Create a `ZHAGateway.coordinator_ieee` shortcut property --- homeassistant/components/zha/__init__.py | 11 ++--------- homeassistant/components/zha/core/device.py | 2 +- homeassistant/components/zha/core/gateway.py | 11 +++++++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/zha/__init__.py b/homeassistant/components/zha/__init__.py index 5bd94388141371..0527eacd4419e7 100644 --- a/homeassistant/components/zha/__init__.py +++ b/homeassistant/components/zha/__init__.py @@ -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, diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index b9630a3b2eb759..d8015f1e9450c5 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -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: diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index 28efa3db514222..932f9e70de11db 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -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() @@ -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" @@ -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."""