Skip to content

Commit

Permalink
Align max expected entities constant between modules (home-assistant#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored May 28, 2024
1 parent 722feb2 commit 33ff844
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,12 @@ class EntityCategory(StrEnum):
FORMAT_TIME: Final = "%H:%M:%S"
FORMAT_DATETIME: Final = f"{FORMAT_DATE} {FORMAT_TIME}"


# Maximum entities expected in the state machine
# This is not a hard limit, but caches and other
# data structures will be pre-allocated to this size
MAX_EXPECTED_ENTITY_IDS: Final = 16384

# These can be removed if no deprecated constant are in this module anymore
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
__dir__ = partial(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
EVENT_STATE_CHANGED,
EVENT_STATE_REPORTED,
MATCH_ALL,
MAX_EXPECTED_ENTITY_IDS,
MAX_LENGTH_EVENT_EVENT_TYPE,
MAX_LENGTH_STATE_STATE,
UnitOfLength,
Expand Down Expand Up @@ -177,7 +178,6 @@ class EventStateChangedData(TypedDict):
# How long to wait until things that run on startup have to finish.
TIMEOUT_EVENT_START = 15

MAX_EXPECTED_ENTITY_IDS = 16384

EVENTS_EXCLUDED_FROM_MATCH_ALL = {
EVENT_HOMEASSISTANT_CLOSE,
Expand Down
7 changes: 3 additions & 4 deletions homeassistant/helpers/entity_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
import re
from typing import Any

from homeassistant.const import MAX_EXPECTED_ENTITY_IDS
from homeassistant.core import split_entity_id

_MAX_EXPECTED_ENTITIES = 16384


class EntityValues:
"""Class to store entity id based values.
This class is expected to only be used infrequently
as it caches all entity ids up to _MAX_EXPECTED_ENTITIES.
as it caches all entity ids up to MAX_EXPECTED_ENTITY_IDS.
The cache includes `self` so it is important to
only use this in places where usage of `EntityValues` is immortal.
Expand All @@ -41,7 +40,7 @@ def __init__(

self._glob = compiled

@lru_cache(maxsize=_MAX_EXPECTED_ENTITIES)
@lru_cache(maxsize=MAX_EXPECTED_ENTITY_IDS)
def get(self, entity_id: str) -> dict[str, str]:
"""Get config for an entity id."""
domain, _ = split_entity_id(entity_id)
Expand Down

0 comments on commit 33ff844

Please sign in to comment.