climate.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """
  2. Setup for different kinds of Goldair 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_GECO_HEATER,
  7. CONF_TYPE_GPCV_HEATER, CONF_TYPE_HEATER,
  8. CONF_CLIMATE, CONF_TYPE_AUTO)
  9. from .dehumidifier.climate import GoldairDehumidifier
  10. from .fan.climate import GoldairFan
  11. from .geco_heater.climate import GoldairGECOHeater
  12. from .gpcv_heater.climate import GoldairGPCVHeater
  13. from .heater.climate import GoldairHeater
  14. async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
  15. """Set up the Goldair climate device according to its type."""
  16. data = hass.data[DOMAIN][discovery_info[CONF_DEVICE_ID]]
  17. device = data['device']
  18. if discovery_info[CONF_TYPE] == CONF_TYPE_AUTO:
  19. discovery_info[CONF_TYPE] = await device.async_inferred_type()
  20. if discovery_info[CONF_TYPE] is None:
  21. raise ValueError(f"Unable to detect type for device {device.name}")
  22. if discovery_info[CONF_TYPE] == CONF_TYPE_HEATER:
  23. data[CONF_CLIMATE] = GoldairHeater(device)
  24. elif discovery_info[CONF_TYPE] == CONF_TYPE_DEHUMIDIFIER:
  25. data[CONF_CLIMATE] = GoldairDehumidifier(device)
  26. elif discovery_info[CONF_TYPE] == CONF_TYPE_FAN:
  27. data[CONF_CLIMATE] = GoldairFan(device)
  28. elif discovery_info[CONF_TYPE] == CONF_TYPE_GECO_HEATER:
  29. data[CONF_CLIMATE] = GoldairGECOHeater(device)
  30. elif discovery_info[CONF_TYPE] == CONF_TYPE_GPCV_HEATER:
  31. data[CONF_CLIMATE] = GoldairGPCVHeater(device)
  32. if CONF_CLIMATE in data:
  33. async_add_entities([data[CONF_CLIMATE]])
  34. async def async_setup_entry(hass, config_entry, async_add_entities):
  35. config = {**config_entry.data, **config_entry.options}
  36. discovery_info = {
  37. CONF_DEVICE_ID: config[CONF_DEVICE_ID],
  38. CONF_TYPE: config[CONF_TYPE],
  39. }
  40. await async_setup_platform(hass, {}, async_add_entities, discovery_info)