roborock.devices.traits.v1.command

 1from typing import Any
 2
 3from roborock import RoborockCommand
 4from roborock.protocols.v1_protocol import ParamsType
 5
 6
 7class CommandTrait:
 8    """Trait for sending commands to Roborock devices.
 9
10    This trait allows sending raw commands directly to the device. It is particularly
11    useful for:
12    1.  **Cleaning Control**: Sending commands like `app_start`, `app_stop`, `app_pause`,
13        or `app_charge` which don't belong to a specific state trait.
14    2.  **Unsupported Features**: Accessing device functionality that hasn't been
15        mapped to a specific trait yet.
16
17    See `roborock.roborock_typing.RoborockCommand` for a list of available commands.
18    """
19
20    def __post_init__(self) -> None:
21        """Post-initialization to set up the RPC channel.
22
23        This is called automatically after the dataclass is initialized by the
24        device setup code.
25        """
26        self._rpc_channel = None
27
28    async def send(self, command: RoborockCommand | str, params: ParamsType = None) -> Any:
29        """Send a command to the device.
30
31        Sending a raw command to the device using this method does not update
32        the internal state of any other traits. It is the responsibility of the
33        caller to ensure that any traits affected by the command are refreshed
34        as needed.
35        """
36        if not self._rpc_channel:
37            raise ValueError("Device trait in invalid state")
38        return await self._rpc_channel.send_command(command, params=params)
class CommandTrait:
 8class CommandTrait:
 9    """Trait for sending commands to Roborock devices.
10
11    This trait allows sending raw commands directly to the device. It is particularly
12    useful for:
13    1.  **Cleaning Control**: Sending commands like `app_start`, `app_stop`, `app_pause`,
14        or `app_charge` which don't belong to a specific state trait.
15    2.  **Unsupported Features**: Accessing device functionality that hasn't been
16        mapped to a specific trait yet.
17
18    See `roborock.roborock_typing.RoborockCommand` for a list of available commands.
19    """
20
21    def __post_init__(self) -> None:
22        """Post-initialization to set up the RPC channel.
23
24        This is called automatically after the dataclass is initialized by the
25        device setup code.
26        """
27        self._rpc_channel = None
28
29    async def send(self, command: RoborockCommand | str, params: ParamsType = None) -> Any:
30        """Send a command to the device.
31
32        Sending a raw command to the device using this method does not update
33        the internal state of any other traits. It is the responsibility of the
34        caller to ensure that any traits affected by the command are refreshed
35        as needed.
36        """
37        if not self._rpc_channel:
38            raise ValueError("Device trait in invalid state")
39        return await self._rpc_channel.send_command(command, params=params)

Trait for sending commands to Roborock devices.

This trait allows sending raw commands directly to the device. It is particularly useful for:

  1. Cleaning Control: Sending commands like app_start, app_stop, app_pause, or app_charge which don't belong to a specific state trait.
  2. Unsupported Features: Accessing device functionality that hasn't been mapped to a specific trait yet.

See roborock.roborock_typing.RoborockCommand for a list of available commands.

async def send( self, command: roborock.roborock_typing.RoborockCommand | str, params: list | dict | int | None = None) -> Any:
29    async def send(self, command: RoborockCommand | str, params: ParamsType = None) -> Any:
30        """Send a command to the device.
31
32        Sending a raw command to the device using this method does not update
33        the internal state of any other traits. It is the responsibility of the
34        caller to ensure that any traits affected by the command are refreshed
35        as needed.
36        """
37        if not self._rpc_channel:
38            raise ValueError("Device trait in invalid state")
39        return await self._rpc_channel.send_command(command, params=params)

Send a command to the device.

Sending a raw command to the device using this method does not update the internal state of any other traits. It is the responsibility of the caller to ensure that any traits affected by the command are refreshed as needed.