2022-03-21 21:10:12 +00:00
|
|
|
import pytest
|
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
from kasa import DeviceType
|
|
|
|
from kasa.iot import IotLightStrip
|
2021-09-24 20:26:21 +00:00
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
from .conftest import lightstrip_iot
|
2021-09-24 20:26:21 +00:00
|
|
|
|
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
@lightstrip_iot
|
2024-02-04 15:20:08 +00:00
|
|
|
async def test_lightstrip_length(dev: IotLightStrip):
|
2021-09-24 20:26:21 +00:00
|
|
|
assert dev.is_light_strip
|
|
|
|
assert dev.device_type == DeviceType.LightStrip
|
|
|
|
assert dev.length == dev.sys_info["length"]
|
|
|
|
|
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
@lightstrip_iot
|
2024-02-04 15:20:08 +00:00
|
|
|
async def test_lightstrip_effect(dev: IotLightStrip):
|
2021-09-24 20:26:21 +00:00
|
|
|
assert isinstance(dev.effect, dict)
|
|
|
|
for k in ["brightness", "custom", "enable", "id", "name"]:
|
|
|
|
assert k in dev.effect
|
2022-03-21 21:10:12 +00:00
|
|
|
|
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
@lightstrip_iot
|
2024-02-04 15:20:08 +00:00
|
|
|
async def test_effects_lightstrip_set_effect(dev: IotLightStrip):
|
2024-05-10 18:29:28 +00:00
|
|
|
with pytest.raises(ValueError):
|
2022-03-21 21:10:12 +00:00
|
|
|
await dev.set_effect("Not real")
|
|
|
|
|
|
|
|
await dev.set_effect("Candy Cane")
|
2024-04-24 11:25:16 +00:00
|
|
|
await dev.update()
|
2022-03-21 21:10:12 +00:00
|
|
|
assert dev.effect["name"] == "Candy Cane"
|
|
|
|
|
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
@lightstrip_iot
|
2023-01-20 23:25:59 +00:00
|
|
|
@pytest.mark.parametrize("brightness", [100, 50])
|
|
|
|
async def test_effects_lightstrip_set_effect_brightness(
|
2024-02-04 15:20:08 +00:00
|
|
|
dev: IotLightStrip, brightness, mocker
|
2023-01-20 23:25:59 +00:00
|
|
|
):
|
2024-02-04 15:20:08 +00:00
|
|
|
query_helper = mocker.patch("kasa.iot.IotLightStrip._query_helper")
|
2023-01-20 23:25:59 +00:00
|
|
|
|
2023-02-18 17:03:54 +00:00
|
|
|
# test that default brightness works (100 for candy cane)
|
|
|
|
if brightness == 100:
|
2023-01-20 23:25:59 +00:00
|
|
|
await dev.set_effect("Candy Cane")
|
|
|
|
else:
|
|
|
|
await dev.set_effect("Candy Cane", brightness=brightness)
|
|
|
|
|
|
|
|
args, kwargs = query_helper.call_args_list[0]
|
|
|
|
payload = args[2]
|
|
|
|
assert payload["brightness"] == brightness
|
|
|
|
|
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
@lightstrip_iot
|
2023-02-18 17:03:54 +00:00
|
|
|
@pytest.mark.parametrize("transition", [500, 1000])
|
|
|
|
async def test_effects_lightstrip_set_effect_transition(
|
2024-02-04 15:20:08 +00:00
|
|
|
dev: IotLightStrip, transition, mocker
|
2023-02-18 17:03:54 +00:00
|
|
|
):
|
2024-02-04 15:20:08 +00:00
|
|
|
query_helper = mocker.patch("kasa.iot.IotLightStrip._query_helper")
|
2023-02-18 17:03:54 +00:00
|
|
|
|
|
|
|
# test that default (500 for candy cane) transition works
|
|
|
|
if transition == 500:
|
|
|
|
await dev.set_effect("Candy Cane")
|
|
|
|
else:
|
|
|
|
await dev.set_effect("Candy Cane", transition=transition)
|
|
|
|
|
|
|
|
args, kwargs = query_helper.call_args_list[0]
|
|
|
|
payload = args[2]
|
|
|
|
assert payload["transition"] == transition
|
|
|
|
|
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
@lightstrip_iot
|
2024-02-04 15:20:08 +00:00
|
|
|
async def test_effects_lightstrip_has_effects(dev: IotLightStrip):
|
2022-03-21 21:10:12 +00:00
|
|
|
assert dev.has_effects is True
|
|
|
|
assert dev.effect_list
|
2024-03-15 15:55:48 +00:00
|
|
|
|
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
@lightstrip_iot
|
2024-03-15 15:55:48 +00:00
|
|
|
def test_device_type_lightstrip(dev):
|
|
|
|
assert dev.device_type == DeviceType.LightStrip
|