Change light white service call attribute to accept True (#89803)
This commit is contained in:
parent
a153720599
commit
ae127e7687
3 changed files with 43 additions and 8 deletions
|
@ -276,7 +276,7 @@ LIGHT_TURN_ON_SCHEMA = {
|
||||||
vol.Exclusive(ATTR_XY_COLOR, COLOR_GROUP): vol.All(
|
vol.Exclusive(ATTR_XY_COLOR, COLOR_GROUP): vol.All(
|
||||||
vol.Coerce(tuple), vol.ExactSequence((cv.small_float, cv.small_float))
|
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_FLASH: VALID_FLASH,
|
||||||
ATTR_EFFECT: cv.string,
|
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:
|
elif ColorMode.XY in supported_color_modes:
|
||||||
params[ATTR_XY_COLOR] = color_util.color_RGB_to_xy(*rgb_color)
|
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 both white and brightness are specified, override white
|
||||||
if (
|
if (
|
||||||
supported_color_modes
|
supported_color_modes
|
||||||
|
|
|
@ -370,19 +370,16 @@ turn_on:
|
||||||
unit_of_measurement: "%"
|
unit_of_measurement: "%"
|
||||||
white:
|
white:
|
||||||
name: White
|
name: White
|
||||||
description:
|
description: Set the light to white mode.
|
||||||
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.
|
|
||||||
filter:
|
filter:
|
||||||
attribute:
|
attribute:
|
||||||
supported_color_modes:
|
supported_color_modes:
|
||||||
- light.ColorMode.WHITE
|
- light.ColorMode.WHITE
|
||||||
advanced: true
|
advanced: true
|
||||||
selector:
|
selector:
|
||||||
number:
|
constant:
|
||||||
min: 0
|
value: true
|
||||||
max: 255
|
label: Enabled
|
||||||
profile:
|
profile:
|
||||||
name: Profile
|
name: Profile
|
||||||
description: Name of a light profile to use.
|
description: Name of a light profile to use.
|
||||||
|
@ -749,6 +746,18 @@ toggle:
|
||||||
min: 0
|
min: 0
|
||||||
max: 100
|
max: 100
|
||||||
unit_of_measurement: "%"
|
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:
|
profile:
|
||||||
name: Profile
|
name: Profile
|
||||||
description: Name of a light profile to use.
|
description: Name of a light profile to use.
|
||||||
|
|
|
@ -2159,6 +2159,26 @@ async def test_light_service_call_white_mode(
|
||||||
_, data = entity0.last_call("turn_off")
|
_, data = entity0.last_call("turn_off")
|
||||||
assert data == {}
|
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(
|
async def test_light_state_color_conversion(
|
||||||
hass: HomeAssistant, enable_custom_integrations: None
|
hass: HomeAssistant, enable_custom_integrations: None
|
||||||
|
|
Loading…
Add table
Reference in a new issue