climate.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_GECO_HEATER,
  11. CONF_TYPE_GPCV_HEATER,
  12. CONF_TYPE_GPPH_HEATER,
  13. CONF_TYPE_KOGAN_HEATER,
  14. CONF_CLIMATE,
  15. CONF_TYPE_AUTO,
  16. )
  17. from .dehumidifier.climate import GoldairDehumidifier
  18. from .fan.climate import GoldairFan
  19. from .geco_heater.climate import GoldairGECOHeater
  20. from .gpcv_heater.climate import GoldairGPCVHeater
  21. from .heater.climate import GoldairHeater
  22. from .kogan_heater.climate import KoganHeater
  23. async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
  24. """Set up the Goldair climate device according to its type."""
  25. data = hass.data[DOMAIN][discovery_info[CONF_DEVICE_ID]]
  26. device = data["device"]
  27. if discovery_info[CONF_TYPE] == CONF_TYPE_AUTO:
  28. discovery_info[CONF_TYPE] = await device.async_inferred_type()
  29. if discovery_info[CONF_TYPE] is None:
  30. raise ValueError(f"Unable to detect type for device {device.name}")
  31. if discovery_info[CONF_TYPE] == CONF_TYPE_GPPH_HEATER:
  32. data[CONF_CLIMATE] = GoldairHeater(device)
  33. elif discovery_info[CONF_TYPE] == CONF_TYPE_DEHUMIDIFIER:
  34. data[CONF_CLIMATE] = GoldairDehumidifier(device)
  35. elif discovery_info[CONF_TYPE] == CONF_TYPE_FAN:
  36. data[CONF_CLIMATE] = GoldairFan(device)
  37. elif discovery_info[CONF_TYPE] == CONF_TYPE_GECO_HEATER:
  38. data[CONF_CLIMATE] = GoldairGECOHeater(device)
  39. elif discovery_info[CONF_TYPE] == CONF_TYPE_GPCV_HEATER:
  40. data[CONF_CLIMATE] = GoldairGPCVHeater(device)
  41. elif discovery_info[CONF_TYPE] == CONF_TYPE_KOGAN_HEATER:
  42. data[CONF_CLIMATE] = KoganHeater(device)
  43. else:
  44. raise ValueError("This device does not support working as a climate device")
  45. if CONF_CLIMATE in data:
  46. async_add_entities([data[CONF_CLIMATE]])
  47. async def async_setup_entry(hass, config_entry, async_add_entities):
  48. config = {**config_entry.data, **config_entry.options}
  49. discovery_info = {
  50. CONF_DEVICE_ID: config[CONF_DEVICE_ID],
  51. CONF_TYPE: config[CONF_TYPE],
  52. }
  53. await async_setup_platform(hass, {}, async_add_entities, discovery_info)