light.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """
  2. Platform to control the LED display light on Goldair WiFi-connected heaters and panels.
  3. """
  4. from homeassistant.components.light import LightEntity
  5. from homeassistant.components.climate import ATTR_HVAC_MODE, HVAC_MODE_OFF
  6. from homeassistant.const import STATE_UNAVAILABLE
  7. from ..device import TuyaLocalDevice
  8. from .const import ATTR_DISPLAY_ON, HVAC_MODE_TO_DPS_MODE, PROPERTY_TO_DPS_ID
  9. class GoldairHeaterLedDisplayLight(LightEntity):
  10. """Representation of a Goldair WiFi-connected heater LED display."""
  11. def __init__(self, device):
  12. """Initialize the light.
  13. Args:
  14. device (TuyaLocalDevice): 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 icon(self):
  34. """Return the icon to use in the frontend for this device."""
  35. if self.is_on:
  36. return "mdi:led-on"
  37. else:
  38. return "mdi:led-off"
  39. @property
  40. def is_on(self):
  41. """Return the current state."""
  42. return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
  43. async def async_turn_on(self):
  44. await self._device.async_set_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], True)
  45. async def async_turn_off(self):
  46. await self._device.async_set_property(
  47. PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], False
  48. )
  49. async def async_toggle(self):
  50. dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
  51. dps_display_on = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
  52. if dps_hvac_mode != HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]:
  53. await (
  54. self.async_turn_on() if not dps_display_on else self.async_turn_off()
  55. )
  56. async def async_update(self):
  57. await self._device.async_refresh()