smartbulb: Limit brightness range to 1-100 (#829)

The allowed brightness for tested light devices (L530, L900) is [1-100]
instead of [0-100] like it was for some kasa devices.
This commit is contained in:
Teemu R
2024-04-17 13:33:10 +02:00
committed by GitHub
parent 700643d3cf
commit 82d92aeea5
3 changed files with 33 additions and 28 deletions

View File

@@ -16,7 +16,7 @@ async def test_brightness_component(dev: SmartDevice):
# Test getting the value
feature = dev.features["brightness"]
assert isinstance(feature.value, int)
assert feature.value > 0 and feature.value <= 100
assert feature.value > 1 and feature.value <= 100
# Test setting the value
await feature.set_value(10)

View File

@@ -8,9 +8,10 @@ from pytest_mock import MockerFixture
from kasa import KasaException
from kasa.exceptions import SmartErrorCode
from kasa.smart import SmartDevice
from kasa.smart import SmartBulb, SmartDevice
from .conftest import (
bulb_smart,
device_smart,
)
@@ -103,3 +104,25 @@ async def test_update_module_queries(dev: SmartDevice, mocker: MockerFixture):
full_query = {**full_query, **mod.query()}
query.assert_called_with(full_query)
@bulb_smart
async def test_smartdevice_brightness(dev: SmartBulb):
"""Test brightness setter and getter."""
assert isinstance(dev, SmartDevice)
assert "brightness" in dev._components
# Test getting the value
feature = dev.features["brightness"]
assert feature.minimum_value == 1
assert feature.maximum_value == 100
await dev.set_brightness(10)
await dev.update()
assert dev.brightness == 10
with pytest.raises(ValueError):
await dev.set_brightness(feature.minimum_value - 10)
with pytest.raises(ValueError):
await dev.set_brightness(feature.maximum_value + 10)