light.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. """
  2. Platform to control the LED display light on Goldair WiFi-connected heaters and panels.
  3. """
  4. from homeassistant.components.climate import ATTR_HVAC_MODE, HVAC_MODE_OFF
  5. from homeassistant.components.light import Light
  6. from homeassistant.const import STATE_UNAVAILABLE
  7. from ..device import GoldairTuyaDevice
  8. from .const import ATTR_DISPLAY_ON, HVAC_MODE_TO_DPS_MODE, PROPERTY_TO_DPS_ID
  9. class GoldairHeaterLedDisplayLight(Light):
  10. """Representation of a Goldair WiFi-connected heater LED display."""
  11. def __init__(self, device):
  12. """Initialize the light.
  13. Args:
  14. device (GoldairTuyaDevice): The device API instance."""
  15. self._device = device
  16. @property
  17. def should_poll(self):
  18. """Return the polling state."""
  19. return True
  20. @property
  21. def name(self):
  22. """Return the name of the light."""
  23. return self._device.name
  24. @property
  25. def unique_id(self):
  26. """Return the unique id for this heater LED display."""
  27. return self._device.unique_id
  28. @property
  29. def device_info(self):
  30. """Return device information about this heater LED display."""
  31. return self._device.device_info
  32. @property
  33. def is_on(self):
  34. """Return the current state."""
  35. dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
  36. dps_display_on = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
  37. if (
  38. dps_hvac_mode is None
  39. or dps_hvac_mode == HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]
  40. ):
  41. return STATE_UNAVAILABLE
  42. else:
  43. return dps_display_on
  44. async def async_turn_on(self):
  45. await self._device.async_set_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], True)
  46. async def async_turn_off(self):
  47. await self._device.async_set_property(
  48. PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], False
  49. )
  50. async def async_toggle(self):
  51. dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
  52. dps_display_on = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
  53. if dps_hvac_mode != HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]:
  54. await (
  55. self.async_turn_on() if not dps_display_on else self.async_turn_off()
  56. )
  57. async def async_update(self):
  58. await self._device.async_refresh()