1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
from roborock.data import ChildLockStatus
from roborock.devices.traits.v1 import common
from roborock.roborock_typing import RoborockCommand
_STATUS_PARAM = "lock_status"
class ChildLockTrait(ChildLockStatus, common.V1TraitMixin, common.RoborockSwitchBase):
"""Trait for controlling the child lock of a Roborock device."""
command = RoborockCommand.GET_CHILD_LOCK_STATUS
requires_feature = "is_set_child_supported"
@property
def is_on(self) -> bool:
"""Return whether the child lock is enabled."""
return self.lock_status == 1
async def enable(self) -> None:
"""Enable the child lock."""
await self.rpc_channel.send_command(RoborockCommand.SET_CHILD_LOCK_STATUS, params={_STATUS_PARAM: 1})
# Optimistic update to avoid an extra refresh
self.lock_status = 1
async def disable(self) -> None:
"""Disable the child lock."""
await self.rpc_channel.send_command(RoborockCommand.SET_CHILD_LOCK_STATUS, params={_STATUS_PARAM: 0})
# Optimistic update to avoid an extra refresh
self.lock_status = 0
|