lock.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. Setup for different kinds of Goldair climate devices
  3. """
  4. import logging
  5. from . import DOMAIN
  6. from .const import (
  7. CONF_CHILD_LOCK,
  8. CONF_DEVICE_ID,
  9. CONF_TYPE,
  10. CONF_TYPE_AUTO,
  11. CONF_TYPE_DEHUMIDIFIER,
  12. CONF_TYPE_FAN,
  13. CONF_TYPE_GECO_HEATER,
  14. CONF_TYPE_GPCV_HEATER,
  15. CONF_TYPE_GPPH_HEATER,
  16. )
  17. from .dehumidifier.lock import GoldairDehumidifierChildLock
  18. from .geco_heater.lock import GoldairGECOHeaterChildLock
  19. from .gpcv_heater.lock import GoldairGPCVHeaterChildLock
  20. from .heater.lock import GoldairHeaterChildLock
  21. _LOGGER = logging.getLogger(__name__)
  22. async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
  23. """Set up the Goldair climate device according to its type."""
  24. _LOGGER.debug(f"Domain data: {hass.data[DOMAIN]}")
  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_CHILD_LOCK] = GoldairHeaterChildLock(device)
  33. elif discovery_info[CONF_TYPE] == CONF_TYPE_DEHUMIDIFIER:
  34. data[CONF_CHILD_LOCK] = GoldairDehumidifierChildLock(device)
  35. elif discovery_info[CONF_TYPE] == CONF_TYPE_FAN:
  36. raise ValueError("Goldair fans do not support child lock.")
  37. elif discovery_info[CONF_TYPE] == CONF_TYPE_GECO_HEATER:
  38. data[CONF_CHILD_LOCK] = GoldairGECOHeaterChildLock(device)
  39. elif discovery_info[CONF_TYPE] == CONF_TYPE_GPCV_HEATER:
  40. data[CONF_CHILD_LOCK] = GoldairGPCVHeaterChildLock(device)
  41. if CONF_CHILD_LOCK in data:
  42. async_add_entities([data[CONF_CHILD_LOCK]])
  43. async def async_setup_entry(hass, config_entry, async_add_entities):
  44. config = {**config_entry.data, **config_entry.options}
  45. discovery_info = {
  46. CONF_DEVICE_ID: config[CONF_DEVICE_ID],
  47. CONF_TYPE: config[CONF_TYPE],
  48. }
  49. await async_setup_platform(hass, {}, async_add_entities, discovery_info)