1 """Reproduce an Switch state."""
3 from __future__
import annotations
6 from collections.abc
import Iterable
21 _LOGGER = logging.getLogger(__name__)
23 VALID_STATES = {STATE_ON, STATE_OFF}
30 context: Context |
None =
None,
31 reproduce_options: dict[str, Any] |
None =
None,
33 """Reproduce a single state."""
34 if (cur_state := hass.states.get(state.entity_id))
is None:
35 _LOGGER.warning(
"Unable to find entity %s", state.entity_id)
38 if state.state
not in VALID_STATES:
40 "Invalid state specified for %s: %s", state.entity_id, state.state
45 if cur_state.state == state.state:
48 service_data = {ATTR_ENTITY_ID: state.entity_id}
50 if state.state == STATE_ON:
51 service = SERVICE_TURN_ON
52 elif state.state == STATE_OFF:
53 service = SERVICE_TURN_OFF
55 await hass.services.async_call(
56 DOMAIN, service, service_data, context=context, blocking=
True
62 states: Iterable[State],
64 context: Context |
None =
None,
65 reproduce_options: dict[str, Any] |
None =
None,
67 """Reproduce Switch states."""
71 hass, state, context=context, reproduce_options=reproduce_options
None async_reproduce_states(HomeAssistant hass, Iterable[State] states, *Context|None context=None, dict[str, Any]|None reproduce_options=None)
None _async_reproduce_state(HomeAssistant hass, State state, *Context|None context=None, dict[str, Any]|None reproduce_options=None)