roborock.devices.traits.b01.q7

Traits for Q7 B01 devices. Potentially other devices may fall into this category in the future.

  1"""Traits for Q7 B01 devices.
  2Potentially other devices may fall into this category in the future."""
  3
  4from typing import Any
  5
  6from roborock import B01Props
  7from roborock.data.b01_q7.b01_q7_code_mappings import (
  8    CleanTaskTypeMapping,
  9    SCDeviceCleanParam,
 10    SCWindMapping,
 11    WaterLevelMapping,
 12)
 13from roborock.devices.b01_channel import CommandType, ParamsType, send_decoded_command
 14from roborock.devices.mqtt_channel import MqttChannel
 15from roborock.devices.traits import Trait
 16from roborock.roborock_message import RoborockB01Props
 17from roborock.roborock_typing import RoborockB01Q7Methods
 18
 19__all__ = [
 20    "Q7PropertiesApi",
 21]
 22
 23
 24class Q7PropertiesApi(Trait):
 25    """API for interacting with B01 devices."""
 26
 27    def __init__(self, channel: MqttChannel) -> None:
 28        """Initialize the B01Props API."""
 29        self._channel = channel
 30
 31    async def query_values(self, props: list[RoborockB01Props]) -> B01Props | None:
 32        """Query the device for the values of the given Q7 properties."""
 33        result = await self.send(
 34            RoborockB01Q7Methods.GET_PROP,
 35            {"property": props},
 36        )
 37        if not isinstance(result, dict):
 38            raise TypeError(f"Unexpected response type for GET_PROP: {type(result).__name__}: {result!r}")
 39        return B01Props.from_dict(result)
 40
 41    async def set_prop(self, prop: RoborockB01Props, value: Any) -> None:
 42        """Set a property on the device."""
 43        await self.send(
 44            command=RoborockB01Q7Methods.SET_PROP,
 45            params={prop: value},
 46        )
 47
 48    async def set_fan_speed(self, fan_speed: SCWindMapping) -> None:
 49        """Set the fan speed (wind)."""
 50        await self.set_prop(RoborockB01Props.WIND, fan_speed.code)
 51
 52    async def set_water_level(self, water_level: WaterLevelMapping) -> None:
 53        """Set the water level (water)."""
 54        await self.set_prop(RoborockB01Props.WATER, water_level.code)
 55
 56    async def start_clean(self) -> None:
 57        """Start cleaning."""
 58        await self.send(
 59            command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
 60            params={
 61                "clean_type": CleanTaskTypeMapping.ALL.code,
 62                "ctrl_value": SCDeviceCleanParam.START.code,
 63                "room_ids": [],
 64            },
 65        )
 66
 67    async def pause_clean(self) -> None:
 68        """Pause cleaning."""
 69        await self.send(
 70            command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
 71            params={
 72                "clean_type": CleanTaskTypeMapping.ALL.code,
 73                "ctrl_value": SCDeviceCleanParam.PAUSE.code,
 74                "room_ids": [],
 75            },
 76        )
 77
 78    async def stop_clean(self) -> None:
 79        """Stop cleaning."""
 80        await self.send(
 81            command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
 82            params={
 83                "clean_type": CleanTaskTypeMapping.ALL.code,
 84                "ctrl_value": SCDeviceCleanParam.STOP.code,
 85                "room_ids": [],
 86            },
 87        )
 88
 89    async def return_to_dock(self) -> None:
 90        """Return to dock."""
 91        await self.send(
 92            command=RoborockB01Q7Methods.START_RECHARGE,
 93            params={},
 94        )
 95
 96    async def find_me(self) -> None:
 97        """Locate the robot."""
 98        await self.send(
 99            command=RoborockB01Q7Methods.FIND_DEVICE,
100            params={},
101        )
102
103    async def send(self, command: CommandType, params: ParamsType) -> Any:
104        """Send a command to the device."""
105        return await send_decoded_command(
106            self._channel,
107            dps=10000,
108            command=command,
109            params=params,
110        )
111
112
113def create(channel: MqttChannel) -> Q7PropertiesApi:
114    """Create traits for B01 devices."""
115    return Q7PropertiesApi(channel)
class Q7PropertiesApi(roborock.devices.traits.Trait):
 25class Q7PropertiesApi(Trait):
 26    """API for interacting with B01 devices."""
 27
 28    def __init__(self, channel: MqttChannel) -> None:
 29        """Initialize the B01Props API."""
 30        self._channel = channel
 31
 32    async def query_values(self, props: list[RoborockB01Props]) -> B01Props | None:
 33        """Query the device for the values of the given Q7 properties."""
 34        result = await self.send(
 35            RoborockB01Q7Methods.GET_PROP,
 36            {"property": props},
 37        )
 38        if not isinstance(result, dict):
 39            raise TypeError(f"Unexpected response type for GET_PROP: {type(result).__name__}: {result!r}")
 40        return B01Props.from_dict(result)
 41
 42    async def set_prop(self, prop: RoborockB01Props, value: Any) -> None:
 43        """Set a property on the device."""
 44        await self.send(
 45            command=RoborockB01Q7Methods.SET_PROP,
 46            params={prop: value},
 47        )
 48
 49    async def set_fan_speed(self, fan_speed: SCWindMapping) -> None:
 50        """Set the fan speed (wind)."""
 51        await self.set_prop(RoborockB01Props.WIND, fan_speed.code)
 52
 53    async def set_water_level(self, water_level: WaterLevelMapping) -> None:
 54        """Set the water level (water)."""
 55        await self.set_prop(RoborockB01Props.WATER, water_level.code)
 56
 57    async def start_clean(self) -> None:
 58        """Start cleaning."""
 59        await self.send(
 60            command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
 61            params={
 62                "clean_type": CleanTaskTypeMapping.ALL.code,
 63                "ctrl_value": SCDeviceCleanParam.START.code,
 64                "room_ids": [],
 65            },
 66        )
 67
 68    async def pause_clean(self) -> None:
 69        """Pause cleaning."""
 70        await self.send(
 71            command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
 72            params={
 73                "clean_type": CleanTaskTypeMapping.ALL.code,
 74                "ctrl_value": SCDeviceCleanParam.PAUSE.code,
 75                "room_ids": [],
 76            },
 77        )
 78
 79    async def stop_clean(self) -> None:
 80        """Stop cleaning."""
 81        await self.send(
 82            command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
 83            params={
 84                "clean_type": CleanTaskTypeMapping.ALL.code,
 85                "ctrl_value": SCDeviceCleanParam.STOP.code,
 86                "room_ids": [],
 87            },
 88        )
 89
 90    async def return_to_dock(self) -> None:
 91        """Return to dock."""
 92        await self.send(
 93            command=RoborockB01Q7Methods.START_RECHARGE,
 94            params={},
 95        )
 96
 97    async def find_me(self) -> None:
 98        """Locate the robot."""
 99        await self.send(
100            command=RoborockB01Q7Methods.FIND_DEVICE,
101            params={},
102        )
103
104    async def send(self, command: CommandType, params: ParamsType) -> Any:
105        """Send a command to the device."""
106        return await send_decoded_command(
107            self._channel,
108            dps=10000,
109            command=command,
110            params=params,
111        )

API for interacting with B01 devices.

Q7PropertiesApi(channel: roborock.devices.mqtt_channel.MqttChannel)
28    def __init__(self, channel: MqttChannel) -> None:
29        """Initialize the B01Props API."""
30        self._channel = channel

Initialize the B01Props API.

async def query_values( self, props: list[roborock.roborock_message.RoborockB01Props]) -> roborock.data.b01_q7.b01_q7_containers.B01Props | None:
32    async def query_values(self, props: list[RoborockB01Props]) -> B01Props | None:
33        """Query the device for the values of the given Q7 properties."""
34        result = await self.send(
35            RoborockB01Q7Methods.GET_PROP,
36            {"property": props},
37        )
38        if not isinstance(result, dict):
39            raise TypeError(f"Unexpected response type for GET_PROP: {type(result).__name__}: {result!r}")
40        return B01Props.from_dict(result)

Query the device for the values of the given Q7 properties.

async def set_prop( self, prop: roborock.roborock_message.RoborockB01Props, value: Any) -> None:
42    async def set_prop(self, prop: RoborockB01Props, value: Any) -> None:
43        """Set a property on the device."""
44        await self.send(
45            command=RoborockB01Q7Methods.SET_PROP,
46            params={prop: value},
47        )

Set a property on the device.

async def set_fan_speed( self, fan_speed: roborock.data.b01_q7.b01_q7_code_mappings.SCWindMapping) -> None:
49    async def set_fan_speed(self, fan_speed: SCWindMapping) -> None:
50        """Set the fan speed (wind)."""
51        await self.set_prop(RoborockB01Props.WIND, fan_speed.code)

Set the fan speed (wind).

async def set_water_level( self, water_level: roborock.data.b01_q7.b01_q7_code_mappings.WaterLevelMapping) -> None:
53    async def set_water_level(self, water_level: WaterLevelMapping) -> None:
54        """Set the water level (water)."""
55        await self.set_prop(RoborockB01Props.WATER, water_level.code)

Set the water level (water).

async def start_clean(self) -> None:
57    async def start_clean(self) -> None:
58        """Start cleaning."""
59        await self.send(
60            command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
61            params={
62                "clean_type": CleanTaskTypeMapping.ALL.code,
63                "ctrl_value": SCDeviceCleanParam.START.code,
64                "room_ids": [],
65            },
66        )

Start cleaning.

async def pause_clean(self) -> None:
68    async def pause_clean(self) -> None:
69        """Pause cleaning."""
70        await self.send(
71            command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
72            params={
73                "clean_type": CleanTaskTypeMapping.ALL.code,
74                "ctrl_value": SCDeviceCleanParam.PAUSE.code,
75                "room_ids": [],
76            },
77        )

Pause cleaning.

async def stop_clean(self) -> None:
79    async def stop_clean(self) -> None:
80        """Stop cleaning."""
81        await self.send(
82            command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
83            params={
84                "clean_type": CleanTaskTypeMapping.ALL.code,
85                "ctrl_value": SCDeviceCleanParam.STOP.code,
86                "room_ids": [],
87            },
88        )

Stop cleaning.

async def return_to_dock(self) -> None:
90    async def return_to_dock(self) -> None:
91        """Return to dock."""
92        await self.send(
93            command=RoborockB01Q7Methods.START_RECHARGE,
94            params={},
95        )

Return to dock.

async def find_me(self) -> None:
 97    async def find_me(self) -> None:
 98        """Locate the robot."""
 99        await self.send(
100            command=RoborockB01Q7Methods.FIND_DEVICE,
101            params={},
102        )

Locate the robot.

async def send( self, command: roborock.roborock_typing.RoborockB01Q7Methods | str, params: list | dict | int | None) -> Any:
104    async def send(self, command: CommandType, params: ParamsType) -> Any:
105        """Send a command to the device."""
106        return await send_decoded_command(
107            self._channel,
108            dps=10000,
109            command=command,
110            params=params,
111        )

Send a command to the device.