vacuum.py 2.4 KB

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