ceiling_light.py 2.5 KB

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