1 """Script variables."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
10 from .
import template
14 """Class to hold and render script variables."""
16 def __init__(self, variables: dict[str, Any]) ->
None:
17 """Initialize script variables."""
25 run_variables: Mapping[str, Any] |
None,
27 render_as_defaults: bool =
True,
28 limited: bool =
False,
30 """Render script variables.
32 The run variables are used to compute the static variables.
34 If `render_as_defaults` is True, the run variables will not be overridden.
41 if render_as_defaults:
44 if run_variables
is not None:
45 rendered_variables.update(run_variables)
47 rendered_variables = (
48 {}
if run_variables
is None else dict(run_variables)
50 rendered_variables.update(self.
variablesvariables)
52 return rendered_variables
54 rendered_variables = {}
if run_variables
is None else dict(run_variables)
56 for key, value
in self.
variablesvariables.items():
59 if render_as_defaults
and key
in rendered_variables:
62 rendered_variables[key] = template.render_complex(
63 value, rendered_variables, limited
66 return rendered_variables
69 """Return dict version of this class."""
dict[str, Any] as_dict(self)
dict[str, Any] async_render(self, HomeAssistant hass, Mapping[str, Any]|None run_variables, *bool render_as_defaults=True, bool limited=False)
None __init__(self, dict[str, Any] variables)