python-kasa/tests/smart/modules/test_waterleak.py
Steven B. a01247d48f
Remove support for python <3.11 (#1273)
Python 3.11 ships with latest Debian Bookworm. 
pypy is not that widely used with this library based on statistics. It could be added back when pypy supports python 3.11.
2024-11-18 18:46:36 +00:00

46 lines
1.2 KiB
Python

from datetime import datetime
from enum import Enum
import pytest
from kasa.smart.modules import WaterleakSensor
from ...device_fixtures import parametrize
waterleak = parametrize(
"has waterleak", component_filter="sensor_alarm", protocol_filter={"SMART.CHILD"}
)
@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, feature, prop_name, type):
"""Test that features are registered and work as expected."""
waterleak: WaterleakSensor = dev.modules["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):
"""Test waterleak features."""
waterleak: WaterleakSensor = dev.modules["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