Skip to content

Commit

Permalink
clean up handle_cluster_handler_attribute_updated
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Mar 26, 2024
1 parent b984e08 commit 3166b86
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 4 deletions.
6 changes: 4 additions & 2 deletions zha/application/platforms/cover/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
from typing import TYPE_CHECKING, Any, cast

from zigpy.zcl.clusters.general import OnOff
from zigpy.zcl.foundation import Status

from zha.application import Platform
Expand Down Expand Up @@ -394,8 +395,9 @@ def handle_cluster_handler_attribute_updated(
self, event: ClusterAttributeUpdatedEvent
) -> None:
"""Set open/closed state."""
self._is_open = bool(event.attribute_value)
self.maybe_emit_state_changed_event()
if event.attribute_id == OnOff.AttributeDefs.on_off.id:
self._is_open = bool(event.attribute_value)
self.maybe_emit_state_changed_event()

def handle_cluster_handler_set_level(self, event: LevelChangeEvent) -> None:
"""Set the reported position."""
Expand Down
7 changes: 6 additions & 1 deletion zha/application/platforms/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import time
from typing import TYPE_CHECKING

from zigpy.zcl.clusters.general import PowerConfiguration

from zha.application import Platform
from zha.application.platforms import PlatformEntity
from zha.application.platforms.sensor import Battery
Expand Down Expand Up @@ -111,7 +113,10 @@ def handle_cluster_handler_attribute_updated(
self, event: ClusterAttributeUpdatedEvent
) -> None:
"""Handle tracking."""
if event.attribute_name != "battery_percentage_remaining":
if (
event.attribute_name
!= PowerConfiguration.AttributeDefs.battery_percentage_remaining.name
):
return
self.debug("battery_percentage_remaining updated: %s", event.attribute_value)
self._connected = True
Expand Down
5 changes: 5 additions & 0 deletions zha/application/platforms/light/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,11 @@ def handle_cluster_handler_attribute_updated(
self, event: ClusterAttributeUpdatedEvent
) -> None:
"""Set the state."""
if (
event.cluster_id != self._on_off_cluster_handler.cluster.cluster_id
or event.attribute_id != OnOff.AttributeDefs.on_off.id
):
return
if self.is_transitioning:
self.debug(
"received onoff %s while transitioning - skipping update",
Expand Down
3 changes: 3 additions & 0 deletions zha/application/platforms/lock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import functools
from typing import TYPE_CHECKING, Any

from zigpy.zcl.clusters.closures import DoorLock as DoorLockCluster
from zigpy.zcl.foundation import Status

from zha.application import Platform
Expand Down Expand Up @@ -111,6 +112,8 @@ def handle_cluster_handler_attribute_updated(
self, event: ClusterAttributeUpdatedEvent
) -> None:
"""Handle state update from cluster handler."""
if event.attribute_id != DoorLockCluster.AttributeDefs.lock_state.id:
return
self._state = VALUE_TO_STATE.get(event.attribute_value, self._state)
self.maybe_emit_state_changed_event()

Expand Down
3 changes: 2 additions & 1 deletion zha/application/platforms/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def handle_cluster_handler_attribute_updated(
event: ClusterAttributeUpdatedEvent, # pylint: disable=unused-argument
) -> None:
"""Handle state update from cluster handler."""
self.maybe_emit_state_changed_event()
if event.attribute_name == OnOff.AttributeDefs.on_off.name:
self.maybe_emit_state_changed_event()


@GROUP_MATCH()
Expand Down
2 changes: 2 additions & 0 deletions zha/zigbee/cluster_handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class ClusterAttributeUpdatedEvent:
attribute_name: str
attribute_value: Any
cluster_handler_unique_id: str
cluster_id: int
event_type: Final[str] = CLUSTER_HANDLER_EVENT
event: Final[str] = CLUSTER_HANDLER_ATTRIBUTE_UPDATED

Expand Down Expand Up @@ -465,6 +466,7 @@ def attribute_updated(self, attrid: int, value: Any, _: Any) -> None:
attribute_name=attr_name,
attribute_value=value,
cluster_handler_unique_id=self.unique_id,
cluster_id=self.cluster.cluster_id,
),
)

Expand Down
2 changes: 2 additions & 0 deletions zha/zigbee/cluster_handlers/closures.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async def async_update(self):
attribute_name=DoorLock.AttributeDefs.lock_state.name,
attribute_value=result,
cluster_handler_unique_id=self.unique_id,
cluster_id=self.cluster.cluster_id,
),
)

Expand Down Expand Up @@ -83,6 +84,7 @@ def attribute_updated(self, attrid: int, value: Any, _: Any) -> None:
attribute_name=attr_name,
attribute_value=value,
cluster_handler_unique_id=self.unique_id,
cluster_id=self.cluster.cluster_id,
),
)

Expand Down
1 change: 1 addition & 0 deletions zha/zigbee/cluster_handlers/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ def attribute_updated(self, attrid: int, value: Any, _: Any) -> None:
attribute_name=OnOff.AttributeDefs.on_off.name,
attribute_value=value,
cluster_handler_unique_id=self.unique_id,
cluster_id=self.cluster.cluster_id,
),
)

Expand Down
2 changes: 2 additions & 0 deletions zha/zigbee/cluster_handlers/hvac.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def attribute_updated(self, attrid: int, value: Any, _: Any) -> None:
attribute_name=attr_name,
attribute_value=value,
cluster_handler_unique_id=self.unique_id,
cluster_id=self.cluster.cluster_id,
),
)

Expand Down Expand Up @@ -304,6 +305,7 @@ def attribute_updated(self, attrid: int, value: Any, _: Any) -> None:
attribute_name=attr_name,
attribute_value=value,
cluster_handler_unique_id=self.unique_id,
cluster_id=self.cluster.cluster_id,
),
)

Expand Down
1 change: 1 addition & 0 deletions zha/zigbee/cluster_handlers/manufacturerspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def attribute_updated(self, attrid: int, value: Any, _: Any) -> None:
attribute_name=attr_name,
attribute_value=value,
cluster_handler_unique_id=self.unique_id,
cluster_id=self.cluster.cluster_id,
),
)
return
Expand Down
1 change: 1 addition & 0 deletions zha/zigbee/cluster_handlers/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ def attribute_updated(self, attrid: int, value: Any, _: Any) -> None:
attribute_name=IasZone.AttributeDefs.zone_status.name,
attribute_value=value,
cluster_handler_unique_id=self.unique_id,
cluster_id=self.cluster.cluster_id,
),
)

Expand Down

0 comments on commit 3166b86

Please sign in to comment.