Mark backgrounds optional for tplink random effects (#69622)

This commit is contained in:
J. Nick Koston 2022-04-07 11:19:17 -10:00 committed by GitHub
parent a61ac3ddc6
commit 6dc72ebf6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.Optional("random_seed", default=100): vol.All(
vol.Coerce(int), vol.Range(min=1, max=100) vol.Coerce(int), vol.Range(min=1, max=100)
), ),
vol.Required("backgrounds"): vol.All( vol.Optional("backgrounds"): vol.All(
cv.ensure_list, cv.ensure_list,
vol.Length(min=1, max=16), vol.Length(min=1, max=16),
[vol.All(vol.Coerce(tuple), HSV_SEQUENCE)], [vol.All(vol.Coerce(tuple), HSV_SEQUENCE)],
@ -366,7 +366,7 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb):
fadeoff: int, fadeoff: int,
init_states: tuple[int, int, int], init_states: tuple[int, int, int],
random_seed: 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, hue_range: tuple[int, int] | None = None,
saturation_range: tuple[int, int] | None = None, saturation_range: tuple[int, int] | None = None,
brightness_range: tuple[int, int] | None = None, brightness_range: tuple[int, int] | None = None,
@ -378,8 +378,9 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb):
"type": "random", "type": "random",
"init_states": [init_states], "init_states": [init_states],
"random_seed": random_seed, "random_seed": random_seed,
"backgrounds": backgrounds,
} }
if backgrounds:
effect["backgrounds"] = backgrounds
if fadeoff: if fadeoff:
effect["fadeoff"] = fadeoff effect["fadeoff"] = fadeoff
if hue_range: if hue_range:

View File

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

View File

@ -517,6 +517,33 @@ async def test_smart_strip_custom_random_effect(hass: HomeAssistant) -> None:
) )
strip.set_custom_effect.reset_mock() 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 = { strip.effect = {
"custom": 1, "custom": 1,
"id": "yMwcNpLxijmoKamskHCvvravpbnIqAIN", "id": "yMwcNpLxijmoKamskHCvvravpbnIqAIN",