light.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. Platform to control the LED display light on Goldair WiFi-connected dehumidifiers.
  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_OFF, HVAC_MODE_TO_DPS_MODE, PROPERTY_TO_DPS_ID
  9. class GoldairDehumidifierLedDisplayLight(LightEntity):
  10. """Representation of a Goldair WiFi-connected dehumidifier 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 dehumidifier LED display."""
  27. return self._device.unique_id
  28. @property
  29. def device_info(self):
  30. """Return device information about this dehumidifier 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 not (self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]))
  43. async def async_turn_on(self):
  44. await self._device.async_set_property(
  45. PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF], False
  46. )
  47. async def async_turn_off(self):
  48. await self._device.async_set_property(
  49. PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF], True
  50. )
  51. async def async_toggle(self):
  52. dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
  53. dps_display_off = self._device.get_property(
  54. PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]
  55. )
  56. if dps_hvac_mode != HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]:
  57. await (self.async_turn_on() if dps_display_off else self.async_turn_off())
  58. async def async_update(self):
  59. await self._device.async_refresh()