| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- """
- Platform to control the LED display light on Goldair WiFi-connected fans.
- """
- try:
- from homeassistant.components.light import LightEntity
- except ImportError:
- from homeassistant.components.light import Light as LightEntity
- from homeassistant.components.climate import ATTR_HVAC_MODE, HVAC_MODE_OFF
- from homeassistant.const import STATE_UNAVAILABLE
- from ..device import TuyaLocalDevice
- from .const import ATTR_DISPLAY_ON, HVAC_MODE_TO_DPS_MODE, PROPERTY_TO_DPS_ID
- class GoldairFanLedDisplayLight(LightEntity):
- """Representation of a Goldair WiFi-connected fan LED display."""
- def __init__(self, device):
- """Initialize the light.
- Args:
- device (TuyaLocalDevice): The device API instance."""
- self._device = device
- @property
- def should_poll(self):
- """Return the polling state."""
- return True
- @property
- def name(self):
- """Return the name of the light."""
- return self._device.name
- @property
- def unique_id(self):
- """Return the unique id for this fan LED display."""
- return self._device.unique_id
- @property
- def device_info(self):
- """Return device information about this LED display."""
- return self._device.device_info
- @property
- def icon(self):
- """Return the icon to use in the frontend for this device."""
- if self.is_on:
- return "mdi:led-on"
- else:
- return "mdi:led-off"
- @property
- def is_on(self):
- """Return the current state."""
- return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
- async def async_turn_on(self):
- await self._device.async_set_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], True)
- async def async_turn_off(self):
- await self._device.async_set_property(
- PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], False
- )
- async def async_toggle(self):
- dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
- dps_display_on = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
- if dps_hvac_mode != HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]:
- await (
- self.async_turn_on() if not dps_display_on else self.async_turn_off()
- )
- async def async_update(self):
- await self._device.async_refresh()
|