From 0abde86cf97e7f5d1460f03192edd3edee2e0e01 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:18:57 +0200 Subject: [PATCH] Use HassKey in light (#126333) --- homeassistant/components/light/__init__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 445096ae643..94b27664b99 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -29,14 +29,16 @@ from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.typing import ConfigType, VolDictType from homeassistant.loader import bind_hass import homeassistant.util.color as color_util +from homeassistant.util.hass_dict import HassKey DOMAIN = "light" +DOMAIN_DATA: HassKey[EntityComponent[LightEntity]] = HassKey(DOMAIN) ENTITY_ID_FORMAT = DOMAIN + ".{}" PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE SCAN_INTERVAL = timedelta(seconds=30) -DATA_PROFILES = "light_profiles" +DATA_PROFILES: HassKey[Profiles] = HassKey(f"{DOMAIN}_profiles") class LightEntityFeature(IntFlag): @@ -299,7 +301,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool: def preprocess_turn_on_alternatives( - hass: HomeAssistant, params: dict[str, Any] | VolDictType + hass: HomeAssistant, params: dict[str, Any] ) -> None: """Process extra data for turn light on request. @@ -393,7 +395,7 @@ def filter_turn_on_params(light: LightEntity, params: dict[str, Any]) -> dict[st async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: C901 """Expose light control via state machine and services.""" - component = hass.data[DOMAIN] = EntityComponent[LightEntity]( + component = hass.data[DOMAIN_DATA] = EntityComponent[LightEntity]( _LOGGER, DOMAIN, hass, SCAN_INTERVAL ) await component.async_setup(config) @@ -403,7 +405,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: # of the light base platform. hass.async_create_task(profiles.async_initialize(), eager_start=True) - def preprocess_data(data: VolDictType) -> VolDictType: + def preprocess_data(data: dict[str, Any]) -> VolDictType: """Preprocess the service data.""" base: VolDictType = { entity_field: data.pop(entity_field) @@ -670,14 +672,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up a config entry.""" - component: EntityComponent[LightEntity] = hass.data[DOMAIN] - return await component.async_setup_entry(entry) + return await hass.data[DOMAIN_DATA].async_setup_entry(entry) async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" - component: EntityComponent[LightEntity] = hass.data[DOMAIN] - return await component.async_unload_entry(entry) + return await hass.data[DOMAIN_DATA].async_unload_entry(entry) def _coerce_none(value: str) -> None: