1 """Reproduce an Cover state."""
3 from __future__
import annotations
6 from collections.abc
import Iterable
13 SERVICE_CLOSE_COVER_TILT,
15 SERVICE_OPEN_COVER_TILT,
16 SERVICE_SET_COVER_POSITION,
17 SERVICE_SET_COVER_TILT_POSITION,
22 ATTR_CURRENT_POSITION,
23 ATTR_CURRENT_TILT_POSITION,
30 _LOGGER = logging.getLogger(__name__)
44 context: Context |
None =
None,
45 reproduce_options: dict[str, Any] |
None =
None,
47 """Reproduce a single state."""
48 if (cur_state := hass.states.get(state.entity_id))
is None:
49 _LOGGER.warning(
"Unable to find entity %s", state.entity_id)
52 if state.state
not in VALID_STATES:
54 "Invalid state specified for %s: %s", state.entity_id, state.state
60 cur_state.state == state.state
61 and cur_state.attributes.get(ATTR_CURRENT_POSITION)
62 == state.attributes.get(ATTR_CURRENT_POSITION)
63 and cur_state.attributes.get(ATTR_CURRENT_TILT_POSITION)
64 == state.attributes.get(ATTR_CURRENT_TILT_POSITION)
68 service_data = {ATTR_ENTITY_ID: state.entity_id}
69 service_data_tilting = {ATTR_ENTITY_ID: state.entity_id}
72 cur_state.state == state.state
73 and cur_state.attributes.get(ATTR_CURRENT_POSITION)
74 == state.attributes.get(ATTR_CURRENT_POSITION)
77 if state.state
in [CoverState.CLOSED, CoverState.CLOSING]:
78 service = SERVICE_CLOSE_COVER
79 elif state.state
in [CoverState.OPEN, CoverState.OPENING]:
81 ATTR_CURRENT_POSITION
in cur_state.attributes
82 and ATTR_CURRENT_POSITION
in state.attributes
84 service = SERVICE_SET_COVER_POSITION
85 service_data[ATTR_POSITION] = state.attributes[ATTR_CURRENT_POSITION]
87 service = SERVICE_OPEN_COVER
89 await hass.services.async_call(
90 DOMAIN, service, service_data, context=context, blocking=
True
94 ATTR_CURRENT_TILT_POSITION
in state.attributes
95 and ATTR_CURRENT_TILT_POSITION
in cur_state.attributes
96 and cur_state.attributes.get(ATTR_CURRENT_TILT_POSITION)
97 != state.attributes.get(ATTR_CURRENT_TILT_POSITION)
100 if state.attributes.get(ATTR_CURRENT_TILT_POSITION) == 100:
101 service_tilting = SERVICE_OPEN_COVER_TILT
102 elif state.attributes.get(ATTR_CURRENT_TILT_POSITION) == 0:
103 service_tilting = SERVICE_CLOSE_COVER_TILT
105 service_tilting = SERVICE_SET_COVER_TILT_POSITION
106 service_data_tilting[ATTR_TILT_POSITION] = state.attributes[
107 ATTR_CURRENT_TILT_POSITION
110 await hass.services.async_call(
113 service_data_tilting,
121 states: Iterable[State],
123 context: Context |
None =
None,
124 reproduce_options: dict[str, Any] |
None =
None,
126 """Reproduce Cover states."""
128 await asyncio.gather(
131 hass, state, context=context, reproduce_options=reproduce_options
None _async_reproduce_state(HomeAssistant hass, State state, *Context|None context=None, dict[str, Any]|None reproduce_options=None)
None async_reproduce_states(HomeAssistant hass, Iterable[State] states, *Context|None context=None, dict[str, Any]|None reproduce_options=None)