select.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """
  2. Platform for Tuya Select options that don't fit into other entity types.
  3. """
  4. from homeassistant.components.select import SelectEntity
  5. from ..device import TuyaLocalDevice
  6. from ..helpers.device_config import TuyaEntityConfig
  7. from ..helpers.mixin import TuyaLocalEntity
  8. class TuyaLocalSelect(TuyaLocalEntity, SelectEntity):
  9. """Representation of a Tuya Select"""
  10. def __init__(self, device: TuyaLocalDevice, config: TuyaEntityConfig):
  11. """
  12. Initialise the select.
  13. Args:
  14. device (TuyaLocalDevice): the device API instance
  15. config (TuyaEntityConfig): the configuration for this entity
  16. """
  17. dps_map = self._init_begin(device, config)
  18. self._option_dps = dps_map.pop("option")
  19. if self._option_dps is None:
  20. raise AttributeError(f"{config.name} is missing an option dps")
  21. if not self._option_dps.values(device):
  22. raise AttributeError(
  23. f"{config.name} does not have a mapping to a list of options"
  24. )
  25. self._init_end(dps_map)
  26. @property
  27. def options(self):
  28. "Return the list of possible options."
  29. return self._option_dps.values(self._device)
  30. @property
  31. def current_option(self):
  32. "Return the currently selected option"
  33. return self._option_dps.get_value(self._device)
  34. async def async_select_option(self, option):
  35. "Set the option"
  36. await self._option_dps.async_set_value(self._device, option)