File: led_status.py

package info (click to toggle)
python-roborock 4.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,480 kB
  • sloc: python: 16,602; makefile: 17; sh: 6
file content (43 lines) | stat: -rw-r--r-- 1,640 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from roborock.data import LedStatus
from roborock.devices.traits.v1 import common
from roborock.roborock_typing import RoborockCommand

from .common import V1ResponseData


class LedStatusTrait(LedStatus, common.V1TraitMixin, common.RoborockSwitchBase):
    """Trait for controlling the LED status of a Roborock device."""

    command = RoborockCommand.GET_LED_STATUS
    requires_feature = "is_led_status_switch_supported"

    @property
    def is_on(self) -> bool:
        """Return whether the LED status is enabled."""
        return self.status == 1

    async def enable(self) -> None:
        """Enable the LED status."""
        await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[1])
        # Optimistic update to avoid an extra refresh
        self.status = 1

    async def disable(self) -> None:
        """Disable the LED status."""
        await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[0])
        # Optimistic update to avoid an extra refresh
        self.status = 0

    @classmethod
    def _parse_type_response(cls, response: V1ResponseData) -> LedStatus:
        """Parse the response from the device into a a RoborockBase.

        Subclasses should override this method to implement custom parsing
        logic as needed.
        """
        if not isinstance(response, list):
            raise ValueError(f"Unexpected {cls} response format: {response!r}")
        response = response[0]
        if not isinstance(response, int):
            raise ValueError(f"Unexpected {cls} response format: {response!r}")
        return cls.from_dict({"status": response})