1 """Support for KNX/IP select entities."""
3 from __future__
import annotations
6 from xknx.devices
import Device
as XknxDevice, RawValue
8 from homeassistant
import config_entries
23 from .
import KNXModule
32 from .entity
import KnxYamlEntity
33 from .schema
import SelectSchema
39 async_add_entities: AddEntitiesCallback,
41 """Set up select(s) for KNX platform."""
42 knx_module = hass.data[KNX_MODULE_KEY]
43 config: list[ConfigType] = knx_module.config_yaml[Platform.SELECT]
49 """Return a KNX RawValue to be used within XKNX."""
52 name=config[CONF_NAME],
53 payload_length=config[CONF_PAYLOAD_LENGTH],
54 group_address=config[KNX_ADDRESS],
55 group_address_state=config.get(CONF_STATE_ADDRESS),
56 respond_to_read=config[CONF_RESPOND_TO_READ],
57 sync_state=config[CONF_SYNC_STATE],
62 """Representation of a KNX select."""
66 def __init__(self, knx_module: KNXModule, config: ConfigType) ->
None:
67 """Initialize a KNX select."""
69 knx_module=knx_module,
72 self._option_payloads: dict[str, int] = {
73 option[SelectSchema.CONF_OPTION]: option[CONF_PAYLOAD]
74 for option
in config[SelectSchema.CONF_OPTIONS]
82 """Restore last state."""
84 if not self.
_device_device.remote_value.readable
and (
88 last_state.state
not in (STATE_UNKNOWN, STATE_UNAVAILABLE)
89 and (option := self._option_payloads.
get(last_state.state))
is not None
91 self.
_device_device.remote_value.update_value(option)
94 """Call after device was updated."""
96 self.
_device_device.remote_value.value
101 """Return the option a given payload is assigned to."""
104 key
for key, value
in self._option_payloads.items()
if value == payload
106 except StopIteration:
110 """Change the selected option."""
111 payload = self._option_payloads[option]
112 await self.
_device_device.set(payload)
None __init__(self, KNXModule knx_module, ConfigType config)
str|None option_from_payload(self, int|None payload)
None async_select_option(self, str option)
None after_update_callback(self, XknxDevice device)
None async_added_to_hass(self)
State|None async_get_last_state(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, config_entries.ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
RawValue _create_raw_value(XKNX xknx, ConfigType config)