mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-07-08 14:52:03 +00:00
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
Add type annotations across all 'smart' tests, enabling mypy to check test function bodies, catching type errors that were previously hidden.
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pytest_mock import MockerFixture
|
|
|
|
from kasa import Module
|
|
from kasa.smart import SmartDevice
|
|
from kasa.smart.modules.mop import Waterlevel
|
|
|
|
from ...device_fixtures import get_parent_and_child_modules, parametrize
|
|
|
|
mop = parametrize("has mop", component_filter="mop", protocol_filter={"SMART"})
|
|
|
|
|
|
@mop
|
|
@pytest.mark.parametrize(
|
|
("feature", "prop_name", "type"),
|
|
[
|
|
("mop_attached", "mop_attached", bool),
|
|
("mop_waterlevel", "waterlevel", str),
|
|
],
|
|
)
|
|
async def test_features(
|
|
dev: SmartDevice, feature: str, prop_name: str, type: type
|
|
) -> None:
|
|
"""Test that features are registered and work as expected."""
|
|
mod = next(get_parent_and_child_modules(dev, Module.Mop))
|
|
assert mod is not None
|
|
|
|
prop = getattr(mod, prop_name)
|
|
assert isinstance(prop, type)
|
|
|
|
feat = mod._device.features[feature]
|
|
assert feat.value == prop
|
|
assert isinstance(feat.value, type)
|
|
|
|
|
|
@mop
|
|
async def test_mop_waterlevel(dev: SmartDevice, mocker: MockerFixture) -> None:
|
|
"""Test dust mode."""
|
|
mop_module = next(get_parent_and_child_modules(dev, Module.Mop))
|
|
call = mocker.spy(mop_module, "call")
|
|
|
|
waterlevel = mop_module._device.features["mop_waterlevel"]
|
|
assert mop_module.waterlevel == waterlevel.value
|
|
|
|
new_level = Waterlevel.High
|
|
await mop_module.set_waterlevel(new_level.name)
|
|
|
|
call.assert_called_with(
|
|
"setCleanAttr", {"cistern": new_level.value, "type": "global"}
|
|
)
|
|
|
|
await dev.update()
|
|
|
|
assert mop_module.waterlevel == new_level.name
|
|
|
|
with pytest.raises(ValueError, match="Invalid waterlevel"):
|
|
await mop_module.set_waterlevel("invalid")
|