lock.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_CHILD_LOCK, CONF_TYPE_AUTO)
  9. from .dehumidifier.lock import GoldairDehumidifierChildLock
  10. from .gpcv_heater.lock import GoldairGPCVHeaterChildLock
  11. from .geco_heater.lock import GoldairGECOHeaterChildLock
  12. from .heater.lock import GoldairHeaterChildLock
  13. async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
  14. """Set up the Goldair climate device according to its type."""
  15. data = hass.data[DOMAIN][discovery_info[CONF_DEVICE_ID]]
  16. device = data['device']
  17. if discovery_info[CONF_TYPE] == CONF_TYPE_AUTO:
  18. discovery_info[CONF_TYPE] = await device.async_inferred_type()
  19. if discovery_info[CONF_TYPE] is None:
  20. raise ValueError(f"Unable to detect type for device {device.name}")
  21. if discovery_info[CONF_TYPE] == CONF_TYPE_HEATER:
  22. data[CONF_CHILD_LOCK] = GoldairHeaterChildLock(device)
  23. elif discovery_info[CONF_TYPE] == CONF_TYPE_DEHUMIDIFIER:
  24. data[CONF_CHILD_LOCK] = GoldairDehumidifierChildLock(device)
  25. elif discovery_info[CONF_TYPE] == CONF_TYPE_FAN:
  26. raise ValueError("Goldair fans do not support child lock.")
  27. elif discovery_info[CONF_TYPE] == CONF_TYPE_GECO_HEATER:
  28. data[CONF_CHILD_LOCK] = GoldairGECOHeaterChildLock(device)
  29. elif discovery_info[CONF_TYPE] == CONF_TYPE_GPCV_HEATER:
  30. data[CONF_CHILD_LOCK] = GoldairGPCVHeaterChildLock(device)
  31. if CONF_CHILD_LOCK in data:
  32. async_add_entities([data[CONF_CHILD_LOCK]])
  33. async def async_setup_entry(hass, config_entry, async_add_entities):
  34. config = {**config_entry.data, **config_entry.options}
  35. discovery_info = {
  36. CONF_DEVICE_ID: config[CONF_DEVICE_ID],
  37. CONF_TYPE: config[CONF_TYPE],
  38. }
  39. await async_setup_platform(hass, {}, async_add_entities, discovery_info)