light.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.tuya_local import TuyaLocalDevice
  7. from custom_components.tuya_local.heater.climate import (
  8. ATTR_DISPLAY_ON, PROPERTY_TO_DPS_ID, HVAC_MODE_TO_DPS_MODE
  9. )
  10. from homeassistant.components.climate import (
  11. ATTR_HVAC_MODE, HVAC_MODE_OFF
  12. )
  13. class GoldairHeaterLedDisplayLight(Light):
  14. """Representation of a Goldair WiFi-connected heater LED display."""
  15. def __init__(self, device):
  16. """Initialize the light.
  17. Args:
  18. device (TuyaLocalDevice): The device API instance."""
  19. self._device = device
  20. @property
  21. def should_poll(self):
  22. """Return the polling state."""
  23. return True
  24. @property
  25. def name(self):
  26. """Return the name of the light."""
  27. return self._device.name
  28. @property
  29. def is_on(self):
  30. """Return the current state."""
  31. dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
  32. dps_display_on = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
  33. if dps_hvac_mode is None or dps_hvac_mode == HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]:
  34. return STATE_UNAVAILABLE
  35. else:
  36. return dps_display_on
  37. def turn_on(self):
  38. self._device.set_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], True)
  39. def turn_off(self):
  40. self._device.set_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], False)
  41. def toggle(self):
  42. dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
  43. dps_display_on = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
  44. if dps_hvac_mode != HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]:
  45. self.turn_on() if not dps_display_on else self.turn_off()