python-kasa 0.6.2.1__py3-none-any.whl → 0.7.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kasa/__init__.py +88 -27
- kasa/aestransport.py +51 -34
- kasa/cli.py +326 -130
- kasa/device.py +406 -0
- kasa/device_factory.py +83 -44
- kasa/device_type.py +7 -3
- kasa/deviceconfig.py +16 -9
- kasa/discover.py +100 -81
- kasa/emeterstatus.py +7 -5
- kasa/exceptions.py +41 -26
- kasa/feature.py +201 -0
- kasa/httpclient.py +21 -14
- kasa/interfaces/__init__.py +16 -0
- kasa/interfaces/fan.py +20 -0
- kasa/interfaces/led.py +38 -0
- kasa/interfaces/light.py +133 -0
- kasa/interfaces/lighteffect.py +80 -0
- kasa/interfaces/lightpreset.py +76 -0
- kasa/iot/__init__.py +18 -0
- kasa/{effects.py → iot/effects.py} +4 -2
- kasa/{smartbulb.py → iot/iotbulb.py} +100 -147
- kasa/{smartdevice.py → iot/iotdevice.py} +157 -286
- kasa/{smartdimmer.py → iot/iotdimmer.py} +42 -33
- kasa/iot/iotlightstrip.py +71 -0
- kasa/{modules/module.py → iot/iotmodule.py} +22 -42
- kasa/iot/iotplug.py +94 -0
- kasa/{smartstrip.py → iot/iotstrip.py} +57 -75
- kasa/{modules → iot/modules}/__init__.py +10 -2
- kasa/{modules → iot/modules}/ambientlight.py +31 -3
- kasa/{modules → iot/modules}/antitheft.py +1 -0
- kasa/{modules → iot/modules}/cloud.py +25 -6
- kasa/{modules → iot/modules}/countdown.py +1 -0
- kasa/iot/modules/emeter.py +210 -0
- kasa/iot/modules/led.py +32 -0
- kasa/iot/modules/light.py +221 -0
- kasa/iot/modules/lighteffect.py +122 -0
- kasa/iot/modules/lightpreset.py +151 -0
- kasa/{modules → iot/modules}/motion.py +8 -8
- kasa/{modules → iot/modules}/rulemodule.py +11 -12
- kasa/{modules → iot/modules}/schedule.py +1 -0
- kasa/{modules → iot/modules}/time.py +5 -4
- kasa/{modules → iot/modules}/usage.py +10 -8
- kasa/iotprotocol.py +22 -20
- kasa/klaptransport.py +25 -15
- kasa/module.py +136 -0
- kasa/modulemapping.py +25 -0
- kasa/modulemapping.pyi +96 -0
- kasa/protocol.py +6 -4
- kasa/smart/__init__.py +6 -0
- kasa/smart/effects.py +429 -0
- kasa/smart/modules/__init__.py +57 -0
- kasa/smart/modules/alarm.py +142 -0
- kasa/smart/modules/autooff.py +96 -0
- kasa/smart/modules/batterysensor.py +54 -0
- kasa/smart/modules/brightness.py +66 -0
- kasa/smart/modules/childdevice.py +10 -0
- kasa/smart/modules/cloud.py +42 -0
- kasa/smart/modules/color.py +96 -0
- kasa/smart/modules/colortemperature.py +78 -0
- kasa/smart/modules/contactsensor.py +42 -0
- kasa/smart/modules/devicemodule.py +22 -0
- kasa/smart/modules/energy.py +101 -0
- kasa/smart/modules/fan.py +80 -0
- kasa/smart/modules/firmware.py +216 -0
- kasa/smart/modules/frostprotection.py +59 -0
- kasa/smart/modules/humiditysensor.py +55 -0
- kasa/smart/modules/led.py +49 -0
- kasa/smart/modules/light.py +139 -0
- kasa/smart/modules/lighteffect.py +115 -0
- kasa/smart/modules/lightpreset.py +142 -0
- kasa/smart/modules/lightstripeffect.py +135 -0
- kasa/smart/modules/lighttransition.py +183 -0
- kasa/smart/modules/reportmode.py +36 -0
- kasa/smart/modules/temperaturecontrol.py +177 -0
- kasa/smart/modules/temperaturesensor.py +77 -0
- kasa/smart/modules/time.py +57 -0
- kasa/smart/modules/waterleaksensor.py +66 -0
- kasa/smart/smartchilddevice.py +65 -0
- kasa/smart/smartdevice.py +653 -0
- kasa/smart/smartmodule.py +112 -0
- kasa/smartprotocol.py +107 -41
- kasa/tests/conftest.py +27 -562
- kasa/tests/device_fixtures.py +427 -0
- kasa/tests/discovery_fixtures.py +197 -0
- kasa/tests/fakeprotocol_iot.py +64 -6
- kasa/tests/fakeprotocol_smart.py +215 -22
- kasa/tests/fixtureinfo.py +154 -0
- kasa/tests/fixtures/smart/H100(EU)_1.0_1.2.3.json +221 -0
- kasa/tests/fixtures/smart/H100(EU)_1.0_1.5.10.json +547 -0
- kasa/tests/fixtures/smart/H100(EU)_1.0_1.5.5.json +391 -0
- kasa/tests/fixtures/smart/KH100(UK)_1.0_1.5.6.json +1557 -0
- kasa/tests/fixtures/smart/KS240(US)_1.0_1.0.4.json +899 -0
- kasa/tests/fixtures/smart/KS240(US)_1.0_1.0.5.json +479 -0
- kasa/tests/fixtures/smart/L530E(EU)_3.0_1.1.6.json +449 -0
- kasa/tests/fixtures/smart/P100_1.0.0_1.1.3.json +173 -0
- kasa/tests/fixtures/smart/P100_1.0.0_1.4.0.json +204 -0
- kasa/tests/fixtures/smart/P110(EU)_1.0_1.0.7.json +566 -0
- kasa/tests/fixtures/smart/child/KE100(EU)_1.0_2.4.0.json +170 -0
- kasa/tests/fixtures/smart/child/KE100(EU)_1.0_2.8.0.json +171 -0
- kasa/tests/fixtures/smart/child/KE100(UK)_1.0_2.8.0.json +171 -0
- kasa/tests/fixtures/smart/child/T110(EU)_1.0_1.8.0.json +526 -0
- kasa/tests/fixtures/smart/child/T300(EU)_1.0_1.7.0.json +533 -0
- kasa/tests/fixtures/smart/child/T310(EU)_1.0_1.5.0.json +530 -0
- kasa/tests/fixtures/smart/child/T315(EU)_1.0_1.7.0.json +537 -0
- kasa/tests/smart/__init__.py +0 -0
- kasa/tests/smart/features/__init__.py +0 -0
- kasa/tests/smart/features/test_brightness.py +55 -0
- kasa/tests/smart/features/test_colortemp.py +30 -0
- kasa/tests/smart/modules/__init__.py +0 -0
- kasa/tests/smart/modules/test_contact.py +28 -0
- kasa/tests/smart/modules/test_fan.py +79 -0
- kasa/tests/smart/modules/test_firmware.py +108 -0
- kasa/tests/smart/modules/test_humidity.py +28 -0
- kasa/tests/smart/modules/test_light_effect.py +41 -0
- kasa/tests/smart/modules/test_temperature.py +47 -0
- kasa/tests/smart/modules/test_temperaturecontrol.py +137 -0
- kasa/tests/smart/modules/test_waterleak.py +42 -0
- kasa/tests/test_aestransport.py +115 -23
- kasa/tests/test_bulb.py +115 -85
- kasa/tests/test_childdevice.py +19 -7
- kasa/tests/test_cli.py +453 -99
- kasa/tests/test_common_modules.py +216 -0
- kasa/tests/test_device.py +268 -0
- kasa/tests/test_device_factory.py +61 -35
- kasa/tests/test_device_type.py +1 -1
- kasa/tests/test_deviceconfig.py +2 -2
- kasa/tests/test_dimmer.py +33 -24
- kasa/tests/test_discovery.py +112 -63
- kasa/tests/test_emeter.py +14 -10
- kasa/tests/test_feature.py +205 -0
- kasa/tests/test_httpclient.py +9 -9
- kasa/tests/test_iotdevice.py +286 -0
- kasa/tests/test_klapprotocol.py +94 -37
- kasa/tests/test_lightstrip.py +24 -19
- kasa/tests/test_plug.py +46 -8
- kasa/tests/test_protocol.py +8 -10
- kasa/tests/test_readme_examples.py +87 -26
- kasa/tests/test_smartdevice.py +203 -311
- kasa/tests/test_smartprotocol.py +130 -25
- kasa/tests/test_strip.py +15 -6
- kasa/tests/test_usage.py +1 -1
- kasa/xortransport.py +15 -12
- {python_kasa-0.6.2.1.dist-info → python_kasa-0.7.0.dev0.dist-info}/METADATA +45 -143
- python_kasa-0.7.0.dev0.dist-info/RECORD +239 -0
- kasa/modules/emeter.py +0 -111
- kasa/smartlightstrip.py +0 -143
- kasa/smartplug.py +0 -91
- kasa/tapo/__init__.py +0 -7
- kasa/tapo/childdevice.py +0 -41
- kasa/tapo/tapobulb.py +0 -262
- kasa/tapo/tapodevice.py +0 -409
- kasa/tapo/tapoplug.py +0 -45
- kasa/tests/fixtures/HS105(US)_1.0_mocked.json +0 -47
- kasa/tests/fixtures/HS110(EU)_2.0_mocked.json +0 -50
- kasa/tests/fixtures/HS110(US)_1.0_mocked.json +0 -50
- kasa/tests/fixtures/HS200(US)_1.0_mocked.json +0 -47
- kasa/tests/fixtures/HS220(US)_1.0_mocked.json +0 -75
- kasa/tests/fixtures/LB100(US)_1.0_mocked.json +0 -103
- kasa/tests/fixtures/LB120(US)_1.0_mocked.json +0 -103
- kasa/tests/fixtures/LB130(US)_1.0_mocked.json +0 -104
- python_kasa-0.6.2.1.dist-info/RECORD +0 -167
- {python_kasa-0.6.2.1.dist-info → python_kasa-0.7.0.dev0.dist-info}/LICENSE +0 -0
- {python_kasa-0.6.2.1.dist-info → python_kasa-0.7.0.dev0.dist-info}/WHEEL +0 -0
- {python_kasa-0.6.2.1.dist-info → python_kasa-0.7.0.dev0.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pytest_mock import MockerFixture
|
|
3
|
+
|
|
4
|
+
from kasa import Module
|
|
5
|
+
from kasa.smart import SmartDevice
|
|
6
|
+
from kasa.tests.device_fixtures import parametrize
|
|
7
|
+
|
|
8
|
+
fan = parametrize("has fan", component_filter="fan_control", protocol_filter={"SMART"})
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@fan
|
|
12
|
+
async def test_fan_speed(dev: SmartDevice, mocker: MockerFixture):
|
|
13
|
+
"""Test fan speed feature."""
|
|
14
|
+
fan = dev.modules.get(Module.Fan)
|
|
15
|
+
assert fan
|
|
16
|
+
|
|
17
|
+
level_feature = dev.features["fan_speed_level"]
|
|
18
|
+
assert (
|
|
19
|
+
level_feature.minimum_value
|
|
20
|
+
<= level_feature.value
|
|
21
|
+
<= level_feature.maximum_value
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
call = mocker.spy(fan, "call")
|
|
25
|
+
await fan.set_fan_speed_level(3)
|
|
26
|
+
call.assert_called_with(
|
|
27
|
+
"set_device_info", {"device_on": True, "fan_speed_level": 3}
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
await dev.update()
|
|
31
|
+
|
|
32
|
+
assert fan.fan_speed_level == 3
|
|
33
|
+
assert level_feature.value == 3
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@fan
|
|
37
|
+
async def test_sleep_mode(dev: SmartDevice, mocker: MockerFixture):
|
|
38
|
+
"""Test sleep mode feature."""
|
|
39
|
+
fan = dev.modules.get(Module.Fan)
|
|
40
|
+
assert fan
|
|
41
|
+
sleep_feature = dev.features["fan_sleep_mode"]
|
|
42
|
+
assert isinstance(sleep_feature.value, bool)
|
|
43
|
+
|
|
44
|
+
call = mocker.spy(fan, "call")
|
|
45
|
+
await fan.set_sleep_mode(True)
|
|
46
|
+
call.assert_called_with("set_device_info", {"fan_sleep_mode_on": True})
|
|
47
|
+
|
|
48
|
+
await dev.update()
|
|
49
|
+
|
|
50
|
+
assert fan.sleep_mode is True
|
|
51
|
+
assert sleep_feature.value is True
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@fan
|
|
55
|
+
async def test_fan_module(dev: SmartDevice, mocker: MockerFixture):
|
|
56
|
+
"""Test fan speed on device interface."""
|
|
57
|
+
assert isinstance(dev, SmartDevice)
|
|
58
|
+
fan = dev.modules.get(Module.Fan)
|
|
59
|
+
assert fan
|
|
60
|
+
device = fan._device
|
|
61
|
+
|
|
62
|
+
await fan.set_fan_speed_level(1)
|
|
63
|
+
await dev.update()
|
|
64
|
+
assert fan.fan_speed_level == 1
|
|
65
|
+
assert device.is_on
|
|
66
|
+
|
|
67
|
+
await fan.set_fan_speed_level(4)
|
|
68
|
+
await dev.update()
|
|
69
|
+
assert fan.fan_speed_level == 4
|
|
70
|
+
|
|
71
|
+
await fan.set_fan_speed_level(0)
|
|
72
|
+
await dev.update()
|
|
73
|
+
assert not device.is_on
|
|
74
|
+
|
|
75
|
+
with pytest.raises(ValueError):
|
|
76
|
+
await fan.set_fan_speed_level(-1)
|
|
77
|
+
|
|
78
|
+
with pytest.raises(ValueError):
|
|
79
|
+
await fan.set_fan_speed_level(5)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
from pytest_mock import MockerFixture
|
|
8
|
+
|
|
9
|
+
from kasa import Module
|
|
10
|
+
from kasa.smart import SmartDevice
|
|
11
|
+
from kasa.smart.modules.firmware import DownloadState
|
|
12
|
+
from kasa.tests.device_fixtures import parametrize
|
|
13
|
+
|
|
14
|
+
firmware = parametrize(
|
|
15
|
+
"has firmware", component_filter="firmware", protocol_filter={"SMART"}
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@firmware
|
|
20
|
+
@pytest.mark.parametrize(
|
|
21
|
+
"feature, prop_name, type, required_version",
|
|
22
|
+
[
|
|
23
|
+
("auto_update_enabled", "auto_update_enabled", bool, 2),
|
|
24
|
+
("update_available", "update_available", bool, 1),
|
|
25
|
+
("update_available", "update_available", bool, 1),
|
|
26
|
+
("current_firmware_version", "current_firmware", str, 1),
|
|
27
|
+
("available_firmware_version", "latest_firmware", str, 1),
|
|
28
|
+
],
|
|
29
|
+
)
|
|
30
|
+
async def test_firmware_features(
|
|
31
|
+
dev: SmartDevice, feature, prop_name, type, required_version, mocker: MockerFixture
|
|
32
|
+
):
|
|
33
|
+
"""Test light effect."""
|
|
34
|
+
fw = dev.modules.get(Module.Firmware)
|
|
35
|
+
assert fw
|
|
36
|
+
|
|
37
|
+
if not dev.is_cloud_connected:
|
|
38
|
+
pytest.skip("Device is not cloud connected, skipping test")
|
|
39
|
+
|
|
40
|
+
if fw.supported_version < required_version:
|
|
41
|
+
pytest.skip("Feature %s requires newer version" % feature)
|
|
42
|
+
|
|
43
|
+
prop = getattr(fw, prop_name)
|
|
44
|
+
assert isinstance(prop, type)
|
|
45
|
+
|
|
46
|
+
feat = dev.features[feature]
|
|
47
|
+
assert feat.value == prop
|
|
48
|
+
assert isinstance(feat.value, type)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@firmware
|
|
52
|
+
async def test_update_available_without_cloud(dev: SmartDevice):
|
|
53
|
+
"""Test that update_available returns None when disconnected."""
|
|
54
|
+
fw = dev.modules.get(Module.Firmware)
|
|
55
|
+
assert fw
|
|
56
|
+
|
|
57
|
+
if dev.is_cloud_connected:
|
|
58
|
+
assert isinstance(fw.update_available, bool)
|
|
59
|
+
else:
|
|
60
|
+
assert fw.update_available is None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@firmware
|
|
64
|
+
async def test_firmware_update(
|
|
65
|
+
dev: SmartDevice, mocker: MockerFixture, caplog: pytest.LogCaptureFixture
|
|
66
|
+
):
|
|
67
|
+
"""Test updating firmware."""
|
|
68
|
+
caplog.set_level(logging.INFO)
|
|
69
|
+
|
|
70
|
+
fw = dev.modules.get(Module.Firmware)
|
|
71
|
+
assert fw
|
|
72
|
+
|
|
73
|
+
upgrade_time = 5
|
|
74
|
+
extras = {"reboot_time": 5, "upgrade_time": upgrade_time, "auto_upgrade": False}
|
|
75
|
+
update_states = [
|
|
76
|
+
# Unknown 1
|
|
77
|
+
DownloadState(status=1, download_progress=0, **extras),
|
|
78
|
+
# Downloading
|
|
79
|
+
DownloadState(status=2, download_progress=10, **extras),
|
|
80
|
+
DownloadState(status=2, download_progress=100, **extras),
|
|
81
|
+
# Flashing
|
|
82
|
+
DownloadState(status=3, download_progress=100, **extras),
|
|
83
|
+
DownloadState(status=3, download_progress=100, **extras),
|
|
84
|
+
# Done
|
|
85
|
+
DownloadState(status=0, download_progress=100, **extras),
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
asyncio_sleep = asyncio.sleep
|
|
89
|
+
sleep = mocker.patch("asyncio.sleep")
|
|
90
|
+
mocker.patch.object(fw, "get_update_state", side_effect=update_states)
|
|
91
|
+
|
|
92
|
+
cb_mock = mocker.AsyncMock()
|
|
93
|
+
|
|
94
|
+
await fw.update(progress_cb=cb_mock)
|
|
95
|
+
|
|
96
|
+
# This is necessary to allow the eventloop to process the created tasks
|
|
97
|
+
await asyncio_sleep(0)
|
|
98
|
+
|
|
99
|
+
assert "Unhandled state code" in caplog.text
|
|
100
|
+
assert "Downloading firmware, progress: 10" in caplog.text
|
|
101
|
+
assert "Flashing firmware, sleeping" in caplog.text
|
|
102
|
+
assert "Update idle" in caplog.text
|
|
103
|
+
|
|
104
|
+
for state in update_states:
|
|
105
|
+
cb_mock.assert_any_await(state)
|
|
106
|
+
|
|
107
|
+
# sleep based on the upgrade_time
|
|
108
|
+
sleep.assert_any_call(upgrade_time)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from kasa.smart.modules import HumiditySensor
|
|
4
|
+
from kasa.tests.device_fixtures import parametrize
|
|
5
|
+
|
|
6
|
+
humidity = parametrize(
|
|
7
|
+
"has humidity", component_filter="humidity", protocol_filter={"SMART.CHILD"}
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@humidity
|
|
12
|
+
@pytest.mark.parametrize(
|
|
13
|
+
"feature, type",
|
|
14
|
+
[
|
|
15
|
+
("humidity", int),
|
|
16
|
+
("humidity_warning", bool),
|
|
17
|
+
],
|
|
18
|
+
)
|
|
19
|
+
async def test_humidity_features(dev, feature, type):
|
|
20
|
+
"""Test that features are registered and work as expected."""
|
|
21
|
+
humidity: HumiditySensor = dev.modules["HumiditySensor"]
|
|
22
|
+
|
|
23
|
+
prop = getattr(humidity, feature)
|
|
24
|
+
assert isinstance(prop, type)
|
|
25
|
+
|
|
26
|
+
feat = dev.features[feature]
|
|
27
|
+
assert feat.value == prop
|
|
28
|
+
assert isinstance(feat.value, type)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from itertools import chain
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
from pytest_mock import MockerFixture
|
|
7
|
+
|
|
8
|
+
from kasa import Device, Feature, Module
|
|
9
|
+
from kasa.smart.modules import LightEffect
|
|
10
|
+
from kasa.tests.device_fixtures import parametrize
|
|
11
|
+
|
|
12
|
+
light_effect = parametrize(
|
|
13
|
+
"has light effect", component_filter="light_effect", protocol_filter={"SMART"}
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@light_effect
|
|
18
|
+
async def test_light_effect(dev: Device, mocker: MockerFixture):
|
|
19
|
+
"""Test light effect."""
|
|
20
|
+
light_effect = dev.modules.get(Module.LightEffect)
|
|
21
|
+
assert isinstance(light_effect, LightEffect)
|
|
22
|
+
|
|
23
|
+
feature = dev.features["light_effect"]
|
|
24
|
+
assert feature.type == Feature.Type.Choice
|
|
25
|
+
|
|
26
|
+
call = mocker.spy(light_effect, "call")
|
|
27
|
+
assert feature.choices == light_effect.effect_list
|
|
28
|
+
assert feature.choices
|
|
29
|
+
for effect in chain(reversed(feature.choices), feature.choices):
|
|
30
|
+
await light_effect.set_effect(effect)
|
|
31
|
+
enable = effect != LightEffect.LIGHT_EFFECTS_OFF
|
|
32
|
+
params: dict[str, bool | str] = {"enable": enable}
|
|
33
|
+
if enable:
|
|
34
|
+
params["id"] = light_effect._scenes_names_to_id[effect]
|
|
35
|
+
call.assert_called_with("set_dynamic_light_effect_rule_enable", params)
|
|
36
|
+
await dev.update()
|
|
37
|
+
assert light_effect.effect == effect
|
|
38
|
+
assert feature.value == effect
|
|
39
|
+
|
|
40
|
+
with pytest.raises(ValueError):
|
|
41
|
+
await light_effect.set_effect("foobar")
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from kasa.smart.modules import TemperatureSensor
|
|
4
|
+
from kasa.tests.device_fixtures import parametrize
|
|
5
|
+
|
|
6
|
+
temperature = parametrize(
|
|
7
|
+
"has temperature", component_filter="temperature", protocol_filter={"SMART.CHILD"}
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
temperature_warning = parametrize(
|
|
11
|
+
"has temperature warning",
|
|
12
|
+
component_filter="comfort_temperature",
|
|
13
|
+
protocol_filter={"SMART.CHILD"},
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@temperature
|
|
18
|
+
@pytest.mark.parametrize(
|
|
19
|
+
"feature, type",
|
|
20
|
+
[
|
|
21
|
+
("temperature", float),
|
|
22
|
+
("temperature_unit", str),
|
|
23
|
+
],
|
|
24
|
+
)
|
|
25
|
+
async def test_temperature_features(dev, feature, type):
|
|
26
|
+
"""Test that features are registered and work as expected."""
|
|
27
|
+
temp_module: TemperatureSensor = dev.modules["TemperatureSensor"]
|
|
28
|
+
|
|
29
|
+
prop = getattr(temp_module, feature)
|
|
30
|
+
assert isinstance(prop, type)
|
|
31
|
+
|
|
32
|
+
feat = dev.features[feature]
|
|
33
|
+
assert feat.value == prop
|
|
34
|
+
assert isinstance(feat.value, type)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@temperature_warning
|
|
38
|
+
async def test_temperature_warning(dev):
|
|
39
|
+
"""Test that features are registered and work as expected."""
|
|
40
|
+
temp_module: TemperatureSensor = dev.modules["TemperatureSensor"]
|
|
41
|
+
|
|
42
|
+
assert hasattr(temp_module, "temperature_warning")
|
|
43
|
+
assert isinstance(temp_module.temperature_warning, bool)
|
|
44
|
+
|
|
45
|
+
feat = dev.features["temperature_warning"]
|
|
46
|
+
assert feat.value == temp_module.temperature_warning
|
|
47
|
+
assert isinstance(feat.value, bool)
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from kasa.smart.modules import TemperatureControl
|
|
6
|
+
from kasa.smart.modules.temperaturecontrol import ThermostatState
|
|
7
|
+
from kasa.tests.device_fixtures import parametrize, thermostats_smart
|
|
8
|
+
|
|
9
|
+
temperature = parametrize(
|
|
10
|
+
"has temperature control",
|
|
11
|
+
component_filter="temperature_control",
|
|
12
|
+
protocol_filter={"SMART.CHILD"},
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@thermostats_smart
|
|
17
|
+
@pytest.mark.parametrize(
|
|
18
|
+
"feature, type",
|
|
19
|
+
[
|
|
20
|
+
("target_temperature", float),
|
|
21
|
+
("temperature_offset", int),
|
|
22
|
+
],
|
|
23
|
+
)
|
|
24
|
+
async def test_temperature_control_features(dev, feature, type):
|
|
25
|
+
"""Test that features are registered and work as expected."""
|
|
26
|
+
temp_module: TemperatureControl = dev.modules["TemperatureControl"]
|
|
27
|
+
|
|
28
|
+
prop = getattr(temp_module, feature)
|
|
29
|
+
assert isinstance(prop, type)
|
|
30
|
+
|
|
31
|
+
feat = dev.features[feature]
|
|
32
|
+
assert feat.value == prop
|
|
33
|
+
assert isinstance(feat.value, type)
|
|
34
|
+
|
|
35
|
+
await feat.set_value(10)
|
|
36
|
+
await dev.update()
|
|
37
|
+
assert feat.value == 10
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@thermostats_smart
|
|
41
|
+
async def test_set_temperature_turns_heating_on(dev):
|
|
42
|
+
"""Test that set_temperature turns heating on."""
|
|
43
|
+
temp_module: TemperatureControl = dev.modules["TemperatureControl"]
|
|
44
|
+
|
|
45
|
+
await temp_module.set_state(False)
|
|
46
|
+
await dev.update()
|
|
47
|
+
assert temp_module.state is False
|
|
48
|
+
assert temp_module.mode is ThermostatState.Off
|
|
49
|
+
|
|
50
|
+
await temp_module.set_target_temperature(10)
|
|
51
|
+
await dev.update()
|
|
52
|
+
assert temp_module.state is True
|
|
53
|
+
assert temp_module.mode is ThermostatState.Heating
|
|
54
|
+
assert temp_module.target_temperature == 10
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@thermostats_smart
|
|
58
|
+
async def test_set_temperature_invalid_values(dev):
|
|
59
|
+
"""Test that out-of-bounds temperature values raise errors."""
|
|
60
|
+
temp_module: TemperatureControl = dev.modules["TemperatureControl"]
|
|
61
|
+
|
|
62
|
+
with pytest.raises(ValueError):
|
|
63
|
+
await temp_module.set_target_temperature(-1)
|
|
64
|
+
|
|
65
|
+
with pytest.raises(ValueError):
|
|
66
|
+
await temp_module.set_target_temperature(100)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@thermostats_smart
|
|
70
|
+
async def test_temperature_offset(dev):
|
|
71
|
+
"""Test the temperature offset API."""
|
|
72
|
+
temp_module: TemperatureControl = dev.modules["TemperatureControl"]
|
|
73
|
+
with pytest.raises(ValueError):
|
|
74
|
+
await temp_module.set_temperature_offset(100)
|
|
75
|
+
|
|
76
|
+
with pytest.raises(ValueError):
|
|
77
|
+
await temp_module.set_temperature_offset(-100)
|
|
78
|
+
|
|
79
|
+
await temp_module.set_temperature_offset(5)
|
|
80
|
+
await dev.update()
|
|
81
|
+
assert temp_module.temperature_offset == 5
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@thermostats_smart
|
|
85
|
+
@pytest.mark.parametrize(
|
|
86
|
+
"mode, states, frost_protection",
|
|
87
|
+
[
|
|
88
|
+
pytest.param(ThermostatState.Idle, [], False, id="idle has empty"),
|
|
89
|
+
pytest.param(
|
|
90
|
+
ThermostatState.Off,
|
|
91
|
+
["anything"],
|
|
92
|
+
True,
|
|
93
|
+
id="any state with frost_protection on means off",
|
|
94
|
+
),
|
|
95
|
+
pytest.param(
|
|
96
|
+
ThermostatState.Heating,
|
|
97
|
+
[ThermostatState.Heating],
|
|
98
|
+
False,
|
|
99
|
+
id="heating is heating",
|
|
100
|
+
),
|
|
101
|
+
pytest.param(ThermostatState.Unknown, ["invalid"], False, id="unknown state"),
|
|
102
|
+
],
|
|
103
|
+
)
|
|
104
|
+
async def test_thermostat_mode(dev, mode, states, frost_protection):
|
|
105
|
+
"""Test different thermostat modes."""
|
|
106
|
+
temp_module: TemperatureControl = dev.modules["TemperatureControl"]
|
|
107
|
+
|
|
108
|
+
temp_module.data["frost_protection_on"] = frost_protection
|
|
109
|
+
temp_module.data["trv_states"] = states
|
|
110
|
+
|
|
111
|
+
assert temp_module.state is not frost_protection
|
|
112
|
+
assert temp_module.mode is mode
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@thermostats_smart
|
|
116
|
+
@pytest.mark.parametrize(
|
|
117
|
+
"mode, states, msg",
|
|
118
|
+
[
|
|
119
|
+
pytest.param(
|
|
120
|
+
ThermostatState.Heating,
|
|
121
|
+
["heating", "something else"],
|
|
122
|
+
"Got multiple states",
|
|
123
|
+
id="multiple states",
|
|
124
|
+
),
|
|
125
|
+
pytest.param(
|
|
126
|
+
ThermostatState.Unknown, ["foobar"], "Got unknown state", id="unknown state"
|
|
127
|
+
),
|
|
128
|
+
],
|
|
129
|
+
)
|
|
130
|
+
async def test_thermostat_mode_warnings(dev, mode, states, msg, caplog):
|
|
131
|
+
"""Test thermostat modes that should log a warning."""
|
|
132
|
+
temp_module: TemperatureControl = dev.modules["TemperatureControl"]
|
|
133
|
+
caplog.set_level(logging.WARNING)
|
|
134
|
+
|
|
135
|
+
temp_module.data["trv_states"] = states
|
|
136
|
+
assert temp_module.mode is mode
|
|
137
|
+
assert msg in caplog.text
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from kasa.smart.modules import WaterleakSensor
|
|
6
|
+
from kasa.tests.device_fixtures import parametrize
|
|
7
|
+
|
|
8
|
+
waterleak = parametrize(
|
|
9
|
+
"has waterleak", component_filter="sensor_alarm", protocol_filter={"SMART.CHILD"}
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@waterleak
|
|
14
|
+
@pytest.mark.parametrize(
|
|
15
|
+
"feature, prop_name, type",
|
|
16
|
+
[
|
|
17
|
+
("water_alert", "alert", int),
|
|
18
|
+
("water_leak", "status", Enum),
|
|
19
|
+
],
|
|
20
|
+
)
|
|
21
|
+
async def test_waterleak_properties(dev, feature, prop_name, type):
|
|
22
|
+
"""Test that features are registered and work as expected."""
|
|
23
|
+
waterleak: WaterleakSensor = dev.modules["WaterleakSensor"]
|
|
24
|
+
|
|
25
|
+
prop = getattr(waterleak, prop_name)
|
|
26
|
+
assert isinstance(prop, type)
|
|
27
|
+
|
|
28
|
+
feat = dev.features[feature]
|
|
29
|
+
assert feat.value == prop
|
|
30
|
+
assert isinstance(feat.value, type)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@waterleak
|
|
34
|
+
async def test_waterleak_features(dev):
|
|
35
|
+
"""Test waterleak features."""
|
|
36
|
+
waterleak: WaterleakSensor = dev.modules["WaterleakSensor"]
|
|
37
|
+
|
|
38
|
+
assert "water_leak" in dev.features
|
|
39
|
+
assert dev.features["water_leak"].value == waterleak.status
|
|
40
|
+
|
|
41
|
+
assert "water_alert" in dev.features
|
|
42
|
+
assert dev.features["water_alert"].value == waterleak.alert
|