2022-03-21 21:10:12 +00:00
|
|
|
import pytest
|
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
from kasa import DeviceType
|
2024-02-21 15:52:55 +00:00
|
|
|
from kasa.exceptions import KasaException
|
2024-02-04 15:20:08 +00:00
|
|
|
from kasa.iot import IotLightStrip
|
2021-09-24 20:26:21 +00:00
|
|
|
|
2022-11-13 22:34:47 +00:00
|
|
|
from .conftest import lightstrip
|
2021-09-24 20:26:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
@lightstrip
|
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"]
|
|
|
|
|
|
|
|
|
|
|
|
@lightstrip
|
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
|
|
|
|
|
|
|
|
|
|
|
@lightstrip
|
2024-02-04 15:20:08 +00:00
|
|
|
async def test_effects_lightstrip_set_effect(dev: IotLightStrip):
|
2024-02-21 15:52:55 +00:00
|
|
|
with pytest.raises(KasaException):
|
2022-03-21 21:10:12 +00:00
|
|
|
await dev.set_effect("Not real")
|
|
|
|
|
|
|
|
await dev.set_effect("Candy Cane")
|
|
|
|
assert dev.effect["name"] == "Candy Cane"
|
|
|
|
assert dev.state_information["Effect"] == "Candy Cane"
|
|
|
|
|
|
|
|
|
2023-01-20 23:25:59 +00:00
|
|
|
@lightstrip
|
|
|
|
@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
|
|
|
|
|
|
|
|
|
2023-02-18 17:03:54 +00:00
|
|
|
@lightstrip
|
|
|
|
@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
|
|
|
|
|
|
|
|
|
2022-03-21 21:10:12 +00:00
|
|
|
@lightstrip
|
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
|
|
|
|
|
|
|
|
|
|
|
@lightstrip
|
|
|
|
def test_device_type_lightstrip(dev):
|
|
|
|
assert dev.device_type == DeviceType.LightStrip
|