ceiling_light.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from __future__ import annotations
  2. import logging
  3. from .base_light import SwitchbotBaseLight
  4. from .device import REQ_HEADER, ColorMode
  5. CEILING_LIGHT_COMMAND_HEADER = "5401"
  6. CEILING_LIGHT_REQUEST = f"{REQ_HEADER}5501"
  7. CEILING_LIGHT_COMMAND = f"{REQ_HEADER}{CEILING_LIGHT_COMMAND_HEADER}"
  8. CEILING_LIGHT_ON_KEY = f"{CEILING_LIGHT_COMMAND}01FF01FFFF"
  9. CEILING_LIGHT_OFF_KEY = f"{CEILING_LIGHT_COMMAND}02FF01FFFF"
  10. CW_BRIGHTNESS_KEY = f"{CEILING_LIGHT_COMMAND}010001"
  11. BRIGHTNESS_KEY = f"{CEILING_LIGHT_COMMAND}01FF01"
  12. _LOGGER = logging.getLogger(__name__)
  13. class SwitchbotCeilingLight(SwitchbotBaseLight):
  14. """Representation of a Switchbot bulb."""
  15. @property
  16. def color_modes(self) -> set[ColorMode]:
  17. """Return the supported color modes."""
  18. return {ColorMode.COLOR_TEMP}
  19. async def turn_on(self) -> bool:
  20. """Turn device on."""
  21. result = await self._send_command(CEILING_LIGHT_ON_KEY)
  22. ret = self._check_command_result(result, 0, {0x01})
  23. self._override_state({"isOn": True})
  24. self._fire_callbacks()
  25. return ret
  26. async def turn_off(self) -> bool:
  27. """Turn device off."""
  28. result = await self._send_command(CEILING_LIGHT_OFF_KEY)
  29. ret = self._check_command_result(result, 0, {0x01})
  30. self._override_state({"isOn": False})
  31. self._fire_callbacks()
  32. return ret
  33. async def set_brightness(self, brightness: int) -> bool:
  34. """Set brightness."""
  35. assert 0 <= brightness <= 100, "Brightness must be between 0 and 100"
  36. result = await self._send_command(f"{BRIGHTNESS_KEY}{brightness:02X}0FA1")
  37. ret = self._check_command_result(result, 0, {0x01})
  38. self._override_state({"brightness": brightness, "isOn": True})
  39. self._fire_callbacks()
  40. return ret
  41. async def set_color_temp(self, brightness: int, color_temp: int) -> bool:
  42. """Set color temp."""
  43. assert 0 <= brightness <= 100, "Brightness must be between 0 and 100"
  44. assert 2700 <= color_temp <= 6500, "Color Temp must be between 0 and 100"
  45. result = await self._send_command(
  46. f"{CW_BRIGHTNESS_KEY}{brightness:02X}{color_temp:04X}"
  47. )
  48. ret = self._check_command_result(result, 0, {0x01})
  49. self._state["cw"] = color_temp
  50. self._override_state({"brightness": brightness, "isOn": True})
  51. self._fire_callbacks()
  52. return ret
  53. async def set_rgb(self, brightness: int, r: int, g: int, b: int) -> bool:
  54. """Set rgb."""
  55. # Not supported on this device