Refactor esphome platform setup to reduce boilerplate (#120415)
This commit is contained in:
parent
49e6316c42
commit
4feca36ca6
17 changed files with 170 additions and 327 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from functools import lru_cache
|
||||
from functools import lru_cache, partial
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
from aioesphomeapi import (
|
||||
|
@ -29,8 +29,7 @@ from homeassistant.components.light import (
|
|||
LightEntity,
|
||||
LightEntityFeature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.core import callback
|
||||
|
||||
from .entity import (
|
||||
EsphomeEntity,
|
||||
|
@ -38,27 +37,10 @@ from .entity import (
|
|||
esphome_state_property,
|
||||
platform_async_setup_entry,
|
||||
)
|
||||
from .entry_data import ESPHomeConfigEntry
|
||||
|
||||
FLASH_LENGTHS = {FLASH_SHORT: 2, FLASH_LONG: 10}
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ESPHomeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up ESPHome lights based on a config entry."""
|
||||
await platform_async_setup_entry(
|
||||
hass,
|
||||
entry,
|
||||
async_add_entities,
|
||||
info_type=LightInfo,
|
||||
entity_type=EsphomeLight,
|
||||
state_type=LightState,
|
||||
)
|
||||
|
||||
|
||||
_COLOR_MODE_MAPPING = {
|
||||
ColorMode.ONOFF: [
|
||||
LightColorCapability.ON_OFF,
|
||||
|
@ -437,3 +419,11 @@ class EsphomeLight(EsphomeEntity[LightInfo, LightState], LightEntity):
|
|||
if ColorMode.COLOR_TEMP in supported:
|
||||
self._attr_min_color_temp_kelvin = _mired_to_kelvin(static_info.max_mireds)
|
||||
self._attr_max_color_temp_kelvin = _mired_to_kelvin(static_info.min_mireds)
|
||||
|
||||
|
||||
async_setup_entry = partial(
|
||||
platform_async_setup_entry,
|
||||
info_type=LightInfo,
|
||||
entity_type=EsphomeLight,
|
||||
state_type=LightState,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue