diff --git a/homeassistant/components/tplink/light.py b/homeassistant/components/tplink/light.py index 9a67f8daf4b..32af7cf47be 100644 --- a/homeassistant/components/tplink/light.py +++ b/homeassistant/components/tplink/light.py @@ -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: diff --git a/homeassistant/components/tplink/services.yaml b/homeassistant/components/tplink/services.yaml index 26e002e0e30..6f2d9054b1e 100644 --- a/homeassistant/components/tplink/services.yaml +++ b/homeassistant/components/tplink/services.yaml @@ -93,7 +93,7 @@ random_effect: - [199, 89, 50] - [160, 50, 50] - [180, 100, 50] - required: true + required: false selector: object: segments: diff --git a/tests/components/tplink/test_light.py b/tests/components/tplink/test_light.py index 9975aa1c660..c56bb6399fb 100644 --- a/tests/components/tplink/test_light.py +++ b/tests/components/tplink/test_light.py @@ -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",