Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions homeassistant/components/zha/core/channels/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,22 @@ def on_off(self) -> bool | None:
"""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."""
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/zha/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def is_on(self) -> bool:

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()

Expand Down