light.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. Platform to control the LED display light on Goldair WiFi-connected dehumidifiers.
  3. """
  4. try:
  5. from homeassistant.components.light import LightEntity
  6. except ImportError:
  7. from homeassistant.components.light import Light as LightEntity
  8. from homeassistant.components.climate import ATTR_HVAC_MODE, HVAC_MODE_OFF
  9. from homeassistant.const import STATE_UNAVAILABLE
  10. from ..device import TuyaLocalDevice
  11. from .const import ATTR_DISPLAY_OFF, HVAC_MODE_TO_DPS_MODE, PROPERTY_TO_DPS_ID
  12. class GoldairDehumidifierLedDisplayLight(LightEntity):
  13. """Representation of a Goldair WiFi-connected dehumidifier LED display."""
  14. def __init__(self, device):
  15. """Initialize the light.
  16. Args:
  17. device (TuyaLocalDevice): 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 unique_id(self):
  29. """Return the unique id for this dehumidifier LED display."""
  30. return self._device.unique_id
  31. @property
  32. def device_info(self):
  33. """Return device information about this dehumidifier LED display."""
  34. return self._device.device_info
  35. @property
  36. def icon(self):
  37. """Return the icon to use in the frontend for this device."""
  38. if self.is_on:
  39. return "mdi:led-on"
  40. else:
  41. return "mdi:led-off"
  42. @property
  43. def is_on(self):
  44. """Return the current state."""
  45. return not(self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]))
  46. async def async_turn_on(self):
  47. await self._device.async_set_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF], False)
  48. async def async_turn_off(self):
  49. await self._device.async_set_property(
  50. PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF], True
  51. )
  52. async def async_toggle(self):
  53. dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
  54. dps_display_off = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF])
  55. if dps_hvac_mode != HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]:
  56. await (self.turn_on() if dps_display_off else self.turn_off())
  57. async def async_update(self):
  58. await self._device.async_refresh()