Improve light typing (#78641)
parent
35221e9a61
commit
bbf54e6f44
|
@ -444,6 +444,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
||||||
# If a color is specified, convert to the color space supported by the light
|
# If a color is specified, convert to the color space supported by the light
|
||||||
# Backwards compatibility: Fall back to hs color if light.supported_color_modes
|
# Backwards compatibility: Fall back to hs color if light.supported_color_modes
|
||||||
# is not implemented
|
# is not implemented
|
||||||
|
rgb_color: tuple[int, int, int] | None
|
||||||
|
rgbww_color: tuple[int, int, int, int, int] | None
|
||||||
if not supported_color_modes:
|
if not supported_color_modes:
|
||||||
if (rgb_color := params.pop(ATTR_RGB_COLOR, None)) is not None:
|
if (rgb_color := params.pop(ATTR_RGB_COLOR, None)) is not None:
|
||||||
params[ATTR_HS_COLOR] = color_util.color_RGB_to_hs(*rgb_color)
|
params[ATTR_HS_COLOR] = color_util.color_RGB_to_hs(*rgb_color)
|
||||||
|
@ -453,6 +455,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
||||||
rgb_color = color_util.color_rgbw_to_rgb(*rgbw_color)
|
rgb_color = color_util.color_rgbw_to_rgb(*rgbw_color)
|
||||||
params[ATTR_HS_COLOR] = color_util.color_RGB_to_hs(*rgb_color)
|
params[ATTR_HS_COLOR] = color_util.color_RGB_to_hs(*rgb_color)
|
||||||
elif (rgbww_color := params.pop(ATTR_RGBWW_COLOR, None)) is not None:
|
elif (rgbww_color := params.pop(ATTR_RGBWW_COLOR, None)) is not None:
|
||||||
|
# https://github.com/python/mypy/issues/13673
|
||||||
rgb_color = color_util.color_rgbww_to_rgb( # type: ignore[call-arg]
|
rgb_color = color_util.color_rgbww_to_rgb( # type: ignore[call-arg]
|
||||||
*rgbww_color, light.min_mireds, light.max_mireds
|
*rgbww_color, light.min_mireds, light.max_mireds
|
||||||
)
|
)
|
||||||
|
@ -466,16 +469,17 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
||||||
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
|
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
|
||||||
elif ColorMode.RGBWW in supported_color_modes:
|
elif ColorMode.RGBWW in supported_color_modes:
|
||||||
rgb_color = color_util.color_hs_to_RGB(*hs_color)
|
rgb_color = color_util.color_hs_to_RGB(*hs_color)
|
||||||
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww( # type: ignore[call-arg]
|
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww(
|
||||||
*rgb_color, light.min_mireds, light.max_mireds
|
*rgb_color, light.min_mireds, light.max_mireds
|
||||||
)
|
)
|
||||||
elif ColorMode.XY in supported_color_modes:
|
elif ColorMode.XY in supported_color_modes:
|
||||||
params[ATTR_XY_COLOR] = color_util.color_hs_to_xy(*hs_color)
|
params[ATTR_XY_COLOR] = color_util.color_hs_to_xy(*hs_color)
|
||||||
elif ATTR_RGB_COLOR in params and ColorMode.RGB not in supported_color_modes:
|
elif ATTR_RGB_COLOR in params and ColorMode.RGB not in supported_color_modes:
|
||||||
rgb_color = params.pop(ATTR_RGB_COLOR)
|
assert (rgb_color := params.pop(ATTR_RGB_COLOR)) is not None
|
||||||
if ColorMode.RGBW in supported_color_modes:
|
if ColorMode.RGBW in supported_color_modes:
|
||||||
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
|
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
|
||||||
elif ColorMode.RGBWW in supported_color_modes:
|
elif ColorMode.RGBWW in supported_color_modes:
|
||||||
|
# https://github.com/python/mypy/issues/13673
|
||||||
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww( # type: ignore[call-arg]
|
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww( # type: ignore[call-arg]
|
||||||
*rgb_color, light.min_mireds, light.max_mireds
|
*rgb_color, light.min_mireds, light.max_mireds
|
||||||
)
|
)
|
||||||
|
@ -494,7 +498,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
||||||
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
|
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
|
||||||
elif ColorMode.RGBWW in supported_color_modes:
|
elif ColorMode.RGBWW in supported_color_modes:
|
||||||
rgb_color = color_util.color_xy_to_RGB(*xy_color)
|
rgb_color = color_util.color_xy_to_RGB(*xy_color)
|
||||||
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww( # type: ignore[call-arg]
|
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww(
|
||||||
*rgb_color, light.min_mireds, light.max_mireds
|
*rgb_color, light.min_mireds, light.max_mireds
|
||||||
)
|
)
|
||||||
elif ATTR_RGBW_COLOR in params and ColorMode.RGBW not in supported_color_modes:
|
elif ATTR_RGBW_COLOR in params and ColorMode.RGBW not in supported_color_modes:
|
||||||
|
@ -503,7 +507,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
||||||
if ColorMode.RGB in supported_color_modes:
|
if ColorMode.RGB in supported_color_modes:
|
||||||
params[ATTR_RGB_COLOR] = rgb_color
|
params[ATTR_RGB_COLOR] = rgb_color
|
||||||
elif ColorMode.RGBWW in supported_color_modes:
|
elif ColorMode.RGBWW in supported_color_modes:
|
||||||
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww( # type: ignore[call-arg]
|
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww(
|
||||||
*rgb_color, light.min_mireds, light.max_mireds
|
*rgb_color, light.min_mireds, light.max_mireds
|
||||||
)
|
)
|
||||||
elif ColorMode.HS in supported_color_modes:
|
elif ColorMode.HS in supported_color_modes:
|
||||||
|
@ -513,7 +517,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
||||||
elif (
|
elif (
|
||||||
ATTR_RGBWW_COLOR in params and ColorMode.RGBWW not in supported_color_modes
|
ATTR_RGBWW_COLOR in params and ColorMode.RGBWW not in supported_color_modes
|
||||||
):
|
):
|
||||||
rgbww_color = params.pop(ATTR_RGBWW_COLOR)
|
assert (rgbww_color := params.pop(ATTR_RGBWW_COLOR)) is not None
|
||||||
|
# https://github.com/python/mypy/issues/13673
|
||||||
rgb_color = color_util.color_rgbww_to_rgb( # type: ignore[call-arg]
|
rgb_color = color_util.color_rgbww_to_rgb( # type: ignore[call-arg]
|
||||||
*rgbww_color, light.min_mireds, light.max_mireds
|
*rgbww_color, light.min_mireds, light.max_mireds
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue