1 """A class to hold entity values."""
3 from __future__
import annotations
6 from functools
import lru_cache
15 """Class to store entity id based values.
17 This class is expected to only be used infrequently
18 as it caches all entity ids up to MAX_EXPECTED_ENTITY_IDS.
20 The cache includes `self` so it is important to
21 only use this in places where usage of `EntityValues` is immortal.
26 exact: dict[str, dict[str, str]] |
None =
None,
27 domain: dict[str, dict[str, str]] |
None =
None,
28 glob: dict[str, dict[str, str]] |
None =
None,
30 """Initialize an EntityConfigDict."""
35 compiled: dict[re.Pattern[str], Any] |
None =
None
38 re.compile(fnmatch.translate(key)): value
for key, value
in glob.items()
43 @lru_cache(maxsize=MAX_EXPECTED_ENTITY_IDS)
44 def get(self, entity_id: str) -> dict[str, str]:
45 """Get config for an entity id."""
47 result: dict[str, str] = {}
49 if self.
_domain_domain
is not None and domain
in self.
_domain_domain:
50 result.update(self.
_domain_domain[domain])
52 if self.
_glob_glob
is not None:
53 for pattern, values
in self.
_glob_glob.items():
54 if pattern.match(entity_id):
57 if self.
_exact_exact
is not None and entity_id
in self.
_exact_exact:
58 result.update(self.
_exact_exact[entity_id])
dict[str, str] get(self, str entity_id)
None __init__(self, dict[str, dict[str, str]]|None exact=None, dict[str, dict[str, str]]|None domain=None, dict[str, dict[str, str]]|None glob=None)
tuple[str, str] split_entity_id(str entity_id)