1 """Reproduce an Input select state."""
3 from __future__
import annotations
6 from collections.abc
import Iterable, Mapping
13 from .
import ATTR_OPTIONS, DOMAIN, SERVICE_SELECT_OPTION, SERVICE_SET_OPTIONS
15 ATTR_GROUP = [ATTR_OPTION, ATTR_OPTIONS]
17 _LOGGER = logging.getLogger(__name__)
24 context: Context |
None =
None,
25 reproduce_options: dict[str, Any] |
None =
None,
27 """Reproduce a single state."""
29 if (cur_state := hass.states.get(state.entity_id))
is None:
30 _LOGGER.warning(
"Unable to find entity %s", state.entity_id)
34 if cur_state.state == state.state
and all(
36 for attr
in ATTR_GROUP
41 service_data = {ATTR_ENTITY_ID: state.entity_id}
44 if ATTR_OPTIONS
in state.attributes:
45 service = SERVICE_SET_OPTIONS
46 service_data[ATTR_OPTIONS] = state.attributes[ATTR_OPTIONS]
48 await hass.services.async_call(
49 DOMAIN, service, service_data, context=context, blocking=
True
53 del service_data[ATTR_OPTIONS]
56 service = SERVICE_SELECT_OPTION
57 service_data[ATTR_OPTION] = state.state
59 await hass.services.async_call(
60 DOMAIN, service, service_data, context=context, blocking=
True
66 states: Iterable[State],
68 context: Context |
None =
None,
69 reproduce_options: dict[str, Any] |
None =
None,
71 """Reproduce Input select states."""
76 hass, state, context=context, reproduce_options=reproduce_options
84 """Return true if the given attributes are equal."""
85 return attr1.get(attr_str) == attr2.get(attr_str)