Files
python-kasa/tests/smart/features/test_brightness.py
ZeliardM 88e1c27bd0
Some checks are pending
CI / Perform Lint Checks (3.14) (push) Waiting to run
CI / Python 3.11 on macos-latest (push) Blocked by required conditions
CI / Python 3.12 on macos-latest (push) Blocked by required conditions
CI / Python 3.13 on macos-latest (push) Blocked by required conditions
CI / Python 3.14 on macos-latest (push) Blocked by required conditions
CI / Python 3.11 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.12 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.13 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.14 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.11 on windows-latest (push) Blocked by required conditions
CI / Python 3.12 on windows-latest (push) Blocked by required conditions
CI / Python 3.13 on windows-latest (push) Blocked by required conditions
CI / Python 3.14 on windows-latest (push) Blocked by required conditions
CodeQL Checks / Analyze (python) (push) Waiting to run
tests: add type annotations to Smart tests (#1686)
Add type annotations across all 'smart' tests, enabling mypy to check test function bodies, catching type errors that were previously hidden.
2026-07-08 00:11:59 +02:00

59 lines
1.8 KiB
Python

import pytest
from kasa.iot import IotDevice
from kasa.smart import SmartDevice
from ...conftest import dimmable_iot, get_parent_and_child_modules, parametrize
brightness = parametrize("brightness smart", component_filter="brightness")
@brightness
async def test_brightness_component(dev: SmartDevice) -> None:
"""Test brightness feature."""
brightness = next(get_parent_and_child_modules(dev, "Brightness"))
assert brightness
assert isinstance(dev, SmartDevice)
assert "brightness" in dev._components
# Test getting the value
feature = brightness._device.features["brightness"]
assert isinstance(feature.value, int)
assert feature.value > 1
assert feature.value <= 100
# Test setting the value
await feature.set_value(10)
await dev.update()
assert feature.value == 10
with pytest.raises(ValueError, match="out of range"):
await feature.set_value(feature.minimum_value - 10)
with pytest.raises(ValueError, match="out of range"):
await feature.set_value(feature.maximum_value + 10)
@dimmable_iot
async def test_brightness_dimmable(dev: IotDevice) -> None:
"""Test brightness feature."""
assert isinstance(dev, IotDevice)
assert "brightness" in dev.sys_info or bool(dev.sys_info["is_dimmable"])
# Test getting the value
feature = dev.features["brightness"]
assert isinstance(feature.value, int)
assert feature.value > 0
assert feature.value <= 100
# Test setting the value
await feature.set_value(10)
await dev.update()
assert feature.value == 10
with pytest.raises(ValueError, match="out of range"):
await feature.set_value(feature.minimum_value - 10)
with pytest.raises(ValueError, match="out of range"):
await feature.set_value(feature.maximum_value + 10)