From c50a340cbce45be9d16b61c875c3852ceac53ed8 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 7 May 2024 18:18:20 +0200 Subject: [PATCH] Use HassKey for setup and bootstrap (#116998) --- homeassistant/bootstrap.py | 3 ++- homeassistant/config.py | 3 ++- homeassistant/const.py | 3 ++- homeassistant/setup.py | 6 ++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index b9753823008..355cf17eb62 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -101,6 +101,7 @@ from .setup import ( async_setup_component, ) from .util.async_ import create_eager_task +from .util.hass_dict import HassKey from .util.logging import async_activate_log_queue_handler from .util.package import async_get_user_site, is_virtual_env @@ -120,7 +121,7 @@ SETUP_ORDER_SORT_KEY = partial(contains, BASE_PLATFORMS) ERROR_LOG_FILENAME = "home-assistant.log" # hass.data key for logging information. -DATA_REGISTRIES_LOADED = "bootstrap_registries_loaded" +DATA_REGISTRIES_LOADED: HassKey[None] = HassKey("bootstrap_registries_loaded") LOG_SLOW_STARTUP_INTERVAL = 60 SLOW_STARTUP_CHECK_INTERVAL = 1 diff --git a/homeassistant/config.py b/homeassistant/config.py index 96a8d2d8555..6a090c812b5 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -69,6 +69,7 @@ from .helpers.typing import ConfigType from .loader import ComponentProtocol, Integration, IntegrationNotFound from .requirements import RequirementsNotFound, async_get_integration_with_requirements from .util.async_ import create_eager_task +from .util.hass_dict import HassKey from .util.package import is_docker_env from .util.unit_system import get_unit_system, validate_unit_system from .util.yaml import SECRET_YAML, Secrets, YamlTypeError, load_yaml_dict @@ -81,7 +82,7 @@ RE_ASCII = re.compile(r"\033\[[^m]*m") YAML_CONFIG_FILE = "configuration.yaml" VERSION_FILE = ".HA_VERSION" CONFIG_DIR_NAME = ".homeassistant" -DATA_CUSTOMIZE = "hass_customize" +DATA_CUSTOMIZE: HassKey[EntityValues] = HassKey("hass_customize") AUTOMATION_CONFIG_PATH = "automations.yaml" SCRIPT_CONFIG_PATH = "scripts.yaml" diff --git a/homeassistant/const.py b/homeassistant/const.py index 45ff6ecf976..66b4b3e4dcf 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -14,6 +14,7 @@ from .helpers.deprecation import ( dir_with_deprecated_constants, ) from .util.event_type import EventType +from .util.hass_dict import HassKey from .util.signal_type import SignalType if TYPE_CHECKING: @@ -1625,7 +1626,7 @@ SIGNAL_BOOTSTRAP_INTEGRATIONS: SignalType[dict[str, float]] = SignalType( # hass.data key for logging information. -KEY_DATA_LOGGING = "logging" +KEY_DATA_LOGGING: HassKey[str] = HassKey("logging") # Date/Time formats diff --git a/homeassistant/setup.py b/homeassistant/setup.py index 802902e8dec..e5d28a2676b 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -73,9 +73,11 @@ DATA_SETUP_TIME: HassKey[ defaultdict[str, defaultdict[str | None, defaultdict[SetupPhases, float]]] ] = HassKey("setup_time") -DATA_DEPS_REQS = "deps_reqs_processed" +DATA_DEPS_REQS: HassKey[set[str]] = HassKey("deps_reqs_processed") -DATA_PERSISTENT_ERRORS = "bootstrap_persistent_errors" +DATA_PERSISTENT_ERRORS: HassKey[dict[str, str | None]] = HassKey( + "bootstrap_persistent_errors" +) NOTIFY_FOR_TRANSLATION_KEYS = [ "config_validation_err",