From 2fffac02a3b6fffa51c1618d0ddc6c04aebe7130 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Fri, 6 May 2022 10:24:08 -0400 Subject: [PATCH] Update Zigpy attribute cache for switch devices that do not report state (#71417) * fix devices that do not report state * whoops --- .../components/zha/core/channels/general.py | 16 ++++++++++++++++ homeassistant/components/zha/switch.py | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/zha/core/channels/general.py b/homeassistant/components/zha/core/channels/general.py index e6524c9aad1..2e6093dd4f7 100644 --- a/homeassistant/components/zha/core/channels/general.py +++ b/homeassistant/components/zha/core/channels/general.py @@ -308,6 +308,22 @@ class OnOffChannel(ZigbeeChannel): """Return cached value of on/off attribute.""" return self.cluster.get("on_off") + async def turn_on(self) -> bool: + """Turn the on off cluster on.""" + result = await self.on() + if isinstance(result, Exception) or result[1] is not Status.SUCCESS: + return False + self.cluster.update_attribute(self.ON_OFF, t.Bool.true) + return True + + async def turn_off(self) -> bool: + """Turn the on off cluster off.""" + result = await self.off() + if isinstance(result, Exception) or result[1] is not Status.SUCCESS: + return False + self.cluster.update_attribute(self.ON_OFF, t.Bool.false) + return True + @callback def cluster_command(self, tsn, command_id, args): """Handle commands received to this cluster.""" diff --git a/homeassistant/components/zha/switch.py b/homeassistant/components/zha/switch.py index 254e3691da1..76c41093ed6 100644 --- a/homeassistant/components/zha/switch.py +++ b/homeassistant/components/zha/switch.py @@ -64,15 +64,15 @@ class Switch(ZhaEntity, SwitchEntity): async def async_turn_on(self, **kwargs) -> None: """Turn the entity on.""" - result = await self._on_off_channel.on() - if isinstance(result, Exception) or result[1] is not Status.SUCCESS: + result = await self._on_off_channel.turn_on() + if not result: return self.async_write_ha_state() async def async_turn_off(self, **kwargs) -> None: """Turn the entity off.""" - result = await self._on_off_channel.off() - if isinstance(result, Exception) or result[1] is not Status.SUCCESS: + result = await self._on_off_channel.turn_off() + if not result: return self.async_write_ha_state()