Mark backgrounds optional for tplink random effects (#69622)

pull/69509/head
J. Nick Koston 2022-04-07 11:19:17 -10:00 committed by Paulus Schoutsen
parent 9063428358
commit 3dd0ddb73e
3 changed files with 32 additions and 4 deletions

View File

@ -103,7 +103,7 @@ RANDOM_EFFECT_DICT: Final = {
vol.Optional("random_seed", default=100): vol.All(
vol.Coerce(int), vol.Range(min=1, max=100)
),
vol.Required("backgrounds"): vol.All(
vol.Optional("backgrounds"): vol.All(
cv.ensure_list,
vol.Length(min=1, max=16),
[vol.All(vol.Coerce(tuple), HSV_SEQUENCE)],
@ -366,7 +366,7 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb):
fadeoff: int,
init_states: tuple[int, int, int],
random_seed: int,
backgrounds: Sequence[tuple[int, int, int]],
backgrounds: Sequence[tuple[int, int, int]] | None = None,
hue_range: tuple[int, int] | None = None,
saturation_range: tuple[int, int] | None = None,
brightness_range: tuple[int, int] | None = None,
@ -378,8 +378,9 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb):
"type": "random",
"init_states": [init_states],
"random_seed": random_seed,
"backgrounds": backgrounds,
}
if backgrounds:
effect["backgrounds"] = backgrounds
if fadeoff:
effect["fadeoff"] = fadeoff
if hue_range:

View File

@ -93,7 +93,7 @@ random_effect:
- [199, 89, 50]
- [160, 50, 50]
- [180, 100, 50]
required: true
required: false
selector:
object:
segments:

View File

@ -517,6 +517,33 @@ async def test_smart_strip_custom_random_effect(hass: HomeAssistant) -> None:
)
strip.set_custom_effect.reset_mock()
await hass.services.async_call(
DOMAIN,
"random_effect",
{
ATTR_ENTITY_ID: entity_id,
"init_states": [340, 20, 50],
},
blocking=True,
)
strip.set_custom_effect.assert_called_once_with(
{
"custom": 1,
"id": "yMwcNpLxijmoKamskHCvvravpbnIqAIN",
"brightness": 100,
"name": "Custom",
"segments": [0],
"expansion_strategy": 1,
"enable": 1,
"duration": 0,
"transition": 0,
"type": "random",
"init_states": [[340, 20, 50]],
"random_seed": 100,
}
)
strip.set_custom_effect.reset_mock()
strip.effect = {
"custom": 1,
"id": "yMwcNpLxijmoKamskHCvvravpbnIqAIN",