Change light white service call attribute to accept True (#89803)

pull/89839/head^2
Erik Montnemery 2023-03-17 04:02:56 +01:00 committed by GitHub
parent a153720599
commit ae127e7687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 8 deletions

View File

@ -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

View File

@ -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.

View File

@ -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