bulb.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from __future__ import annotations
  2. from typing import Any
  3. from .device import SwitchbotDevice
  4. # Plug Mini keys
  5. PLUG_ON_KEY = "570f50010180"
  6. PLUG_OFF_KEY = "570f50010100"
  7. class SwitchbotBulb(SwitchbotDevice):
  8. """Representation of a Switchbot bulb."""
  9. def __init__(self, *args: Any, **kwargs: Any) -> None:
  10. """Switchbot plug mini constructor."""
  11. super().__init__(*args, **kwargs)
  12. self._settings: dict[str, Any] = {}
  13. async def update(self, interface: int | None = None) -> None:
  14. """Update state of device."""
  15. await self.get_device_data(retry=self._retry_count, interface=interface)
  16. async def turn_on(self) -> bool:
  17. """Turn device on."""
  18. result = await self._sendcommand(PLUG_ON_KEY, self._retry_count)
  19. return result[1] == 0x80
  20. async def turn_off(self) -> bool:
  21. """Turn device off."""
  22. result = await self._sendcommand(PLUG_OFF_KEY, self._retry_count)
  23. return result[1] == 0x00
  24. def is_on(self) -> bool | None:
  25. """Return blub state from cache."""
  26. return self._get_adv_value("isOn")