mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Enable setting brightness with color temp for smart devices (#1091)
This commit is contained in:
@@ -12,6 +12,7 @@ from kasa.tests.device_fixtures import (
|
||||
parametrize,
|
||||
parametrize_combine,
|
||||
plug_iot,
|
||||
variable_temp_iot,
|
||||
)
|
||||
|
||||
led_smart = parametrize(
|
||||
@@ -36,6 +37,14 @@ dimmable_smart = parametrize(
|
||||
)
|
||||
dimmable = parametrize_combine([dimmable_smart, dimmer_iot, dimmable_iot])
|
||||
|
||||
variable_temp_smart = parametrize(
|
||||
"variable temp smart",
|
||||
component_filter="color_temperature",
|
||||
protocol_filter={"SMART"},
|
||||
)
|
||||
|
||||
variable_temp = parametrize_combine([variable_temp_iot, variable_temp_smart])
|
||||
|
||||
light_preset_smart = parametrize(
|
||||
"has light preset smart", component_filter="preset", protocol_filter={"SMART"}
|
||||
)
|
||||
@@ -147,6 +156,45 @@ async def test_light_brightness(dev: Device):
|
||||
await light.set_brightness(feature.maximum_value + 10)
|
||||
|
||||
|
||||
@variable_temp
|
||||
async def test_light_color_temp(dev: Device):
|
||||
"""Test color temp setter and getter."""
|
||||
assert isinstance(dev, Device)
|
||||
|
||||
light = next(get_parent_and_child_modules(dev, Module.Light))
|
||||
assert light
|
||||
if not light.is_variable_color_temp:
|
||||
pytest.skip(
|
||||
"Some smart light strips have color_temperature"
|
||||
" component but min and max are the same"
|
||||
)
|
||||
|
||||
# Test getting the value
|
||||
feature = light._device.features["color_temperature"]
|
||||
assert isinstance(feature.minimum_value, int)
|
||||
assert isinstance(feature.maximum_value, int)
|
||||
|
||||
await light.set_color_temp(feature.minimum_value + 10)
|
||||
await dev.update()
|
||||
assert light.color_temp == feature.minimum_value + 10
|
||||
|
||||
# Test setting brightness with color temp
|
||||
await light.set_brightness(50)
|
||||
await dev.update()
|
||||
assert light.brightness == 50
|
||||
|
||||
await light.set_color_temp(feature.minimum_value + 20, brightness=60)
|
||||
await dev.update()
|
||||
assert light.color_temp == feature.minimum_value + 20
|
||||
assert light.brightness == 60
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
await light.set_color_temp(feature.minimum_value - 10)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
await light.set_color_temp(feature.maximum_value + 10)
|
||||
|
||||
|
||||
@light
|
||||
async def test_light_set_state(dev: Device):
|
||||
"""Test brightness setter and getter."""
|
||||
|
Reference in New Issue
Block a user