1 """Helpers that help with state related things."""
3 from __future__
import annotations
6 from collections
import defaultdict
7 from collections.abc
import Iterable
9 from types
import ModuleType
10 from typing
import Any
26 _LOGGER = logging.getLogger(__name__)
32 states: State | Iterable[State],
34 context: Context |
None =
None,
35 reproduce_options: dict[str, Any] |
None =
None,
37 """Reproduce a list of states on multiple domains."""
38 if isinstance(states, State):
41 to_call: dict[str, list[State]] = defaultdict(list)
44 to_call[state.domain].append(state)
46 async
def worker(domain: str, states_by_domain: list[State]) ->
None:
49 except IntegrationNotFound:
51 "Trying to reproduce state for unknown integration: %s", domain
56 platform: ModuleType = await integration.async_get_platform(
60 _LOGGER.warning(
"Integration %s does not support reproduce state", domain)
63 await platform.async_reproduce_states(
64 hass, states_by_domain, context=context, reproduce_options=reproduce_options
70 *(worker(domain, data)
for domain, data
in to_call.items())
75 """Try to coerce our state to a number.
77 Raises ValueError if this is not possible.
97 return float(state.state)
None async_reproduce_state(HomeAssistant hass, State|Iterable[State] states, *Context|None context=None, dict[str, Any]|None reproduce_options=None)
float state_as_number(State state)
Integration async_get_integration(HomeAssistant hass, str domain)