diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 9d15d004220..dfe2e6909b4 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -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: diff --git a/tests/components/light/test_init.py b/tests/components/light/test_init.py index 1c1475edf98..3a8efa5fd97 100644 --- a/tests/components/light/test_init.py +++ b/tests/components/light/test_init.py @@ -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,