diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index d8543946df7..2af959d22fe 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -276,7 +276,7 @@ LIGHT_TURN_ON_SCHEMA = { vol.Exclusive(ATTR_XY_COLOR, COLOR_GROUP): vol.All( vol.Coerce(tuple), vol.ExactSequence((cv.small_float, cv.small_float)) ), - vol.Exclusive(ATTR_WHITE, COLOR_GROUP): VALID_BRIGHTNESS, + vol.Exclusive(ATTR_WHITE, COLOR_GROUP): vol.Any(True, VALID_BRIGHTNESS), ATTR_FLASH: VALID_FLASH, ATTR_EFFECT: cv.string, } @@ -557,6 +557,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: elif ColorMode.XY in supported_color_modes: params[ATTR_XY_COLOR] = color_util.color_RGB_to_xy(*rgb_color) + # If white is set to True, set it to the light's brightness + # Add a warning in Home Assistant Core 2023.5 if the brightness is set to an + # integer. + if params.get(ATTR_WHITE) is True: + params[ATTR_WHITE] = light.brightness + # If both white and brightness are specified, override white if ( supported_color_modes diff --git a/homeassistant/components/light/services.yaml b/homeassistant/components/light/services.yaml index 65bf77f15c7..d1221dd1210 100644 --- a/homeassistant/components/light/services.yaml +++ b/homeassistant/components/light/services.yaml @@ -370,19 +370,16 @@ turn_on: unit_of_measurement: "%" white: name: White - description: - Set the light to white mode and change its brightness, where 0 turns - the light off, 1 is the minimum brightness and 255 is the maximum - brightness supported by the light. + description: Set the light to white mode. filter: attribute: supported_color_modes: - light.ColorMode.WHITE advanced: true selector: - number: - min: 0 - max: 255 + constant: + value: true + label: Enabled profile: name: Profile description: Name of a light profile to use. @@ -749,6 +746,18 @@ toggle: min: 0 max: 100 unit_of_measurement: "%" + white: + name: White + description: Set the light to white mode. + filter: + attribute: + supported_color_modes: + - light.ColorMode.WHITE + advanced: true + selector: + constant: + value: true + label: Enabled profile: name: Profile description: Name of a light profile to use. diff --git a/tests/components/light/test_init.py b/tests/components/light/test_init.py index 347dfb82bb8..4b4c027541e 100644 --- a/tests/components/light/test_init.py +++ b/tests/components/light/test_init.py @@ -2159,6 +2159,26 @@ async def test_light_service_call_white_mode( _, data = entity0.last_call("turn_off") assert data == {} + entity0.calls = [] + await hass.services.async_call( + "light", + "turn_on", + {"entity_id": [entity0.entity_id], "white": True}, + blocking=True, + ) + _, data = entity0.last_call("turn_on") + assert data == {"white": 100} + + entity0.calls = [] + await hass.services.async_call( + "light", + "turn_on", + {"entity_id": [entity0.entity_id], "brightness_pct": 50, "white": True}, + blocking=True, + ) + _, data = entity0.last_call("turn_on") + assert data == {"white": 128} + async def test_light_state_color_conversion( hass: HomeAssistant, enable_custom_integrations: None