|
| 1 | +"""Library to handle connection with Switchbot.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Any |
| 6 | + |
| 7 | +from .device import SwitchbotSequenceDevice, update_after_operation |
| 8 | + |
| 9 | +COMMAND_CLEAN_UP = { |
| 10 | + 1: "570F5A00FFFF7001", |
| 11 | + 2: "5A400101010126", |
| 12 | +} |
| 13 | +COMMAND_RETURN_DOCK = { |
| 14 | + 1: "570F5A00FFFF7002", |
| 15 | + 2: "5A400101010225", |
| 16 | +} |
| 17 | + |
| 18 | + |
| 19 | +class SwitchbotVacuum(SwitchbotSequenceDevice): |
| 20 | + """Representation of a Switchbot Vacuum.""" |
| 21 | + |
| 22 | + def __init__(self, device, password=None, interface=0, **kwargs): |
| 23 | + super().__init__(device, password, interface, **kwargs) |
| 24 | + |
| 25 | + @update_after_operation |
| 26 | + async def clean_up(self, protocol_version: int) -> bool: |
| 27 | + """Send command to perform a spot clean-up.""" |
| 28 | + return await self._send_command(COMMAND_CLEAN_UP[protocol_version]) |
| 29 | + |
| 30 | + @update_after_operation |
| 31 | + async def return_to_dock(self, protocol_version: int) -> bool: |
| 32 | + """Send command to return the dock.""" |
| 33 | + return await self._send_command(COMMAND_RETURN_DOCK[protocol_version]) |
| 34 | + |
| 35 | + async def get_basic_info(self) -> dict[str, Any] | None: |
| 36 | + """Only support get the ble version through the command.""" |
| 37 | + if not (_data := await self._get_basic_info()): |
| 38 | + return None |
| 39 | + return { |
| 40 | + "firmware": _data[2], |
| 41 | + } |
| 42 | + |
| 43 | + def get_soc_version(self) -> str: |
| 44 | + """Return device soc version.""" |
| 45 | + return self._get_adv_value("soc_version") |
| 46 | + |
| 47 | + def get_last_step(self) -> int: |
| 48 | + """Return device last step after network configuration.""" |
| 49 | + return self._get_adv_value("step") |
| 50 | + |
| 51 | + def get_mqtt_connnect_status(self) -> bool: |
| 52 | + """Return device mqtt connect status.""" |
| 53 | + return self._get_adv_value("mqtt_connected") |
| 54 | + |
| 55 | + def get_battery(self) -> int: |
| 56 | + """Return device battery.""" |
| 57 | + return self._get_adv_value("battery") |
| 58 | + |
| 59 | + def get_work_status(self) -> int: |
| 60 | + """Return device work status.""" |
| 61 | + return self._get_adv_value("work_status") |
| 62 | + |
| 63 | + def get_dustbin_bound_status(self) -> bool: |
| 64 | + """Return the dustbin bound status""" |
| 65 | + return self._get_adv_value("dustbin_bound") |
| 66 | + |
| 67 | + def get_dustbin_connnected_status(self) -> bool: |
| 68 | + """Return the dustbin connected status""" |
| 69 | + return self._get_adv_value("dusbin_connected") |
| 70 | + |
| 71 | + def get_network_connected_status(self) -> bool: |
| 72 | + """Return the network connected status""" |
| 73 | + return self._get_adv_value("network_connected") |
0 commit comments