1 """Reproduce an Water heater state."""
3 from __future__
import annotations
6 from collections.abc
import Iterable
24 SERVICE_SET_AWAY_MODE,
25 SERVICE_SET_OPERATION_MODE,
26 SERVICE_SET_TEMPERATURE,
35 _LOGGER = logging.getLogger(__name__)
53 context: Context |
None =
None,
54 reproduce_options: dict[str, Any] |
None =
None,
56 """Reproduce a single state."""
57 if (cur_state := hass.states.get(state.entity_id))
is None:
58 _LOGGER.warning(
"Unable to find entity %s", state.entity_id)
61 if state.state
not in VALID_STATES:
63 "Invalid state specified for %s: %s", state.entity_id, state.state
69 cur_state.state == state.state
70 and cur_state.attributes.get(ATTR_TEMPERATURE)
71 == state.attributes.get(ATTR_TEMPERATURE)
72 and cur_state.attributes.get(ATTR_AWAY_MODE)
73 == state.attributes.get(ATTR_AWAY_MODE)
77 service_data = {ATTR_ENTITY_ID: state.entity_id}
79 if state.state != cur_state.state:
80 if state.state == STATE_ON:
81 service = SERVICE_TURN_ON
82 elif state.state == STATE_OFF:
83 service = SERVICE_TURN_OFF
85 service = SERVICE_SET_OPERATION_MODE
86 service_data[ATTR_OPERATION_MODE] = state.state
88 await hass.services.async_call(
89 DOMAIN, service, service_data, context=context, blocking=
True
93 state.attributes.get(ATTR_TEMPERATURE)
94 != cur_state.attributes.get(ATTR_TEMPERATURE)
95 and state.attributes.get(ATTR_TEMPERATURE)
is not None
97 await hass.services.async_call(
99 SERVICE_SET_TEMPERATURE,
101 ATTR_ENTITY_ID: state.entity_id,
102 ATTR_TEMPERATURE: state.attributes.get(ATTR_TEMPERATURE),
109 state.attributes.get(ATTR_AWAY_MODE) != cur_state.attributes.get(ATTR_AWAY_MODE)
110 and state.attributes.get(ATTR_AWAY_MODE)
is not None
112 await hass.services.async_call(
114 SERVICE_SET_AWAY_MODE,
116 ATTR_ENTITY_ID: state.entity_id,
117 ATTR_AWAY_MODE: state.attributes.get(ATTR_AWAY_MODE),
126 states: Iterable[State],
128 context: Context |
None =
None,
129 reproduce_options: dict[str, Any] |
None =
None,
131 """Reproduce Water heater states."""
132 await asyncio.gather(
135 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)