roborock.devices.traits.v1.led_status

 1from roborock.data import LedStatus
 2from roborock.devices.traits.v1 import common
 3from roborock.roborock_typing import RoborockCommand
 4
 5from .common import V1ResponseData
 6
 7
 8class LedStatusTrait(LedStatus, common.V1TraitMixin, common.RoborockSwitchBase):
 9    """Trait for controlling the LED status of a Roborock device."""
10
11    command = RoborockCommand.GET_LED_STATUS
12    requires_feature = "is_led_status_switch_supported"
13
14    @property
15    def is_on(self) -> bool:
16        """Return whether the LED status is enabled."""
17        return self.status == 1
18
19    async def enable(self) -> None:
20        """Enable the LED status."""
21        await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[1])
22        # Optimistic update to avoid an extra refresh
23        self.status = 1
24
25    async def disable(self) -> None:
26        """Disable the LED status."""
27        await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[0])
28        # Optimistic update to avoid an extra refresh
29        self.status = 0
30
31    @classmethod
32    def _parse_type_response(cls, response: V1ResponseData) -> LedStatus:
33        """Parse the response from the device into a a RoborockBase.
34
35        Subclasses should override this method to implement custom parsing
36        logic as needed.
37        """
38        if not isinstance(response, list):
39            raise ValueError(f"Unexpected {cls} response format: {response!r}")
40        response = response[0]
41        if not isinstance(response, int):
42            raise ValueError(f"Unexpected {cls} response format: {response!r}")
43        return cls.from_dict({"status": response})
 9class LedStatusTrait(LedStatus, common.V1TraitMixin, common.RoborockSwitchBase):
10    """Trait for controlling the LED status of a Roborock device."""
11
12    command = RoborockCommand.GET_LED_STATUS
13    requires_feature = "is_led_status_switch_supported"
14
15    @property
16    def is_on(self) -> bool:
17        """Return whether the LED status is enabled."""
18        return self.status == 1
19
20    async def enable(self) -> None:
21        """Enable the LED status."""
22        await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[1])
23        # Optimistic update to avoid an extra refresh
24        self.status = 1
25
26    async def disable(self) -> None:
27        """Disable the LED status."""
28        await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[0])
29        # Optimistic update to avoid an extra refresh
30        self.status = 0
31
32    @classmethod
33    def _parse_type_response(cls, response: V1ResponseData) -> LedStatus:
34        """Parse the response from the device into a a RoborockBase.
35
36        Subclasses should override this method to implement custom parsing
37        logic as needed.
38        """
39        if not isinstance(response, list):
40            raise ValueError(f"Unexpected {cls} response format: {response!r}")
41        response = response[0]
42        if not isinstance(response, int):
43            raise ValueError(f"Unexpected {cls} response format: {response!r}")
44        return cls.from_dict({"status": response})

Trait for controlling the LED status of a Roborock device.

command = <RoborockCommand.GET_LED_STATUS: 'get_led_status'>
requires_feature = 'is_led_status_switch_supported'
is_on: bool
15    @property
16    def is_on(self) -> bool:
17        """Return whether the LED status is enabled."""
18        return self.status == 1

Return whether the LED status is enabled.

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

Enable the LED status.

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

Disable the LED status.