roborock.devices.traits.v1.child_lock

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

Trait for controlling the child lock of a Roborock device.

command = <RoborockCommand.GET_CHILD_LOCK_STATUS: 'get_child_lock_status'>

The RoborockCommand used to fetch the trait data from the device (internal only).

converter = DefaultConverter

The converter used to parse the response from the device (internal only).

requires_feature = 'is_set_child_supported'
is_on: bool
16    @property
17    def is_on(self) -> bool:
18        """Return whether the child lock is enabled."""
19        return self.lock_status == 1

Return whether the child lock is enabled.

async def enable(self) -> None:
21    async def enable(self) -> None:
22        """Enable the child lock."""
23        await self.rpc_channel.send_command(RoborockCommand.SET_CHILD_LOCK_STATUS, params={_STATUS_PARAM: 1})
24        # Optimistic update to avoid an extra refresh
25        self.lock_status = 1

Enable the child lock.

async def disable(self) -> None:
27    async def disable(self) -> None:
28        """Disable the child lock."""
29        await self.rpc_channel.send_command(RoborockCommand.SET_CHILD_LOCK_STATUS, params={_STATUS_PARAM: 0})
30        # Optimistic update to avoid an extra refresh
31        self.lock_status = 0

Disable the child lock.