Identify the active ZHA coordinator device in API responses (#74739)

* Remove deprecated zigpy properties

* Create a `ZHADevice.is_active_coordinator` property

* Add `@puddly` to the ZHA code owners

* Create a `ZHAGateway.coordinator_ieee` shortcut property
This commit is contained in:
puddly 2022-07-11 14:19:30 -04:00 committed by GitHub
parent 14baaf4b67
commit 2986a2f01b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 18 deletions

View file

@ -30,6 +30,7 @@ from homeassistant.helpers.event import async_track_time_interval
from . import channels
from .const import (
ATTR_ACTIVE_COORDINATOR,
ATTR_ARGS,
ATTR_ATTRIBUTE,
ATTR_AVAILABLE,
@ -252,12 +253,20 @@ class ZHADevice(LogMixin):
@property
def is_coordinator(self) -> bool | None:
"""Return true if this device represents the coordinator."""
"""Return true if this device represents a coordinator."""
if self._zigpy_device.node_desc is None:
return None
return self._zigpy_device.node_desc.is_coordinator
@property
def is_active_coordinator(self) -> bool:
"""Return true if this device is the active coordinator."""
if not self.is_coordinator:
return False
return self.ieee == self.gateway.coordinator_ieee
@property
def is_end_device(self) -> bool | None:
"""Return true if this device is an end device."""
@ -499,6 +508,7 @@ class ZHADevice(LogMixin):
"""Get ZHA device information."""
device_info: dict[str, Any] = {}
device_info.update(self.device_info)
device_info[ATTR_ACTIVE_COORDINATOR] = self.is_active_coordinator
device_info["entities"] = [
{
"entity_id": entity_ref.reference_id,