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 LedStatusConverter(common.V1TraitDataConverter): 9 """Converter for LedStatus.""" 10 11 def convert(self, response: V1ResponseData) -> LedStatus: 12 """Parse the response from the device into a a RoborockBase. 13 14 Subclasses should override this method to implement custom parsing 15 logic as needed. 16 """ 17 if not isinstance(response, list): 18 raise ValueError(f"Unexpected LedStatus response format: {response!r}") 19 response = response[0] 20 if not isinstance(response, int): 21 raise ValueError(f"Unexpected LedStatus response format: {response!r}") 22 return LedStatus.from_dict({"status": response}) 23 24 25class LedStatusTrait(LedStatus, common.V1TraitMixin, common.RoborockSwitchBase): 26 """Trait for controlling the LED status of a Roborock device.""" 27 28 command = RoborockCommand.GET_LED_STATUS 29 converter = LedStatusConverter() 30 requires_feature = "is_led_status_switch_supported" 31 32 @property 33 def is_on(self) -> bool: 34 """Return whether the LED status is enabled.""" 35 return self.status == 1 36 37 async def enable(self) -> None: 38 """Enable the LED status.""" 39 await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[1]) 40 # Optimistic update to avoid an extra refresh 41 self.status = 1 42 43 async def disable(self) -> None: 44 """Disable the LED status.""" 45 await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[0]) 46 # Optimistic update to avoid an extra refresh 47 self.status = 0
9class LedStatusConverter(common.V1TraitDataConverter): 10 """Converter for LedStatus.""" 11 12 def convert(self, response: V1ResponseData) -> LedStatus: 13 """Parse the response from the device into a a RoborockBase. 14 15 Subclasses should override this method to implement custom parsing 16 logic as needed. 17 """ 18 if not isinstance(response, list): 19 raise ValueError(f"Unexpected LedStatus response format: {response!r}") 20 response = response[0] 21 if not isinstance(response, int): 22 raise ValueError(f"Unexpected LedStatus response format: {response!r}") 23 return LedStatus.from_dict({"status": response})
Converter for LedStatus.
12 def convert(self, response: V1ResponseData) -> LedStatus: 13 """Parse the response from the device into a a RoborockBase. 14 15 Subclasses should override this method to implement custom parsing 16 logic as needed. 17 """ 18 if not isinstance(response, list): 19 raise ValueError(f"Unexpected LedStatus response format: {response!r}") 20 response = response[0] 21 if not isinstance(response, int): 22 raise ValueError(f"Unexpected LedStatus response format: {response!r}") 23 return LedStatus.from_dict({"status": response})
Parse the response from the device into a a RoborockBase.
Subclasses should override this method to implement custom parsing logic as needed.
class
LedStatusTrait(roborock.data.v1.v1_containers.LedStatus, roborock.devices.traits.v1.common.V1TraitMixin, roborock.devices.traits.v1.common.RoborockSwitchBase):
26class LedStatusTrait(LedStatus, common.V1TraitMixin, common.RoborockSwitchBase): 27 """Trait for controlling the LED status of a Roborock device.""" 28 29 command = RoborockCommand.GET_LED_STATUS 30 converter = LedStatusConverter() 31 requires_feature = "is_led_status_switch_supported" 32 33 @property 34 def is_on(self) -> bool: 35 """Return whether the LED status is enabled.""" 36 return self.status == 1 37 38 async def enable(self) -> None: 39 """Enable the LED status.""" 40 await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[1]) 41 # Optimistic update to avoid an extra refresh 42 self.status = 1 43 44 async def disable(self) -> None: 45 """Disable the LED status.""" 46 await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[0]) 47 # Optimistic update to avoid an extra refresh 48 self.status = 0
Trait for controlling the LED status of a Roborock device.
command =
<RoborockCommand.GET_LED_STATUS: 'get_led_status'>
The RoborockCommand used to fetch the trait data from the device (internal only).
converter =
LedStatusConverter
The converter used to parse the response from the device (internal only).
is_on: bool
33 @property 34 def is_on(self) -> bool: 35 """Return whether the LED status is enabled.""" 36 return self.status == 1
Return whether the LED status is enabled.
async def
enable(self) -> None:
38 async def enable(self) -> None: 39 """Enable the LED status.""" 40 await self.rpc_channel.send_command(RoborockCommand.SET_LED_STATUS, params=[1]) 41 # Optimistic update to avoid an extra refresh 42 self.status = 1
Enable the LED status.