light.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """
  2. Setup for different kinds of Tuya climate devices
  3. """
  4. from . import DOMAIN
  5. from .const import (
  6. CONF_DEVICE_ID,
  7. CONF_TYPE,
  8. CONF_TYPE_DEHUMIDIFIER,
  9. CONF_TYPE_FAN,
  10. CONF_TYPE_GPPH_HEATER,
  11. CONF_DISPLAY_LIGHT,
  12. CONF_TYPE_AUTO,
  13. )
  14. from .dehumidifier.light import GoldairDehumidifierLedDisplayLight
  15. from .fan.light import GoldairFanLedDisplayLight
  16. from .heater.light import GoldairHeaterLedDisplayLight
  17. async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
  18. """Set up the Goldair climate device according to its type."""
  19. data = hass.data[DOMAIN][discovery_info[CONF_DEVICE_ID]]
  20. device = data["device"]
  21. if discovery_info[CONF_TYPE] == CONF_TYPE_AUTO:
  22. discovery_info[CONF_TYPE] = await device.async_inferred_type()
  23. if discovery_info[CONF_TYPE] is None:
  24. raise ValueError(f"Unable to detect type for device {device.name}")
  25. if discovery_info[CONF_TYPE] == CONF_TYPE_GPPH_HEATER:
  26. data[CONF_DISPLAY_LIGHT] = GoldairHeaterLedDisplayLight(device)
  27. elif discovery_info[CONF_TYPE] == CONF_TYPE_DEHUMIDIFIER:
  28. data[CONF_DISPLAY_LIGHT] = GoldairDehumidifierLedDisplayLight(device)
  29. elif discovery_info[CONF_TYPE] == CONF_TYPE_FAN:
  30. data[CONF_DISPLAY_LIGHT] = GoldairFanLedDisplayLight(device)
  31. else:
  32. raise ValueError("This device does not support panel lighting control.")
  33. if CONF_DISPLAY_LIGHT in data:
  34. async_add_entities([data[CONF_DISPLAY_LIGHT]])
  35. async def async_setup_entry(hass, config_entry, async_add_entities):
  36. config = {**config_entry.data, **config_entry.options}
  37. discovery_info = {
  38. CONF_DEVICE_ID: config[CONF_DEVICE_ID],
  39. CONF_TYPE: config[CONF_TYPE],
  40. }
  41. await async_setup_platform(hass, {}, async_add_entities, discovery_info)