base_light.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from __future__ import annotations
  2. import logging
  3. from abc import abstractmethod
  4. from typing import Any
  5. from .device import ColorMode, SwitchbotSequenceDevice
  6. class SwitchbotBaseLight(SwitchbotSequenceDevice):
  7. """Representation of a Switchbot light."""
  8. def __init__(self, *args: Any, **kwargs: Any) -> None:
  9. """Switchbot bulb constructor."""
  10. super().__init__(*args, **kwargs)
  11. self._state: dict[str, Any] = {}
  12. @property
  13. def on(self) -> bool | None:
  14. """Return if bulb is on."""
  15. return self.is_on()
  16. @property
  17. def rgb(self) -> tuple[int, int, int] | None:
  18. """Return the current rgb value."""
  19. if "r" not in self._state or "g" not in self._state or "b" not in self._state:
  20. return None
  21. return self._state["r"], self._state["g"], self._state["b"]
  22. @property
  23. def color_temp(self) -> int | None:
  24. """Return the current color temp value."""
  25. return self._state.get("cw") or self.min_temp
  26. @property
  27. def brightness(self) -> int | None:
  28. """Return the current brightness value."""
  29. return self._get_adv_value("brightness") or 0
  30. @property
  31. def color_mode(self) -> ColorMode:
  32. """Return the current color mode."""
  33. return ColorMode(self._get_adv_value("color_mode") or 0)
  34. @property
  35. def min_temp(self) -> int:
  36. """Return minimum color temp."""
  37. return 2700
  38. @property
  39. def max_temp(self) -> int:
  40. """Return maximum color temp."""
  41. return 6500
  42. def is_on(self) -> bool | None:
  43. """Return bulb state from cache."""
  44. return self._get_adv_value("isOn")