-
-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathtest_lightstrip.py
More file actions
84 lines (63 loc) · 2.49 KB
/
test_lightstrip.py
File metadata and controls
84 lines (63 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pytest
from kasa import DeviceType, Module
from kasa.iot import IotLightStrip
from kasa.iot.modules import LightEffect
from .conftest import lightstrip_iot
@lightstrip_iot
async def test_lightstrip_length(dev: IotLightStrip):
assert dev.device_type == DeviceType.LightStrip
assert dev.length == dev.sys_info["length"]
@lightstrip_iot
async def test_lightstrip_effect(dev: IotLightStrip):
le: LightEffect = dev.modules[Module.LightEffect]
assert isinstance(le._deprecated_effect, dict)
for k in ["brightness", "custom", "enable", "id", "name"]:
assert k in le._deprecated_effect
@lightstrip_iot
async def test_effects_lightstrip_set_effect(dev: IotLightStrip):
le: LightEffect = dev.modules[Module.LightEffect]
with pytest.raises(
ValueError, match="The effect Not real is not a built in effect"
):
await le.set_effect("Not real")
await le.set_effect("Candy Cane")
await dev.update()
assert le.effect == "Candy Cane"
@lightstrip_iot
@pytest.mark.parametrize("brightness", [100, 50])
async def test_effects_lightstrip_set_effect_brightness(
dev: IotLightStrip, brightness, mocker
):
query_helper = mocker.patch("kasa.iot.IotLightStrip._query_helper")
le: LightEffect = dev.modules[Module.LightEffect]
# test that default brightness works (100 for candy cane)
if brightness == 100:
await le.set_effect("Candy Cane")
else:
await le.set_effect("Candy Cane", brightness=brightness)
args, kwargs = query_helper.call_args_list[0]
payload = args[2]
assert payload["brightness"] == brightness
@lightstrip_iot
@pytest.mark.parametrize("transition", [500, 1000])
async def test_effects_lightstrip_set_effect_transition(
dev: IotLightStrip, transition, mocker
):
query_helper = mocker.patch("kasa.iot.IotLightStrip._query_helper")
le: LightEffect = dev.modules[Module.LightEffect]
# test that default (500 for candy cane) transition works
if transition == 500:
await le.set_effect("Candy Cane")
else:
await le.set_effect("Candy Cane", transition=transition)
args, kwargs = query_helper.call_args_list[0]
payload = args[2]
assert payload["transition"] == transition
@lightstrip_iot
async def test_effects_lightstrip_has_effects(dev: IotLightStrip):
le: LightEffect = dev.modules[Module.LightEffect]
assert le is not None
assert le.effect_list
@lightstrip_iot
def test_device_type_lightstrip(dev):
assert dev.device_type == DeviceType.LightStrip