Files
python-kasa/tests/smart/modules/test_waterleak.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

61 lines
1.7 KiB
Python

from datetime import datetime
from enum import Enum
import pytest
from kasa import Module
from kasa.smart import SmartDevice
from ...conftest import get_device_for_fixture_protocol
from ...device_fixtures import parametrize
waterleak = parametrize(
"has waterleak", component_filter="sensor_alarm", protocol_filter={"SMART.CHILD"}
)
@pytest.fixture
async def parent(request):
"""Get a dummy parent for tz tests."""
return await get_device_for_fixture_protocol("H100(EU)_1.0_1.5.5.json", "SMART")
@waterleak
@pytest.mark.parametrize(
("feature", "prop_name", "type"),
[
("water_alert", "alert", int),
("water_alert_timestamp", "alert_timestamp", datetime | None),
("water_leak", "status", Enum),
],
)
async def test_waterleak_properties(
dev: SmartDevice, parent: SmartDevice, feature: str, prop_name: str, type: type
) -> None:
"""Test that features are registered and work as expected."""
dev._parent = parent
waterleak = dev.modules[Module.WaterleakSensor]
prop = getattr(waterleak, prop_name)
assert isinstance(prop, type)
feat = dev.features[feature]
assert feat.value == prop
assert isinstance(feat.value, type)
@waterleak
async def test_waterleak_features(dev: SmartDevice, parent: SmartDevice) -> None:
"""Test waterleak features."""
dev._parent = parent
waterleak = dev.modules[Module.WaterleakSensor]
assert "water_leak" in dev.features
assert dev.features["water_leak"].value == waterleak.status
assert "water_alert" in dev.features
assert dev.features["water_alert"].value == waterleak.alert
assert "water_alert_timestamp" in dev.features
assert dev.features["water_alert_timestamp"].value == waterleak.alert_timestamp