lock.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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_GPCV_HEATER, CONF_TYPE_HEATER,
  7. CONF_CHILD_LOCK, CONF_TYPE_AUTO)
  8. from .dehumidifier.lock import GoldairDehumidifierChildLock
  9. from .gpcv_heater.lock import GoldairGPCVHeaterChildLock
  10. from .heater.lock import GoldairHeaterChildLock
  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_CHILD_LOCK] = GoldairHeaterChildLock(device)
  21. elif discovery_info[CONF_TYPE] == CONF_TYPE_DEHUMIDIFIER:
  22. data[CONF_CHILD_LOCK] = GoldairDehumidifierChildLock(device)
  23. elif discovery_info[CONF_TYPE] == CONF_TYPE_FAN:
  24. raise ValueError("Goldair fans do not support child lock.")
  25. elif discovery_info[CONF_TYPE] == CONF_GPCV_HEATER:
  26. data[CONF_CHILD_LOCK] = GoldairGPCVHeaterChildLock(device)
  27. if CONF_CHILD_LOCK in data:
  28. async_add_entities([data[CONF_CHILD_LOCK]])
  29. async def async_setup_entry(hass, config_entry, async_add_entities):
  30. config = {**config_entry.data, **config_entry.options}
  31. discovery_info = {
  32. CONF_DEVICE_ID: config[CONF_DEVICE_ID],
  33. CONF_TYPE: config[CONF_TYPE],
  34. }
  35. await async_setup_platform(hass, {}, async_add_entities, discovery_info)