1 """Reproduce an Input datetime state."""
3 from __future__
import annotations
6 from collections.abc
import Iterable
14 from .
import ATTR_DATE, ATTR_DATETIME, ATTR_TIME, CONF_HAS_DATE, CONF_HAS_TIME, DOMAIN
16 _LOGGER = logging.getLogger(__name__)
20 """Test if string dt is a valid datetime."""
22 return dt_util.parse_datetime(string)
is not None
28 """Test if string dt is a valid date."""
29 return dt_util.parse_date(string)
is not None
33 """Test if string dt is a valid time."""
34 return dt_util.parse_time(string)
is not None
41 context: Context |
None =
None,
42 reproduce_options: dict[str, Any] |
None =
None,
44 """Reproduce a single state."""
45 if (cur_state := hass.states.get(state.entity_id))
is None:
46 _LOGGER.warning(
"Unable to find entity %s", state.entity_id)
49 has_time = cur_state.attributes.get(CONF_HAS_TIME)
50 has_date = cur_state.attributes.get(CONF_HAS_DATE)
58 "Invalid state specified for %s: %s", state.entity_id, state.state
63 if cur_state.state == state.state:
66 service_data = {ATTR_ENTITY_ID: state.entity_id}
68 if has_time
and has_date:
69 service_data[ATTR_DATETIME] = state.state
71 service_data[ATTR_TIME] = state.state
73 service_data[ATTR_DATE] = state.state
75 await hass.services.async_call(
76 DOMAIN,
"set_datetime", service_data, context=context, blocking=
True
82 states: Iterable[State],
84 context: Context |
None =
None,
85 reproduce_options: dict[str, Any] |
None =
None,
87 """Reproduce Input datetime states."""
91 hass, state, context=context, reproduce_options=reproduce_options