plug.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. """Library to handle connection with Switchbot."""
  2. from __future__ import annotations
  3. from typing import Any
  4. from .device import SwitchbotDevice
  5. # Plug Mini keys
  6. PLUG_ON_KEY = "570f50010180"
  7. PLUG_OFF_KEY = "570f50010100"
  8. class SwitchbotPlugMini(SwitchbotDevice):
  9. """Representation of a Switchbot plug mini."""
  10. async def update(self, interface: int | None = None) -> None:
  11. """Update state of device."""
  12. await self.get_device_data(retry=self._retry_count, interface=interface)
  13. async def turn_on(self) -> bool:
  14. """Turn device on."""
  15. result = await self._sendcommand(PLUG_ON_KEY, self._retry_count)
  16. return result[1] == 0x80
  17. async def turn_off(self) -> bool:
  18. """Turn device off."""
  19. result = await self._sendcommand(PLUG_OFF_KEY, self._retry_count)
  20. return result[1] == 0x00
  21. def is_on(self) -> Any:
  22. """Return switch state from cache."""
  23. # To get actual position call update() first.
  24. return self._get_adv_value("isOn")