2022-03-21 11:10:12 -10:00
|
|
|
import pytest
|
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
from kasa import DeviceType
|
|
|
|
from kasa.iot import IotLightStrip
|
2021-09-24 22:26:21 +02:00
|
|
|
|
2024-05-13 17:34:44 +01:00
|
|
|
from .conftest import lightstrip_iot
|
2021-09-24 22:26:21 +02:00
|
|
|
|
|
|
|
|
2024-05-13 17:34:44 +01:00
|
|
|
@lightstrip_iot
|
2024-02-04 15:20:08 +00:00
|
|
|
async def test_lightstrip_length(dev: IotLightStrip):
|
2021-09-24 22:26:21 +02:00
|
|
|
assert dev.is_light_strip
|
|
|
|
assert dev.device_type == DeviceType.LightStrip
|
|
|
|
assert dev.length == dev.sys_info["length"]
|
|
|
|
|
|
|
|
|
2024-05-13 17:34:44 +01:00
|
|
|
@lightstrip_iot
|
2024-02-04 15:20:08 +00:00
|
|
|
async def test_lightstrip_effect(dev: IotLightStrip):
|
2021-09-24 22:26:21 +02:00
|
|
|
assert isinstance(dev.effect, dict)
|
|
|
|
for k in ["brightness", "custom", "enable", "id", "name"]:
|
|
|
|
assert k in dev.effect
|
2022-03-21 11:10:12 -10:00
|
|
|
|
|
|
|
|
2024-05-13 17:34:44 +01:00
|
|
|
@lightstrip_iot
|
2024-02-04 15:20:08 +00:00
|
|
|
async def test_effects_lightstrip_set_effect(dev: IotLightStrip):
|
2024-08-30 17:30:07 +02:00
|
|
|
with pytest.raises(
|
|
|
|
ValueError, match="The effect Not real is not a built in effect"
|
|
|
|
):
|
2022-03-21 11:10:12 -10:00
|
|
|
await dev.set_effect("Not real")
|
|
|
|
|
|
|
|
await dev.set_effect("Candy Cane")
|
2024-04-24 12:25:16 +01:00
|
|
|
await dev.update()
|
2022-03-21 11:10:12 -10:00
|
|
|
assert dev.effect["name"] == "Candy Cane"
|
|
|
|
|
|
|
|
|
2024-05-13 17:34:44 +01:00
|
|
|
@lightstrip_iot
|
2023-01-21 00:25:59 +01: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-21 00:25:59 +01:00
|
|
|
):
|
2024-02-04 15:20:08 +00:00
|
|
|
query_helper = mocker.patch("kasa.iot.IotLightStrip._query_helper")
|
2023-01-21 00:25:59 +01:00
|
|
|
|
2023-02-18 18:03:54 +01:00
|
|
|
# test that default brightness works (100 for candy cane)
|
|
|
|
if brightness == 100:
|
2023-01-21 00:25:59 +01: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 17:34:44 +01:00
|
|
|
@lightstrip_iot
|
2023-02-18 18:03:54 +01: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 18:03:54 +01:00
|
|
|
):
|
2024-02-04 15:20:08 +00:00
|
|
|
query_helper = mocker.patch("kasa.iot.IotLightStrip._query_helper")
|
2023-02-18 18:03:54 +01: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 17:34:44 +01:00
|
|
|
@lightstrip_iot
|
2024-02-04 15:20:08 +00:00
|
|
|
async def test_effects_lightstrip_has_effects(dev: IotLightStrip):
|
2022-03-21 11:10:12 -10:00
|
|
|
assert dev.has_effects is True
|
|
|
|
assert dev.effect_list
|
2024-03-15 16:55:48 +01:00
|
|
|
|
|
|
|
|
2024-05-13 17:34:44 +01:00
|
|
|
@lightstrip_iot
|
2024-03-15 16:55:48 +01:00
|
|
|
def test_device_type_lightstrip(dev):
|
|
|
|
assert dev.device_type == DeviceType.LightStrip
|