Skip to content
652 changes: 343 additions & 309 deletions majordom_zigbee/controller.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions majordom_zigbee/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@


class ZBAttributeUpdatedListener:
def __init__(self, controller, device_id: UUID, cluster: Cluster):
def __init__(self, controller, physical_id: UUID, cluster: Cluster):
self._controller = controller
self._device_id = device_id
self._physical_id = physical_id
self._cluster = cluster

def attribute_updated(self, attribute_id, value, time):
cluster = self._cluster
endpoint_id = cluster.endpoint.endpoint_id
parameter_id = self._controller._mapper.attribute_parameter_uuid(
self._device_id, endpoint_id, cluster.cluster_id, attribute_id
self._physical_id, endpoint_id, cluster.cluster_id, attribute_id
)
event = DeviceParameterChange(
device_id=self._device_id,
physical_id=self._physical_id,
parameter_id=parameter_id,
value=self._controller._mapper.normalize_zigbee_value(value),
)
Expand Down
22 changes: 9 additions & 13 deletions majordom_zigbee/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class ZigBeeMapper:
def __init__(
self,
device_uuid: Callable[[str], UUID],
device_uuid: Callable[[bytes], UUID],
parameter_uuid: Callable[[UUID, str], UUID],
):
# The controller's framework UUID generators (see AbstractController). Every Zigbee
Expand All @@ -27,12 +27,8 @@ def __init__(
# Identity: Zigbee addresses/paths -> MajorDom UUIDs
# -------------------------------------------------------------------------

def device_uuid_from_ieee(self, ieee: str | None) -> UUID:
# ieee is Optional on the domain model, but a paired Zigbee device always has one; a
# missing address here means a corrupt/half-written record, not a normal path.
if ieee is None:
raise ZBUnexpectedError("Zigbee device is missing its IEEE address")
return self._device_uuid(ieee)
def device_uuid_from_ieee(self, ieee: EUI64) -> UUID:
return self._device_uuid(bytes(ieee.serialize()))

def normalize_zigbee_value(self, value):
"""Coerce zigpy wire values to plain python types for the SDK's typed encoder.
Expand All @@ -56,16 +52,16 @@ def normalize_zigbee_value(self, value):
return str(value)
return value

def attribute_parameter_uuid(self, device_id: UUID, endpoint_id: int, cluster_id: int, attribute_id: int) -> UUID:
return self._parameter_uuid(device_id, f"attribute_{endpoint_id}/{cluster_id}/{attribute_id}")
def attribute_parameter_uuid(self, physical_id: UUID, endpoint_id: int, cluster_id: int, attribute_id: int) -> UUID:
return self._parameter_uuid(physical_id, f"attribute_{endpoint_id}/{cluster_id}/{attribute_id}")

def command_parameter_uuid(self, device_id: UUID, endpoint_id: int, cluster_id: int, command_id: int) -> UUID:
return self._parameter_uuid(device_id, f"command_{endpoint_id}/{cluster_id}/{command_id}")
def command_parameter_uuid(self, physical_id: UUID, endpoint_id: int, cluster_id: int, command_id: int) -> UUID:
return self._parameter_uuid(physical_id, f"command_{endpoint_id}/{cluster_id}/{command_id}")

def command_field_uuid(
self, device_id: UUID, endpoint_id: int, cluster_id: int, command_id: int, field_index: int
self, physical_id: UUID, endpoint_id: int, cluster_id: int, command_id: int, field_index: int
) -> UUID:
return self._parameter_uuid(device_id, f"field_{endpoint_id}/{cluster_id}/{command_id}/{field_index}")
return self._parameter_uuid(physical_id, f"field_{endpoint_id}/{cluster_id}/{command_id}/{field_index}")

# -------------------------------------------------------------------------
# Value / type conversions
Expand Down
Loading
Loading