light.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(
  48. PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF], False
  49. )
  50. async def async_turn_off(self):
  51. await self._device.async_set_property(
  52. PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF], True
  53. )
  54. async def async_toggle(self):
  55. dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
  56. dps_display_off = self._device.get_property(
  57. PROPERTY_TO_DPS_ID[ATTR_DISPLAY_OFF]
  58. )
  59. if dps_hvac_mode != HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]:
  60. await (
  61. self.async_turn_on() if dps_display_off else self.async_turn_off()
  62. )
  63. async def async_update(self):
  64. await self._device.async_refresh()