Only apply color from light profile if no color specified (#70640)

This commit is contained in:
Erik Montnemery 2022-04-25 16:56:07 +02:00 committed by GitHub
parent 9b9b553521
commit 28ba572d9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 120 additions and 5 deletions

View File

@ -706,8 +706,21 @@ class Profiles:
if (profile := self.data.get(name)) is None:
return
if profile.hs_color is not None:
params.setdefault(ATTR_HS_COLOR, profile.hs_color)
color_attributes = (
ATTR_COLOR_NAME,
ATTR_COLOR_TEMP,
ATTR_HS_COLOR,
ATTR_RGB_COLOR,
ATTR_RGBW_COLOR,
ATTR_RGBWW_COLOR,
ATTR_XY_COLOR,
ATTR_WHITE,
)
if profile.hs_color is not None and not any(
color_attribute in params for color_attribute in color_attributes
):
params[ATTR_HS_COLOR] = profile.hs_color
if profile.brightness is not None:
params.setdefault(ATTR_BRIGHTNESS, profile.brightness)
if profile.transition is not None:

View File

@ -595,6 +595,7 @@ async def test_default_profiles_group(
"extra_call_params, expected_params_state_was_off, expected_params_state_was_on",
(
(
# No turn on params, should apply profile
{},
{
light.ATTR_HS_COLOR: (50.353, 100),
@ -608,6 +609,7 @@ async def test_default_profiles_group(
},
),
(
# Brightness in turn on params, brightness from profile ignored
{light.ATTR_BRIGHTNESS: 22},
{
light.ATTR_HS_COLOR: (50.353, 100),
@ -620,6 +622,7 @@ async def test_default_profiles_group(
},
),
(
# Transition in turn on params, transition from profile ignored
{light.ATTR_TRANSITION: 22},
{
light.ATTR_HS_COLOR: (50.353, 100),
@ -631,23 +634,115 @@ async def test_default_profiles_group(
},
),
(
# Color temp in turn on params, color from profile ignored
{
light.ATTR_COLOR_TEMP: 600,
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_COLOR_TEMP: 600,
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_COLOR_TEMP: 600,
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
),
(
# HS-color in turn on params, color from profile ignored
{
light.ATTR_HS_COLOR: [70, 80],
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_HS_COLOR: (70, 80),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_HS_COLOR: (70, 80),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
),
(
# RGB-color in turn on params, color from profile ignored
{
light.ATTR_RGB_COLOR: [1, 2, 3],
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_RGB_COLOR: (1, 2, 3),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_RGB_COLOR: (1, 2, 3),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
),
(
# RGBW-color in turn on params, color from profile ignored
{
light.ATTR_RGBW_COLOR: [1, 2, 3, 4],
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_RGBW_COLOR: (1, 2, 3, 4),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_RGBW_COLOR: (1, 2, 3, 4),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
),
(
# RGBWW-color in turn on params, color from profile ignored
{
light.ATTR_RGBWW_COLOR: [1, 2, 3, 4, 5],
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_RGBWW_COLOR: (1, 2, 3, 4, 5),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_RGBWW_COLOR: (1, 2, 3, 4, 5),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
),
(
# XY-color in turn on params, color from profile ignored
{
light.ATTR_XY_COLOR: [0.4448, 0.4066],
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_HS_COLOR: (38.88, 49.02),
light.ATTR_XY_COLOR: (0.4448, 0.4066),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_HS_COLOR: (38.88, 49.02),
light.ATTR_XY_COLOR: (0.4448, 0.4066),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
),
(
# Brightness + transition in turn on params
{light.ATTR_BRIGHTNESS: 11, light.ATTR_TRANSITION: 1},
{
light.ATTR_HS_COLOR: (50.353, 100),
@ -684,7 +779,14 @@ async def test_default_profiles_light(
mock_light_profiles[profile.name] = profile
dev = next(filter(lambda x: x.entity_id == "light.ceiling_2", platform.ENTITIES))
dev.supported_color_modes = [light.ColorMode.HS]
dev.supported_color_modes = {
light.ColorMode.COLOR_TEMP,
light.ColorMode.HS,
light.ColorMode.RGB,
light.ColorMode.RGBW,
light.ColorMode.RGBWW,
light.ColorMode.XY,
}
dev.supported_features = light.LightEntityFeature.TRANSITION
await hass.services.async_call(
light.DOMAIN,