base_light.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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")
  45. @abstractmethod
  46. async def turn_on(self) -> bool:
  47. """Turn device on."""
  48. @abstractmethod
  49. async def turn_off(self) -> bool:
  50. """Turn device off."""
  51. @abstractmethod
  52. async def set_brightness(self, brightness: int) -> bool:
  53. """Set brightness."""
  54. @abstractmethod
  55. async def set_color_temp(self, brightness: int, color_temp: int) -> bool:
  56. """Set color temp."""
  57. @abstractmethod
  58. async def set_rgb(self, brightness: int, r: int, g: int, b: int) -> bool:
  59. """Set rgb."""