roborock.devices.traits.v1.status

 1from functools import cached_property
 2
 3from roborock import (
 4    CleanRoutes,
 5    StatusV2,
 6    VacuumModes,
 7    WaterModes,
 8    get_clean_modes,
 9    get_clean_routes,
10    get_water_mode_mapping,
11    get_water_modes,
12)
13from roborock.roborock_typing import RoborockCommand
14
15from . import common
16from .device_features import DeviceFeaturesTrait
17
18
19class StatusTrait(StatusV2, common.V1TraitMixin):
20    """Trait for managing the status of Roborock devices.
21
22    The StatusTrait gives you the access to the state of a Roborock vacuum.
23    The various attribute options on state change per each device.
24    Values like fan speed, mop mode, etc. have different options for every device
25    and are dynamically determined.
26
27    Usage:
28        Before accessing status properties, you should call `refresh()` to fetch
29        the latest data from the device. You must pass in the device feature trait
30        to this trait so that the dynamic attributes can be pre-determined.
31
32    The current dynamic attributes are:
33    - Fan Speed
34    - Water Mode
35    - Mop Route
36
37    You should call the _options() version of the attribute to know which are supported for your device
38    (i.e. fan_speed_options())
39    Then you can call the _mapping to convert an int value to the actual Enum. (i.e. fan_speed_mapping())
40    You can call the _name property to get the str value of the enum. (i.e. fan_speed_name)
41
42    """
43
44    command = RoborockCommand.GET_STATUS
45    converter = common.DefaultConverter(StatusV2)
46
47    def __init__(self, device_feature_trait: DeviceFeaturesTrait, region: str | None = None) -> None:
48        """Initialize the StatusTrait."""
49        super().__init__()
50        self._device_features_trait = device_feature_trait
51        self._region = region
52
53    @cached_property
54    def fan_speed_options(self) -> list[VacuumModes]:
55        return get_clean_modes(self._device_features_trait)
56
57    @cached_property
58    def fan_speed_mapping(self) -> dict[int, str]:
59        return {fan.code: fan.value for fan in self.fan_speed_options}
60
61    @cached_property
62    def water_mode_options(self) -> list[WaterModes]:
63        return get_water_modes(self._device_features_trait)
64
65    @cached_property
66    def water_mode_mapping(self) -> dict[int, str]:
67        return get_water_mode_mapping(self._device_features_trait)
68
69    @cached_property
70    def mop_route_options(self) -> list[CleanRoutes]:
71        return get_clean_routes(self._device_features_trait, self._region or "us")
72
73    @cached_property
74    def mop_route_mapping(self) -> dict[int, str]:
75        return {route.code: route.value for route in self.mop_route_options}
76
77    @property
78    def fan_speed_name(self) -> str | None:
79        if self.fan_power is None:
80            return None
81        return self.fan_speed_mapping.get(self.fan_power)
82
83    @property
84    def water_mode_name(self) -> str | None:
85        if self.water_box_mode is None:
86            return None
87        return self.water_mode_mapping.get(self.water_box_mode)
88
89    @property
90    def mop_route_name(self) -> str | None:
91        if self.mop_mode is None:
92            return None
93        return self.mop_route_mapping.get(self.mop_mode)
20class StatusTrait(StatusV2, common.V1TraitMixin):
21    """Trait for managing the status of Roborock devices.
22
23    The StatusTrait gives you the access to the state of a Roborock vacuum.
24    The various attribute options on state change per each device.
25    Values like fan speed, mop mode, etc. have different options for every device
26    and are dynamically determined.
27
28    Usage:
29        Before accessing status properties, you should call `refresh()` to fetch
30        the latest data from the device. You must pass in the device feature trait
31        to this trait so that the dynamic attributes can be pre-determined.
32
33    The current dynamic attributes are:
34    - Fan Speed
35    - Water Mode
36    - Mop Route
37
38    You should call the _options() version of the attribute to know which are supported for your device
39    (i.e. fan_speed_options())
40    Then you can call the _mapping to convert an int value to the actual Enum. (i.e. fan_speed_mapping())
41    You can call the _name property to get the str value of the enum. (i.e. fan_speed_name)
42
43    """
44
45    command = RoborockCommand.GET_STATUS
46    converter = common.DefaultConverter(StatusV2)
47
48    def __init__(self, device_feature_trait: DeviceFeaturesTrait, region: str | None = None) -> None:
49        """Initialize the StatusTrait."""
50        super().__init__()
51        self._device_features_trait = device_feature_trait
52        self._region = region
53
54    @cached_property
55    def fan_speed_options(self) -> list[VacuumModes]:
56        return get_clean_modes(self._device_features_trait)
57
58    @cached_property
59    def fan_speed_mapping(self) -> dict[int, str]:
60        return {fan.code: fan.value for fan in self.fan_speed_options}
61
62    @cached_property
63    def water_mode_options(self) -> list[WaterModes]:
64        return get_water_modes(self._device_features_trait)
65
66    @cached_property
67    def water_mode_mapping(self) -> dict[int, str]:
68        return get_water_mode_mapping(self._device_features_trait)
69
70    @cached_property
71    def mop_route_options(self) -> list[CleanRoutes]:
72        return get_clean_routes(self._device_features_trait, self._region or "us")
73
74    @cached_property
75    def mop_route_mapping(self) -> dict[int, str]:
76        return {route.code: route.value for route in self.mop_route_options}
77
78    @property
79    def fan_speed_name(self) -> str | None:
80        if self.fan_power is None:
81            return None
82        return self.fan_speed_mapping.get(self.fan_power)
83
84    @property
85    def water_mode_name(self) -> str | None:
86        if self.water_box_mode is None:
87            return None
88        return self.water_mode_mapping.get(self.water_box_mode)
89
90    @property
91    def mop_route_name(self) -> str | None:
92        if self.mop_mode is None:
93            return None
94        return self.mop_route_mapping.get(self.mop_mode)

Trait for managing the status of Roborock devices.

The StatusTrait gives you the access to the state of a Roborock vacuum. The various attribute options on state change per each device. Values like fan speed, mop mode, etc. have different options for every device and are dynamically determined.

Usage: Before accessing status properties, you should call refresh() to fetch the latest data from the device. You must pass in the device feature trait to this trait so that the dynamic attributes can be pre-determined.

The current dynamic attributes are:

  • Fan Speed
  • Water Mode
  • Mop Route

You should call the _options() version of the attribute to know which are supported for your device (i.e. fan_speed_options()) Then you can call the _mapping to convert an int value to the actual Enum. (i.e. fan_speed_mapping()) You can call the _name property to get the str value of the enum. (i.e. fan_speed_name)

StatusTrait( device_feature_trait: roborock.devices.traits.v1.device_features.DeviceFeaturesTrait, region: str | None = None)
48    def __init__(self, device_feature_trait: DeviceFeaturesTrait, region: str | None = None) -> None:
49        """Initialize the StatusTrait."""
50        super().__init__()
51        self._device_features_trait = device_feature_trait
52        self._region = region

Initialize the StatusTrait.

command = <RoborockCommand.GET_STATUS: 'get_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).

fan_speed_options: list[roborock.data.v1.v1_clean_modes.VacuumModes]
54    @cached_property
55    def fan_speed_options(self) -> list[VacuumModes]:
56        return get_clean_modes(self._device_features_trait)
fan_speed_mapping: dict[int, str]
58    @cached_property
59    def fan_speed_mapping(self) -> dict[int, str]:
60        return {fan.code: fan.value for fan in self.fan_speed_options}
water_mode_options: list[roborock.data.v1.v1_clean_modes.WaterModes]
62    @cached_property
63    def water_mode_options(self) -> list[WaterModes]:
64        return get_water_modes(self._device_features_trait)
water_mode_mapping: dict[int, str]
66    @cached_property
67    def water_mode_mapping(self) -> dict[int, str]:
68        return get_water_mode_mapping(self._device_features_trait)
mop_route_options: list[roborock.data.v1.v1_clean_modes.CleanRoutes]
70    @cached_property
71    def mop_route_options(self) -> list[CleanRoutes]:
72        return get_clean_routes(self._device_features_trait, self._region or "us")
mop_route_mapping: dict[int, str]
74    @cached_property
75    def mop_route_mapping(self) -> dict[int, str]:
76        return {route.code: route.value for route in self.mop_route_options}
fan_speed_name: str | None
78    @property
79    def fan_speed_name(self) -> str | None:
80        if self.fan_power is None:
81            return None
82        return self.fan_speed_mapping.get(self.fan_power)
water_mode_name: str | None
84    @property
85    def water_mode_name(self) -> str | None:
86        if self.water_box_mode is None:
87            return None
88        return self.water_mode_mapping.get(self.water_box_mode)
mop_route_name: str | None
90    @property
91    def mop_route_name(self) -> str | None:
92        if self.mop_mode is None:
93            return None
94        return self.mop_route_mapping.get(self.mop_mode)