From b7f0844a10a228b4057a0169ef236e100aa1f174 Mon Sep 17 00:00:00 2001 From: zigpy-review-bot <286747149+zigpy-review-bot@users.noreply.github.com> Date: Thu, 9 Jul 2026 23:25:06 +0200 Subject: [PATCH] Remove unused `_state` attribute from binary sensors `BinarySensor._state` was only ever assigned, never read: the `state` property and `is_on` recompute directly from the cluster, and `maybe_emit_state_changed_event` compares `self.state`. Drop the dead assignments in `__init__`, `is_on`, `handle_attribute_updated` and `async_update`. --- zha/application/platforms/binary_sensor/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/zha/application/platforms/binary_sensor/__init__.py b/zha/application/platforms/binary_sensor/__init__.py index 688cb706c..738fec12c 100644 --- a/zha/application/platforms/binary_sensor/__init__.py +++ b/zha/application/platforms/binary_sensor/__init__.py @@ -111,7 +111,6 @@ def __init__( ) super().__init__(endpoint=endpoint, device=device, **kwargs) - self._state: bool = self.is_on self.recompute_capabilities() def _is_supported(self) -> bool: @@ -145,7 +144,7 @@ def info_object(self) -> BinarySensorEntityInfo: @property def is_on(self) -> bool: """Return True if the switch is on based on the state machine.""" - self._state = raw_state = self._cluster.get(self._attribute_name) + raw_state = self._cluster.get(self._attribute_name) if raw_state is None: return False if self._attribute_converter: @@ -162,7 +161,6 @@ def handle_attribute_updated( """Handle attribute updates from the cluster.""" if self._attribute_name is None or self._attribute_name != event.attribute_name: return - self._state = bool(event.value) self.maybe_emit_state_changed_event() async def async_update(self) -> None: @@ -177,7 +175,6 @@ async def async_update(self) -> None: ) attr_value = result.get(attribute) if attr_value is not None: - self._state = attr_value self.maybe_emit_state_changed_event() @staticmethod