light.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. import custom_components.goldair_climate as goldair_climate
  7. def setup_platform(hass, config, add_devices, discovery_info=None):
  8. device = hass.data[goldair_climate.DOMAIN][discovery_info['host']]
  9. add_devices([
  10. GoldairLedDisplayLight(device)
  11. ])
  12. class GoldairLedDisplayLight(Light):
  13. """Representation of a Goldair WiFi-connected heater LED display."""
  14. def __init__(self, device):
  15. """Initialize the light.
  16. Args:
  17. device (GoldairHeaterDevice): The device API instance."""
  18. self._device = device
  19. @property
  20. def should_poll(self):
  21. """Return the polling state."""
  22. return True
  23. @property
  24. def name(self):
  25. """Return the name of the light."""
  26. return self._device.name
  27. @property
  28. def is_on(self):
  29. """Return the current state."""
  30. if self._device.is_on is None:
  31. return STATE_UNAVAILABLE
  32. else:
  33. return self._device.is_on and self._device.is_display_on
  34. def turn_on(self):
  35. """Turn on the LED display."""
  36. self._device.turn_display_on()
  37. def turn_off(self):
  38. """Turn off the LED display."""
  39. self._device.turn_display_off()
  40. def toggle(self):
  41. self._device.turn_display_on() if not self._device.is_display_on else self._device.turn_display_off()