mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-03 14:48:21 +00:00
Make Light and Fan a common module interface (#911)
This commit is contained in:
@@ -3,7 +3,9 @@ from pytest_mock import MockerFixture
|
||||
|
||||
from kasa import Device, Module
|
||||
from kasa.tests.device_fixtures import (
|
||||
lightstrip,
|
||||
dimmable_iot,
|
||||
dimmer_iot,
|
||||
lightstrip_iot,
|
||||
parametrize,
|
||||
parametrize_combine,
|
||||
plug_iot,
|
||||
@@ -17,7 +19,12 @@ led = parametrize_combine([led_smart, plug_iot])
|
||||
light_effect_smart = parametrize(
|
||||
"has light effect smart", component_filter="light_effect", protocol_filter={"SMART"}
|
||||
)
|
||||
light_effect = parametrize_combine([light_effect_smart, lightstrip])
|
||||
light_effect = parametrize_combine([light_effect_smart, lightstrip_iot])
|
||||
|
||||
dimmable_smart = parametrize(
|
||||
"dimmable smart", component_filter="brightness", protocol_filter={"SMART"}
|
||||
)
|
||||
dimmable = parametrize_combine([dimmable_smart, dimmer_iot, dimmable_iot])
|
||||
|
||||
|
||||
@led
|
||||
@@ -25,7 +32,7 @@ async def test_led_module(dev: Device, mocker: MockerFixture):
|
||||
"""Test fan speed feature."""
|
||||
led_module = dev.modules.get(Module.Led)
|
||||
assert led_module
|
||||
feat = led_module._module_features["led"]
|
||||
feat = dev.features["led"]
|
||||
|
||||
call = mocker.spy(led_module, "call")
|
||||
await led_module.set_led(True)
|
||||
@@ -52,7 +59,7 @@ async def test_light_effect_module(dev: Device, mocker: MockerFixture):
|
||||
"""Test fan speed feature."""
|
||||
light_effect_module = dev.modules[Module.LightEffect]
|
||||
assert light_effect_module
|
||||
feat = light_effect_module._module_features["light_effect"]
|
||||
feat = dev.features["light_effect"]
|
||||
|
||||
call = mocker.spy(light_effect_module, "call")
|
||||
effect_list = light_effect_module.effect_list
|
||||
@@ -93,3 +100,26 @@ async def test_light_effect_module(dev: Device, mocker: MockerFixture):
|
||||
with pytest.raises(ValueError):
|
||||
await light_effect_module.set_effect("foobar")
|
||||
assert call.call_count == 4
|
||||
|
||||
|
||||
@dimmable
|
||||
async def test_light_brightness(dev: Device):
|
||||
"""Test brightness setter and getter."""
|
||||
assert isinstance(dev, Device)
|
||||
light = dev.modules.get(Module.Light)
|
||||
assert light
|
||||
|
||||
# Test getting the value
|
||||
feature = dev.features["brightness"]
|
||||
assert feature.minimum_value == 0
|
||||
assert feature.maximum_value == 100
|
||||
|
||||
await light.set_brightness(10)
|
||||
await dev.update()
|
||||
assert light.brightness == 10
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
await light.set_brightness(feature.minimum_value - 10)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
await light.set_brightness(feature.maximum_value + 10)
|
||||
|
||||
Reference in New Issue
Block a user