light.py 2.0 KB

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