light.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """
  2. Platform to control the LED display light on Goldair WiFi-connected heaters and panels.
  3. """
  4. from homeassistant.components.light import Light
  5. from homeassistant.const import STATE_UNAVAILABLE
  6. from custom_components.goldair_climate import GoldairTuyaDevice
  7. from custom_components.goldair_climate.heater.climate import (
  8. ATTR_DISPLAY_ON, GOLDAIR_PROPERTY_TO_DPS_ID, GOLDAIR_MODE_TO_HVAC_MODE
  9. )
  10. from homeassistant.components.climate import (
  11. ATTR_HVAC_MODE, HVAC_MODE_OFF
  12. )
  13. import logging
  14. _LOGGER = logging.getLogger(__name__)
  15. class GoldairHeaterLedDisplayLight(Light):
  16. """Representation of a Goldair WiFi-connected heater LED display."""
  17. def __init__(self, device):
  18. """Initialize the light.
  19. Args:
  20. device (GoldairTuyaDevice): The device API instance."""
  21. self._device = device
  22. @property
  23. def should_poll(self):
  24. """Return the polling state."""
  25. return True
  26. @property
  27. def name(self):
  28. """Return the name of the light."""
  29. return self._device.name
  30. @property
  31. def is_on(self):
  32. """Return the current state."""
  33. dps_hvac_mode = self._device.get_property(GOLDAIR_PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
  34. dps_display_on = self._device.get_property(GOLDAIR_PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
  35. if dps_hvac_mode is None or dps_hvac_mode == GOLDAIR_MODE_TO_HVAC_MODE[HVAC_MODE_OFF]:
  36. return STATE_UNAVAILABLE
  37. else:
  38. return dps_display_on
  39. def turn_on(self):
  40. self._device.set_property(GOLDAIR_PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], True)
  41. def turn_off(self):
  42. self._device.set_property(GOLDAIR_PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], False)
  43. def toggle(self):
  44. dps_hvac_mode = self._device.get_property(GOLDAIR_PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
  45. dps_display_on = self._device.get_property(GOLDAIR_PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
  46. if dps_hvac_mode != GOLDAIR_MODE_TO_HVAC_MODE[HVAC_MODE_OFF]:
  47. self.turn_on() if not dps_display_on else self.turn_off()