lock.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """
  2. Setup for different kinds of Tuya 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_HEATER, CONF_TYPE_KOGAN_HEATER, CONF_CHILD_LOCK, CONF_TYPE_AUTO)
  7. from .dehumidifier.lock import GoldairDehumidifierChildLock
  8. from .heater.lock import GoldairHeaterChildLock
  9. async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
  10. """Set up the Goldair climate device according to its type."""
  11. data = hass.data[DOMAIN][discovery_info[CONF_DEVICE_ID]]
  12. device = data['device']
  13. if discovery_info[CONF_TYPE] == CONF_TYPE_AUTO:
  14. discovery_info[CONF_TYPE] = await device.async_inferred_type()
  15. if discovery_info[CONF_TYPE] is None:
  16. raise ValueError(f"Unable to detect type for device {device.name}")
  17. if discovery_info[CONF_TYPE] == CONF_TYPE_HEATER:
  18. data[CONF_CHILD_LOCK] = GoldairHeaterChildLock(device)
  19. if discovery_info[CONF_TYPE] == CONF_TYPE_DEHUMIDIFIER:
  20. data[CONF_CHILD_LOCK] = GoldairDehumidifierChildLock(device)
  21. if discovery_info[CONF_TYPE] == CONF_TYPE_FAN:
  22. raise ValueError('Goldair fans do not support Child Lock.')
  23. if discovery_info[CONF_TYPE] == CONF_TYPE_KOGAN_HEATER:
  24. raise ValueError('Kogan Heaters do not support Child Lock.')
  25. if CONF_CHILD_LOCK in data:
  26. async_add_entities([data[CONF_CHILD_LOCK]])
  27. async def async_setup_entry(hass, config_entry, async_add_entities):
  28. config = {**config_entry.data, **config_entry.options}
  29. discovery_info = {
  30. CONF_DEVICE_ID: config[CONF_DEVICE_ID],
  31. CONF_TYPE: config[CONF_TYPE],
  32. }
  33. await async_setup_platform(hass, {}, async_add_entities, discovery_info)