Use HassKey in light (#126333)
parent
f073e45575
commit
0abde86cf9
|
@ -29,14 +29,16 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
|
from homeassistant.util.hass_dict import HassKey
|
||||||
|
|
||||||
DOMAIN = "light"
|
DOMAIN = "light"
|
||||||
|
DOMAIN_DATA: HassKey[EntityComponent[LightEntity]] = HassKey(DOMAIN)
|
||||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||||
SCAN_INTERVAL = timedelta(seconds=30)
|
SCAN_INTERVAL = timedelta(seconds=30)
|
||||||
|
|
||||||
DATA_PROFILES = "light_profiles"
|
DATA_PROFILES: HassKey[Profiles] = HassKey(f"{DOMAIN}_profiles")
|
||||||
|
|
||||||
|
|
||||||
class LightEntityFeature(IntFlag):
|
class LightEntityFeature(IntFlag):
|
||||||
|
@ -299,7 +301,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def preprocess_turn_on_alternatives(
|
def preprocess_turn_on_alternatives(
|
||||||
hass: HomeAssistant, params: dict[str, Any] | VolDictType
|
hass: HomeAssistant, params: dict[str, Any]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Process extra data for turn light on request.
|
"""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
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: C901
|
||||||
"""Expose light control via state machine and services."""
|
"""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
|
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||||
)
|
)
|
||||||
await component.async_setup(config)
|
await component.async_setup(config)
|
||||||
|
@ -403,7 +405,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
||||||
# of the light base platform.
|
# of the light base platform.
|
||||||
hass.async_create_task(profiles.async_initialize(), eager_start=True)
|
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."""
|
"""Preprocess the service data."""
|
||||||
base: VolDictType = {
|
base: VolDictType = {
|
||||||
entity_field: data.pop(entity_field)
|
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:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up a config entry."""
|
"""Set up a config entry."""
|
||||||
component: EntityComponent[LightEntity] = hass.data[DOMAIN]
|
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||||
return await component.async_setup_entry(entry)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
component: EntityComponent[LightEntity] = hass.data[DOMAIN]
|
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||||
return await component.async_unload_entry(entry)
|
|
||||||
|
|
||||||
|
|
||||||
def _coerce_none(value: str) -> None:
|
def _coerce_none(value: str) -> None:
|
||||||
|
|
Loading…
Reference in New Issue