Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions zha/application/platforms/binary_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(
self._cluster_handler = cluster_handlers[0]
super().__init__(cluster_handlers, endpoint, device, **kwargs)
self._state: bool = self.is_on
self.recompute_capabilities()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method call is a bit weird in ZHA in general. self.recompute_capabilities() should be called as part of creating the instance but we don't have a way to do that in the base class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I noticed 😄


def on_add(self) -> None:
"""Run when entity is added."""
Expand Down Expand Up @@ -247,16 +248,10 @@ class IASZone(BinarySensor):

# TODO: split this sensor off into individual sensor classes per IASZone type

def __init__(
self,
cluster_handlers: list[ClusterHandler],
endpoint: Endpoint,
device: Device,
**kwargs,
) -> None:
"""Initialize the ZHA binary sensor."""
cluster_handler = cluster_handlers[0]
zone_type = cluster_handler.cluster.get("zone_type")
def recompute_capabilities(self) -> None:
"""Recompute capabilities."""
super().recompute_capabilities()
zone_type = self._cluster_handler.cluster.get("zone_type")

if zone_type is None:
self._attr_translation_key = "ias_zone"
Expand All @@ -268,8 +263,6 @@ def __init__(
)
self._attr_device_class = IAS_ZONE_CLASS_MAPPING.get(zone_type)

super().__init__(cluster_handlers, endpoint, device, **kwargs)

@staticmethod
def parse(value: bool | int) -> bool:
"""Parse the raw attribute into a bool state."""
Expand Down
Loading