plug.py 1000 B

1234567891011121314151617181920212223242526272829303132
  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)
  16. return self._check_command_result(result, 1, {0x80})
  17. async def turn_off(self) -> bool:
  18. """Turn device off."""
  19. result = await self._sendcommand(PLUG_OFF_KEY)
  20. return self._check_command_result(result, 1, {0x00})
  21. def is_on(self) -> bool | None:
  22. """Return switch state from cache."""
  23. return self._get_adv_value("isOn")