1 """Module that groups code required to handle state restore for component."""
3 from __future__
import annotations
6 from collections.abc
import Iterable
17 ATTR_SWING_HORIZONTAL_MODE,
19 ATTR_TARGET_TEMP_HIGH,
25 SERVICE_SET_HVAC_MODE,
26 SERVICE_SET_PRESET_MODE,
27 SERVICE_SET_SWING_HORIZONTAL_MODE,
28 SERVICE_SET_SWING_MODE,
29 SERVICE_SET_TEMPERATURE,
37 context: Context |
None =
None,
38 reproduce_options: dict[str, Any] |
None =
None,
40 """Reproduce component states."""
42 async
def call_service(
43 service: str, keys: Iterable, data: dict[str, Any] |
None =
None
45 """Call service with set of attributes given."""
47 data[
"entity_id"] = state.entity_id
49 if (value := state.attributes.get(key))
is not None:
52 await hass.services.async_call(
53 DOMAIN, service, data, blocking=
True, context=context
56 if state.state
in HVAC_MODES:
57 await call_service(SERVICE_SET_HVAC_MODE, [], {ATTR_HVAC_MODE: state.state})
60 (ATTR_TEMPERATURE
in state.attributes)
61 or (ATTR_TARGET_TEMP_HIGH
in state.attributes)
62 or (ATTR_TARGET_TEMP_LOW
in state.attributes)
65 SERVICE_SET_TEMPERATURE,
66 [ATTR_TEMPERATURE, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW],
70 ATTR_PRESET_MODE
in state.attributes
71 and state.attributes[ATTR_PRESET_MODE]
is not None
73 await call_service(SERVICE_SET_PRESET_MODE, [ATTR_PRESET_MODE])
76 ATTR_SWING_MODE
in state.attributes
77 and state.attributes[ATTR_SWING_MODE]
is not None
79 await call_service(SERVICE_SET_SWING_MODE, [ATTR_SWING_MODE])
82 ATTR_SWING_HORIZONTAL_MODE
in state.attributes
83 and state.attributes[ATTR_SWING_HORIZONTAL_MODE]
is not None
86 SERVICE_SET_SWING_HORIZONTAL_MODE, [ATTR_SWING_HORIZONTAL_MODE]
90 ATTR_FAN_MODE
in state.attributes
91 and state.attributes[ATTR_FAN_MODE]
is not None
93 await call_service(SERVICE_SET_FAN_MODE, [ATTR_FAN_MODE])
95 if ATTR_HUMIDITY
in state.attributes:
96 await call_service(SERVICE_SET_HUMIDITY, [ATTR_HUMIDITY])
101 states: Iterable[State],
103 context: Context |
None =
None,
104 reproduce_options: dict[str, Any] |
None =
None,
106 """Reproduce component states."""
107 await asyncio.gather(
110 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_states(HomeAssistant hass, State state, *Context|None context=None, dict[str, Any]|None reproduce_options=None)