mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-07-11 09:52:04 +00:00
Some checks failed
CI / Perform Lint Checks (3.14) (push) Has been cancelled
CodeQL Checks / Analyze (python) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.14 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.14 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
CI / Python 3.14 on windows-latest (push) Has been cancelled
Stale / stale (push) Has been cancelled
Add type annotations across all 'smart' tests, enabling mypy to check test function bodies, catching type errors that were previously hidden.
114 lines
3.3 KiB
Python
114 lines
3.3 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.dustbin import Mode
|
|
|
|
from ...device_fixtures import get_parent_and_child_modules, parametrize
|
|
|
|
dustbin = parametrize(
|
|
"has dustbin", component_filter="dust_bucket", protocol_filter={"SMART"}
|
|
)
|
|
|
|
|
|
@dustbin
|
|
@pytest.mark.parametrize(
|
|
("feature", "prop_name", "type"),
|
|
[
|
|
("dustbin_autocollection_enabled", "auto_collection", bool),
|
|
("dustbin_mode", "mode", str),
|
|
],
|
|
)
|
|
async def test_features(
|
|
dev: SmartDevice, feature: str, prop_name: str, type: type
|
|
) -> None:
|
|
"""Test that features are registered and work as expected."""
|
|
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
|
|
assert dustbin is not None
|
|
|
|
prop = getattr(dustbin, prop_name)
|
|
assert isinstance(prop, type)
|
|
|
|
feat = dustbin._device.features[feature]
|
|
assert feat.value == prop
|
|
assert isinstance(feat.value, type)
|
|
|
|
|
|
@dustbin
|
|
async def test_dustbin_mode(dev: SmartDevice, mocker: MockerFixture) -> None:
|
|
"""Test dust mode."""
|
|
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
|
|
call = mocker.spy(dustbin, "call")
|
|
|
|
mode_feature = dustbin._device.features["dustbin_mode"]
|
|
assert dustbin.mode == mode_feature.value
|
|
|
|
new_mode = Mode.Max
|
|
await dustbin.set_mode(new_mode.name)
|
|
|
|
params = dustbin._settings.copy()
|
|
params["dust_collection_mode"] = new_mode.value
|
|
|
|
call.assert_called_with("setDustCollectionInfo", params)
|
|
|
|
await dev.update()
|
|
|
|
assert dustbin.mode == new_mode.name
|
|
|
|
with pytest.raises(ValueError, match="Invalid auto/emptying mode speed"):
|
|
await dustbin.set_mode("invalid")
|
|
|
|
|
|
@dustbin
|
|
async def test_dustbin_mode_off(dev: SmartDevice, mocker: MockerFixture) -> None:
|
|
"""Test dustbin_mode == Off."""
|
|
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
|
|
call = mocker.spy(dustbin, "call")
|
|
|
|
auto_collection = dustbin._device.features["dustbin_mode"]
|
|
await auto_collection.set_value(Mode.Off.name)
|
|
|
|
params = dustbin._settings.copy()
|
|
params["auto_dust_collection"] = False
|
|
|
|
call.assert_called_with("setDustCollectionInfo", params)
|
|
|
|
await dev.update()
|
|
assert dustbin.auto_collection is False
|
|
assert dustbin.mode is Mode.Off.name
|
|
|
|
|
|
@dustbin
|
|
async def test_autocollection(dev: SmartDevice, mocker: MockerFixture) -> None:
|
|
"""Test autocollection switch."""
|
|
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
|
|
call = mocker.spy(dustbin, "call")
|
|
|
|
auto_collection = dustbin._device.features["dustbin_autocollection_enabled"]
|
|
assert dustbin.auto_collection == auto_collection.value
|
|
|
|
await auto_collection.set_value(True)
|
|
|
|
params = dustbin._settings.copy()
|
|
params["auto_dust_collection"] = True
|
|
|
|
call.assert_called_with("setDustCollectionInfo", params)
|
|
|
|
await dev.update()
|
|
|
|
assert dustbin.auto_collection is True
|
|
|
|
|
|
@dustbin
|
|
async def test_empty_dustbin(dev: SmartDevice, mocker: MockerFixture) -> None:
|
|
"""Test the empty dustbin feature."""
|
|
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
|
|
call = mocker.spy(dustbin, "call")
|
|
|
|
await dustbin.start_emptying()
|
|
|
|
call.assert_called_with("setSwitchDustCollection", {"switch_dust_collection": True})
|