1 """Reproduce an Timer state."""
3 from __future__
import annotations
6 from collections.abc
import Iterable
24 _LOGGER = logging.getLogger(__name__)
26 VALID_STATES = {STATUS_IDLE, STATUS_ACTIVE, STATUS_PAUSED}
33 context: Context |
None =
None,
34 reproduce_options: dict[str, Any] |
None =
None,
36 """Reproduce a single state."""
37 if (cur_state := hass.states.get(state.entity_id))
is None:
38 _LOGGER.warning(
"Unable to find entity %s", state.entity_id)
41 if state.state
not in VALID_STATES:
43 "Invalid state specified for %s: %s", state.entity_id, state.state
48 if cur_state.state == state.state
and cur_state.attributes.get(
50 ) == state.attributes.get(ATTR_DURATION):
53 service_data = {ATTR_ENTITY_ID: state.entity_id}
55 if state.state == STATUS_ACTIVE:
56 service = SERVICE_START
57 if ATTR_DURATION
in state.attributes:
58 service_data[ATTR_DURATION] = state.attributes[ATTR_DURATION]
59 elif state.state == STATUS_PAUSED:
60 service = SERVICE_PAUSE
61 elif state.state == STATUS_IDLE:
62 service = SERVICE_CANCEL
64 await hass.services.async_call(
65 DOMAIN, service, service_data, context=context, blocking=
True
71 states: Iterable[State],
73 context: Context |
None =
None,
74 reproduce_options: dict[str, Any] |
None =
None,
76 """Reproduce Timer states."""
80 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)