Update Zigpy attribute cache for switch devices that do not report state (#71417)

* fix devices that do not report state

* whoops
pull/71444/head
David F. Mulcahey 2022-05-06 10:24:08 -04:00 committed by Paulus Schoutsen
parent 46a36adf26
commit 2fffac02a3
2 changed files with 20 additions and 4 deletions

View File

@ -308,6 +308,22 @@ class OnOffChannel(ZigbeeChannel):
"""Return cached value of on/off attribute.""" """Return cached value of on/off attribute."""
return self.cluster.get("on_off") 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 @callback
def cluster_command(self, tsn, command_id, args): def cluster_command(self, tsn, command_id, args):
"""Handle commands received to this cluster.""" """Handle commands received to this cluster."""

View File

@ -64,15 +64,15 @@ class Switch(ZhaEntity, SwitchEntity):
async def async_turn_on(self, **kwargs) -> None: async def async_turn_on(self, **kwargs) -> None:
"""Turn the entity on.""" """Turn the entity on."""
result = await self._on_off_channel.on() result = await self._on_off_channel.turn_on()
if isinstance(result, Exception) or result[1] is not Status.SUCCESS: if not result:
return return
self.async_write_ha_state() self.async_write_ha_state()
async def async_turn_off(self, **kwargs) -> None: async def async_turn_off(self, **kwargs) -> None:
"""Turn the entity off.""" """Turn the entity off."""
result = await self._on_off_channel.off() result = await self._on_off_channel.turn_off()
if isinstance(result, Exception) or result[1] is not Status.SUCCESS: if not result:
return return
self.async_write_ha_state() self.async_write_ha_state()