Use HassKey in light (#126333)

pull/125763/head
epenet 2024-09-22 14:18:57 +02:00 committed by GitHub
parent f073e45575
commit 0abde86cf9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 8 deletions

View File

@ -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: