light.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_DISPLAY_LIGHT,
  8. CONF_TYPE,
  9. CONF_TYPE_AUTO,
  10. CONF_TYPE_DEHUMIDIFIER,
  11. CONF_TYPE_FAN,
  12. CONF_TYPE_GPPH_HEATER,
  13. CONF_TYPE_PURLINE_M100_HEATER,
  14. )
  15. from .dehumidifier.light import GoldairDehumidifierLedDisplayLight
  16. from .fan.light import GoldairFanLedDisplayLight
  17. from .heater.light import GoldairHeaterLedDisplayLight
  18. from .purline_m100_heater.light import PurlineM100HeaterLedDisplayLight
  19. async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
  20. """Set up the Goldair climate device according to its type."""
  21. data = hass.data[DOMAIN][discovery_info[CONF_DEVICE_ID]]
  22. device = data["device"]
  23. if discovery_info[CONF_TYPE] == CONF_TYPE_AUTO:
  24. discovery_info[CONF_TYPE] = await device.async_inferred_type()
  25. if discovery_info[CONF_TYPE] is None:
  26. raise ValueError(f"Unable to detect type for device {device.name}")
  27. if discovery_info[CONF_TYPE] == CONF_TYPE_GPPH_HEATER:
  28. data[CONF_DISPLAY_LIGHT] = GoldairHeaterLedDisplayLight(device)
  29. elif discovery_info[CONF_TYPE] == CONF_TYPE_DEHUMIDIFIER:
  30. data[CONF_DISPLAY_LIGHT] = GoldairDehumidifierLedDisplayLight(device)
  31. elif discovery_info[CONF_TYPE] == CONF_TYPE_FAN:
  32. data[CONF_DISPLAY_LIGHT] = GoldairFanLedDisplayLight(device)
  33. elif discovery_info[CONF_TYPE] == CONF_TYPE_PURLINE_M100_HEATER:
  34. dataa[CONF_DISPLAY_LIGHT] = PurlineM100HeaterLedDisplayLight(device)
  35. else:
  36. raise ValueError("This device does not support panel lighting control.")
  37. if CONF_DISPLAY_LIGHT in data:
  38. async_add_entities([data[CONF_DISPLAY_LIGHT]])
  39. async def async_setup_entry(hass, config_entry, async_add_entities):
  40. config = {**config_entry.data, **config_entry.options}
  41. discovery_info = {
  42. CONF_DEVICE_ID: config[CONF_DEVICE_ID],
  43. CONF_TYPE: config[CONF_TYPE],
  44. }
  45. await async_setup_platform(hass, {}, async_add_entities, discovery_info)