Home Assistant Unofficial Reference 2024.12.1
objects.py
Go to the documentation of this file.
1 """Custom yaml object types."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 from typing import Any
7 
8 import voluptuous as vol
9 from voluptuous.schema_builder import _compile_scalar
10 import yaml
11 
12 
14  """Wrapper class to be able to add attributes on a list."""
15 
16  __slots__ = ("__config_file__", "__line__")
17 
18  __config_file__: str
19  __line__: int | str
20 
21 
23  """Wrapper class to be able to add attributes on a string."""
24 
25  __slots__ = ("__config_file__", "__line__")
26 
27  __config_file__: str
28  __line__: int | str
29 
30  def __voluptuous_compile__(self, schema: vol.Schema) -> Any:
31  """Needed because vol.Schema.compile does not handle str subclasses."""
32  return _compile_scalar(self) # type: ignore[no-untyped-call]
33 
34 
36  """Wrapper class to be able to add attributes on a dict."""
37 
38  __slots__ = ("__config_file__", "__line__")
39 
40  __config_file__: str
41  __line__: int | str
42 
43 
44 @dataclass(slots=True, frozen=True)
45 class Input:
46  """Input that should be substituted."""
47 
48  name: str
49 
50  @classmethod
51  def from_node(cls, loader: yaml.Loader, node: yaml.nodes.Node) -> Input:
52  """Create a new placeholder from a node."""
53  return cls(node.value)
Input from_node(cls, yaml.Loader loader, yaml.nodes.Node node)
Definition: objects.py:51
Any __voluptuous_compile__(self, vol.Schema schema)
Definition: objects.py:30