2024-04-30 15:31:47 +00:00
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from kasa.smart.modules import WaterleakSensor
|
|
|
|
from kasa.tests.device_fixtures import parametrize
|
|
|
|
|
|
|
|
waterleak = parametrize(
|
|
|
|
"has waterleak", component_filter="sensor_alarm", protocol_filter={"SMART.CHILD"}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@waterleak
|
|
|
|
@pytest.mark.parametrize(
|
2024-05-03 13:24:34 +00:00
|
|
|
"feature, prop_name, type",
|
2024-04-30 15:31:47 +00:00
|
|
|
[
|
2024-05-03 13:24:34 +00:00
|
|
|
("water_alert", "alert", int),
|
|
|
|
("water_leak", "status", Enum),
|
2024-04-30 15:31:47 +00:00
|
|
|
],
|
|
|
|
)
|
2024-05-03 13:24:34 +00:00
|
|
|
async def test_waterleak_properties(dev, feature, prop_name, type):
|
2024-04-30 15:31:47 +00:00
|
|
|
"""Test that features are registered and work as expected."""
|
|
|
|
waterleak: WaterleakSensor = dev.modules["WaterleakSensor"]
|
|
|
|
|
2024-05-03 13:24:34 +00:00
|
|
|
prop = getattr(waterleak, prop_name)
|
2024-04-30 15:31:47 +00:00
|
|
|
assert isinstance(prop, type)
|
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
feat = dev.features[feature]
|
2024-04-30 15:31:47 +00:00
|
|
|
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
|