Enable disallow-any-generics in light (#78499)
This commit is contained in:
parent
a443cefa7b
commit
de7e12eeaf
1 changed files with 10 additions and 6 deletions
|
@ -112,6 +112,8 @@ COLOR_MODES_COLOR = {
|
||||||
ColorMode.XY,
|
ColorMode.XY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# mypy: disallow-any-generics
|
||||||
|
|
||||||
|
|
||||||
def filter_supported_color_modes(color_modes: Iterable[ColorMode]) -> set[ColorMode]:
|
def filter_supported_color_modes(color_modes: Iterable[ColorMode]) -> set[ColorMode]:
|
||||||
"""Filter the given color modes."""
|
"""Filter the given color modes."""
|
||||||
|
@ -167,7 +169,7 @@ def color_temp_supported(color_modes: Iterable[ColorMode | str] | None) -> bool:
|
||||||
return ColorMode.COLOR_TEMP in color_modes
|
return ColorMode.COLOR_TEMP in color_modes
|
||||||
|
|
||||||
|
|
||||||
def get_supported_color_modes(hass: HomeAssistant, entity_id: str) -> set | None:
|
def get_supported_color_modes(hass: HomeAssistant, entity_id: str) -> set[str] | None:
|
||||||
"""Get supported color modes for a light entity.
|
"""Get supported color modes for a light entity.
|
||||||
|
|
||||||
First try the statemachine, then entity registry.
|
First try the statemachine, then entity registry.
|
||||||
|
@ -366,7 +368,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(
|
component = hass.data[DOMAIN] = EntityComponent[LightEntity](
|
||||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||||
)
|
)
|
||||||
await component.async_setup(config)
|
await component.async_setup(config)
|
||||||
|
@ -583,13 +585,13 @@ 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 = cast(EntityComponent, hass.data[DOMAIN])
|
component: EntityComponent[LightEntity] = hass.data[DOMAIN]
|
||||||
return await component.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 = cast(EntityComponent, hass.data[DOMAIN])
|
component: EntityComponent[LightEntity] = hass.data[DOMAIN]
|
||||||
return await component.async_unload_entry(entry)
|
return await component.async_unload_entry(entry)
|
||||||
|
|
||||||
|
|
||||||
|
@ -868,8 +870,10 @@ class LightEntity(ToggleEntity):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _light_internal_convert_color(self, color_mode: ColorMode | str) -> dict:
|
def _light_internal_convert_color(
|
||||||
data: dict[str, tuple] = {}
|
self, color_mode: ColorMode | str
|
||||||
|
) -> dict[str, tuple[float, ...]]:
|
||||||
|
data: dict[str, tuple[float, ...]] = {}
|
||||||
if color_mode == ColorMode.HS and self.hs_color:
|
if color_mode == ColorMode.HS and self.hs_color:
|
||||||
hs_color = self.hs_color
|
hs_color = self.hs_color
|
||||||
data[ATTR_HS_COLOR] = (round(hs_color[0], 3), round(hs_color[1], 3))
|
data[ATTR_HS_COLOR] = (round(hs_color[0], 3), round(hs_color[1], 3))
|
||||||
|
|
Loading…
Add table
Reference in a new issue