python-kasa 0.7.0.dev3__py3-none-any.whl → 0.7.0.dev5__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/cli.py +58 -22
- kasa/device.py +21 -31
- kasa/feature.py +5 -4
- kasa/interfaces/__init__.py +2 -0
- kasa/interfaces/energy.py +181 -0
- kasa/iot/iotbulb.py +1 -1
- kasa/iot/iotdevice.py +26 -101
- kasa/iot/iotstrip.py +112 -60
- kasa/iot/modules/emeter.py +30 -89
- kasa/iot/modules/led.py +5 -0
- kasa/module.py +2 -3
- kasa/smart/modules/autooff.py +8 -0
- kasa/smart/modules/energy.py +58 -60
- kasa/smart/modules/lightpreset.py +10 -0
- kasa/smart/modules/lightstripeffect.py +14 -4
- kasa/smart/modules/lighttransition.py +10 -0
- kasa/smart/modules/time.py +7 -1
- kasa/smart/smartchilddevice.py +12 -1
- kasa/smart/smartdevice.py +34 -74
- kasa/tests/device_fixtures.py +31 -0
- kasa/tests/fakeprotocol_smart.py +19 -1
- kasa/tests/fixtures/smart/L920-5(EU)_1.0_1.0.7.json +350 -0
- kasa/tests/fixtures/smart/P300(EU)_1.0_1.0.15.json +966 -0
- kasa/tests/smart/features/test_brightness.py +3 -3
- kasa/tests/smart/modules/test_autooff.py +8 -8
- kasa/tests/smart/modules/test_fan.py +6 -7
- kasa/tests/test_childdevice.py +19 -1
- kasa/tests/test_cli.py +37 -5
- kasa/tests/test_common_modules.py +8 -7
- kasa/tests/test_device.py +14 -6
- kasa/tests/test_emeter.py +36 -8
- kasa/tests/test_iotdevice.py +9 -2
- kasa/tests/test_smartdevice.py +11 -7
- {python_kasa-0.7.0.dev3.dist-info → python_kasa-0.7.0.dev5.dist-info}/METADATA +1 -1
- {python_kasa-0.7.0.dev3.dist-info → python_kasa-0.7.0.dev5.dist-info}/RECORD +38 -35
- {python_kasa-0.7.0.dev3.dist-info → python_kasa-0.7.0.dev5.dist-info}/LICENSE +0 -0
- {python_kasa-0.7.0.dev3.dist-info → python_kasa-0.7.0.dev5.dist-info}/WHEEL +0 -0
- {python_kasa-0.7.0.dev3.dist-info → python_kasa-0.7.0.dev5.dist-info}/entry_points.txt +0 -0
|
@@ -2,7 +2,7 @@ import pytest
|
|
|
2
2
|
|
|
3
3
|
from kasa.iot import IotDevice
|
|
4
4
|
from kasa.smart import SmartDevice
|
|
5
|
-
from kasa.tests.conftest import dimmable_iot, parametrize
|
|
5
|
+
from kasa.tests.conftest import dimmable_iot, get_parent_and_child_modules, parametrize
|
|
6
6
|
|
|
7
7
|
brightness = parametrize("brightness smart", component_filter="brightness")
|
|
8
8
|
|
|
@@ -10,13 +10,13 @@ brightness = parametrize("brightness smart", component_filter="brightness")
|
|
|
10
10
|
@brightness
|
|
11
11
|
async def test_brightness_component(dev: SmartDevice):
|
|
12
12
|
"""Test brightness feature."""
|
|
13
|
-
brightness = dev
|
|
13
|
+
brightness = next(get_parent_and_child_modules(dev, "Brightness"))
|
|
14
14
|
assert brightness
|
|
15
15
|
assert isinstance(dev, SmartDevice)
|
|
16
16
|
assert "brightness" in dev._components
|
|
17
17
|
|
|
18
18
|
# Test getting the value
|
|
19
|
-
feature =
|
|
19
|
+
feature = brightness._device.features["brightness"]
|
|
20
20
|
assert isinstance(feature.value, int)
|
|
21
21
|
assert feature.value > 1 and feature.value <= 100
|
|
22
22
|
|
|
@@ -9,7 +9,7 @@ from pytest_mock import MockerFixture
|
|
|
9
9
|
|
|
10
10
|
from kasa import Module
|
|
11
11
|
from kasa.smart import SmartDevice
|
|
12
|
-
from kasa.tests.device_fixtures import parametrize
|
|
12
|
+
from kasa.tests.device_fixtures import get_parent_and_child_modules, parametrize
|
|
13
13
|
|
|
14
14
|
autooff = parametrize(
|
|
15
15
|
"has autooff", component_filter="auto_off", protocol_filter={"SMART"}
|
|
@@ -33,13 +33,13 @@ async def test_autooff_features(
|
|
|
33
33
|
dev: SmartDevice, feature: str, prop_name: str, type: type
|
|
34
34
|
):
|
|
35
35
|
"""Test that features are registered and work as expected."""
|
|
36
|
-
autooff = dev
|
|
36
|
+
autooff = next(get_parent_and_child_modules(dev, Module.AutoOff))
|
|
37
37
|
assert autooff is not None
|
|
38
38
|
|
|
39
39
|
prop = getattr(autooff, prop_name)
|
|
40
40
|
assert isinstance(prop, type)
|
|
41
41
|
|
|
42
|
-
feat =
|
|
42
|
+
feat = autooff._device.features[feature]
|
|
43
43
|
assert feat.value == prop
|
|
44
44
|
assert isinstance(feat.value, type)
|
|
45
45
|
|
|
@@ -47,13 +47,13 @@ async def test_autooff_features(
|
|
|
47
47
|
@autooff
|
|
48
48
|
async def test_settings(dev: SmartDevice, mocker: MockerFixture):
|
|
49
49
|
"""Test autooff settings."""
|
|
50
|
-
autooff = dev
|
|
50
|
+
autooff = next(get_parent_and_child_modules(dev, Module.AutoOff))
|
|
51
51
|
assert autooff
|
|
52
52
|
|
|
53
|
-
enabled =
|
|
53
|
+
enabled = autooff._device.features["auto_off_enabled"]
|
|
54
54
|
assert autooff.enabled == enabled.value
|
|
55
55
|
|
|
56
|
-
delay =
|
|
56
|
+
delay = autooff._device.features["auto_off_minutes"]
|
|
57
57
|
assert autooff.delay == delay.value
|
|
58
58
|
|
|
59
59
|
call = mocker.spy(autooff, "call")
|
|
@@ -86,10 +86,10 @@ async def test_auto_off_at(
|
|
|
86
86
|
dev: SmartDevice, mocker: MockerFixture, is_timer_active: bool
|
|
87
87
|
):
|
|
88
88
|
"""Test auto-off at sensor."""
|
|
89
|
-
autooff = dev
|
|
89
|
+
autooff = next(get_parent_and_child_modules(dev, Module.AutoOff))
|
|
90
90
|
assert autooff
|
|
91
91
|
|
|
92
|
-
autooff_at =
|
|
92
|
+
autooff_at = autooff._device.features["auto_off_at"]
|
|
93
93
|
|
|
94
94
|
mocker.patch.object(
|
|
95
95
|
type(autooff),
|
|
@@ -3,7 +3,7 @@ from pytest_mock import MockerFixture
|
|
|
3
3
|
|
|
4
4
|
from kasa import Module
|
|
5
5
|
from kasa.smart import SmartDevice
|
|
6
|
-
from kasa.tests.device_fixtures import parametrize
|
|
6
|
+
from kasa.tests.device_fixtures import get_parent_and_child_modules, parametrize
|
|
7
7
|
|
|
8
8
|
fan = parametrize("has fan", component_filter="fan_control", protocol_filter={"SMART"})
|
|
9
9
|
|
|
@@ -11,10 +11,9 @@ fan = parametrize("has fan", component_filter="fan_control", protocol_filter={"S
|
|
|
11
11
|
@fan
|
|
12
12
|
async def test_fan_speed(dev: SmartDevice, mocker: MockerFixture):
|
|
13
13
|
"""Test fan speed feature."""
|
|
14
|
-
fan = dev
|
|
14
|
+
fan = next(get_parent_and_child_modules(dev, Module.Fan))
|
|
15
15
|
assert fan
|
|
16
|
-
|
|
17
|
-
level_feature = dev.features["fan_speed_level"]
|
|
16
|
+
level_feature = fan._module_features["fan_speed_level"]
|
|
18
17
|
assert (
|
|
19
18
|
level_feature.minimum_value
|
|
20
19
|
<= level_feature.value
|
|
@@ -36,9 +35,9 @@ async def test_fan_speed(dev: SmartDevice, mocker: MockerFixture):
|
|
|
36
35
|
@fan
|
|
37
36
|
async def test_sleep_mode(dev: SmartDevice, mocker: MockerFixture):
|
|
38
37
|
"""Test sleep mode feature."""
|
|
39
|
-
fan = dev
|
|
38
|
+
fan = next(get_parent_and_child_modules(dev, Module.Fan))
|
|
40
39
|
assert fan
|
|
41
|
-
sleep_feature =
|
|
40
|
+
sleep_feature = fan._module_features["fan_sleep_mode"]
|
|
42
41
|
assert isinstance(sleep_feature.value, bool)
|
|
43
42
|
|
|
44
43
|
call = mocker.spy(fan, "call")
|
|
@@ -55,7 +54,7 @@ async def test_sleep_mode(dev: SmartDevice, mocker: MockerFixture):
|
|
|
55
54
|
async def test_fan_module(dev: SmartDevice, mocker: MockerFixture):
|
|
56
55
|
"""Test fan speed on device interface."""
|
|
57
56
|
assert isinstance(dev, SmartDevice)
|
|
58
|
-
fan = dev
|
|
57
|
+
fan = next(get_parent_and_child_modules(dev, Module.Fan))
|
|
59
58
|
assert fan
|
|
60
59
|
device = fan._device
|
|
61
60
|
|
kasa/tests/test_childdevice.py
CHANGED
|
@@ -3,10 +3,20 @@ import sys
|
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
5
|
|
|
6
|
+
from kasa.device_type import DeviceType
|
|
6
7
|
from kasa.smart.smartchilddevice import SmartChildDevice
|
|
8
|
+
from kasa.smart.smartdevice import NON_HUB_PARENT_ONLY_MODULES
|
|
7
9
|
from kasa.smartprotocol import _ChildProtocolWrapper
|
|
8
10
|
|
|
9
|
-
from .conftest import strip_smart
|
|
11
|
+
from .conftest import parametrize, parametrize_subtract, strip_smart
|
|
12
|
+
|
|
13
|
+
has_children_smart = parametrize(
|
|
14
|
+
"has children", component_filter="control_child", protocol_filter={"SMART"}
|
|
15
|
+
)
|
|
16
|
+
hub_smart = parametrize(
|
|
17
|
+
"smart hub", device_type_filter=[DeviceType.Hub], protocol_filter={"SMART"}
|
|
18
|
+
)
|
|
19
|
+
non_hub_parent_smart = parametrize_subtract(has_children_smart, hub_smart)
|
|
10
20
|
|
|
11
21
|
|
|
12
22
|
@strip_smart
|
|
@@ -82,3 +92,11 @@ async def test_childdevice_properties(dev: SmartChildDevice):
|
|
|
82
92
|
exceptions = list(_test_property_getters())
|
|
83
93
|
if exceptions:
|
|
84
94
|
raise ExceptionGroup("Accessing child properties caused exceptions", exceptions)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@non_hub_parent_smart
|
|
98
|
+
async def test_parent_only_modules(dev, dummy_protocol, mocker):
|
|
99
|
+
"""Test that parent only modules are not available on children."""
|
|
100
|
+
for child in dev.children:
|
|
101
|
+
for module in NON_HUB_PARENT_ONLY_MODULES:
|
|
102
|
+
assert module not in [type(module) for module in child.modules.values()]
|
kasa/tests/test_cli.py
CHANGED
|
@@ -31,6 +31,7 @@ from kasa.cli import (
|
|
|
31
31
|
state,
|
|
32
32
|
sysinfo,
|
|
33
33
|
temperature,
|
|
34
|
+
time,
|
|
34
35
|
toggle,
|
|
35
36
|
update_credentials,
|
|
36
37
|
wifi,
|
|
@@ -260,6 +261,37 @@ async def test_update_credentials(dev, runner):
|
|
|
260
261
|
)
|
|
261
262
|
|
|
262
263
|
|
|
264
|
+
async def test_time_get(dev, runner):
|
|
265
|
+
"""Test time get command."""
|
|
266
|
+
res = await runner.invoke(
|
|
267
|
+
time,
|
|
268
|
+
obj=dev,
|
|
269
|
+
)
|
|
270
|
+
assert res.exit_code == 0
|
|
271
|
+
assert "Current time: " in res.output
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
@device_smart
|
|
275
|
+
async def test_time_sync(dev, mocker, runner):
|
|
276
|
+
"""Test time sync command.
|
|
277
|
+
|
|
278
|
+
Currently implemented only for SMART.
|
|
279
|
+
"""
|
|
280
|
+
update = mocker.patch.object(dev, "update")
|
|
281
|
+
set_time_mock = mocker.spy(dev.modules[Module.Time], "set_time")
|
|
282
|
+
res = await runner.invoke(
|
|
283
|
+
time,
|
|
284
|
+
["sync"],
|
|
285
|
+
obj=dev,
|
|
286
|
+
)
|
|
287
|
+
set_time_mock.assert_called()
|
|
288
|
+
update.assert_called()
|
|
289
|
+
|
|
290
|
+
assert res.exit_code == 0
|
|
291
|
+
assert "Old time: " in res.output
|
|
292
|
+
assert "New time: " in res.output
|
|
293
|
+
|
|
294
|
+
|
|
263
295
|
async def test_emeter(dev: Device, mocker, runner):
|
|
264
296
|
res = await runner.invoke(emeter, obj=dev)
|
|
265
297
|
if not dev.has_emeter:
|
|
@@ -429,12 +461,12 @@ async def test_led(dev: Device, runner: CliRunner):
|
|
|
429
461
|
|
|
430
462
|
async def test_json_output(dev: Device, mocker, runner):
|
|
431
463
|
"""Test that the json output produces correct output."""
|
|
432
|
-
mocker.patch("kasa.Discover.
|
|
433
|
-
# These will mock the features to avoid accessing non-existing
|
|
464
|
+
mocker.patch("kasa.Discover.discover_single", return_value=dev)
|
|
465
|
+
# These will mock the features to avoid accessing non-existing ones
|
|
434
466
|
mocker.patch("kasa.device.Device.features", return_value={})
|
|
435
467
|
mocker.patch("kasa.iot.iotdevice.IotDevice.features", return_value={})
|
|
436
468
|
|
|
437
|
-
res = await runner.invoke(cli, ["--json", "state"], obj=dev)
|
|
469
|
+
res = await runner.invoke(cli, ["--host", "127.0.0.1", "--json", "state"], obj=dev)
|
|
438
470
|
assert res.exit_code == 0
|
|
439
471
|
assert json.loads(res.output) == dev.internal_state
|
|
440
472
|
|
|
@@ -757,7 +789,7 @@ async def test_errors(mocker, runner):
|
|
|
757
789
|
)
|
|
758
790
|
assert res.exit_code == 1
|
|
759
791
|
assert (
|
|
760
|
-
"
|
|
792
|
+
"Only discover is available without --host or --alias"
|
|
761
793
|
in res.output.replace("\n", "") # Remove newlines from rich formatting
|
|
762
794
|
)
|
|
763
795
|
assert isinstance(res.exception, SystemExit)
|
|
@@ -828,7 +860,7 @@ async def test_feature_missing(mocker, runner):
|
|
|
828
860
|
)
|
|
829
861
|
assert "No feature by name 'missing'" in res.output
|
|
830
862
|
assert "== Features ==" not in res.output
|
|
831
|
-
assert res.exit_code ==
|
|
863
|
+
assert res.exit_code == 1
|
|
832
864
|
|
|
833
865
|
|
|
834
866
|
async def test_feature_set(mocker, runner):
|
|
@@ -7,6 +7,7 @@ from kasa.tests.device_fixtures import (
|
|
|
7
7
|
bulb_smart,
|
|
8
8
|
dimmable_iot,
|
|
9
9
|
dimmer_iot,
|
|
10
|
+
get_parent_and_child_modules,
|
|
10
11
|
lightstrip_iot,
|
|
11
12
|
parametrize,
|
|
12
13
|
parametrize_combine,
|
|
@@ -123,11 +124,11 @@ async def test_light_effect_module(dev: Device, mocker: MockerFixture):
|
|
|
123
124
|
async def test_light_brightness(dev: Device):
|
|
124
125
|
"""Test brightness setter and getter."""
|
|
125
126
|
assert isinstance(dev, Device)
|
|
126
|
-
light = dev
|
|
127
|
+
light = next(get_parent_and_child_modules(dev, Module.Light))
|
|
127
128
|
assert light
|
|
128
129
|
|
|
129
130
|
# Test getting the value
|
|
130
|
-
feature =
|
|
131
|
+
feature = light._device.features["brightness"]
|
|
131
132
|
assert feature.minimum_value == 0
|
|
132
133
|
assert feature.maximum_value == 100
|
|
133
134
|
|
|
@@ -146,7 +147,7 @@ async def test_light_brightness(dev: Device):
|
|
|
146
147
|
async def test_light_set_state(dev: Device):
|
|
147
148
|
"""Test brightness setter and getter."""
|
|
148
149
|
assert isinstance(dev, Device)
|
|
149
|
-
light = dev
|
|
150
|
+
light = next(get_parent_and_child_modules(dev, Module.Light))
|
|
150
151
|
assert light
|
|
151
152
|
|
|
152
153
|
await light.set_state(LightState(light_on=False))
|
|
@@ -169,11 +170,11 @@ async def test_light_set_state(dev: Device):
|
|
|
169
170
|
@light_preset
|
|
170
171
|
async def test_light_preset_module(dev: Device, mocker: MockerFixture):
|
|
171
172
|
"""Test light preset module."""
|
|
172
|
-
preset_mod = dev
|
|
173
|
+
preset_mod = next(get_parent_and_child_modules(dev, Module.LightPreset))
|
|
173
174
|
assert preset_mod
|
|
174
|
-
light_mod = dev
|
|
175
|
+
light_mod = next(get_parent_and_child_modules(dev, Module.Light))
|
|
175
176
|
assert light_mod
|
|
176
|
-
feat =
|
|
177
|
+
feat = preset_mod._device.features["light_preset"]
|
|
177
178
|
|
|
178
179
|
preset_list = preset_mod.preset_list
|
|
179
180
|
assert "Not set" in preset_list
|
|
@@ -220,7 +221,7 @@ async def test_light_preset_module(dev: Device, mocker: MockerFixture):
|
|
|
220
221
|
@light_preset
|
|
221
222
|
async def test_light_preset_save(dev: Device, mocker: MockerFixture):
|
|
222
223
|
"""Test saving a new preset value."""
|
|
223
|
-
preset_mod = dev
|
|
224
|
+
preset_mod = next(get_parent_and_child_modules(dev, Module.LightPreset))
|
|
224
225
|
assert preset_mod
|
|
225
226
|
preset_list = preset_mod.preset_list
|
|
226
227
|
if len(preset_list) == 1:
|
kasa/tests/test_device.py
CHANGED
|
@@ -163,12 +163,7 @@ async def _test_attribute(
|
|
|
163
163
|
if is_expected and will_raise:
|
|
164
164
|
ctx = pytest.raises(will_raise)
|
|
165
165
|
elif is_expected:
|
|
166
|
-
ctx = pytest.deprecated_call(
|
|
167
|
-
match=(
|
|
168
|
-
f"{attribute_name} is deprecated, use: Module."
|
|
169
|
-
+ f"{module_name} in device.modules instead"
|
|
170
|
-
)
|
|
171
|
-
)
|
|
166
|
+
ctx = pytest.deprecated_call(match=(f"{attribute_name} is deprecated, use:"))
|
|
172
167
|
else:
|
|
173
168
|
ctx = pytest.raises(
|
|
174
169
|
AttributeError, match=f"Device has no attribute '{attribute_name}'"
|
|
@@ -239,6 +234,19 @@ async def test_deprecated_other_attributes(dev: Device):
|
|
|
239
234
|
|
|
240
235
|
await _test_attribute(dev, "led", bool(led_module), "Led")
|
|
241
236
|
await _test_attribute(dev, "set_led", bool(led_module), "Led", True)
|
|
237
|
+
await _test_attribute(dev, "supported_modules", True, None)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
async def test_deprecated_emeter_attributes(dev: Device):
|
|
241
|
+
energy_module = dev.modules.get(Module.Energy)
|
|
242
|
+
|
|
243
|
+
await _test_attribute(dev, "get_emeter_realtime", bool(energy_module), "Energy")
|
|
244
|
+
await _test_attribute(dev, "emeter_realtime", bool(energy_module), "Energy")
|
|
245
|
+
await _test_attribute(dev, "emeter_today", bool(energy_module), "Energy")
|
|
246
|
+
await _test_attribute(dev, "emeter_this_month", bool(energy_module), "Energy")
|
|
247
|
+
await _test_attribute(dev, "current_consumption", bool(energy_module), "Energy")
|
|
248
|
+
await _test_attribute(dev, "get_emeter_daily", bool(energy_module), "Energy")
|
|
249
|
+
await _test_attribute(dev, "get_emeter_monthly", bool(energy_module), "Energy")
|
|
242
250
|
|
|
243
251
|
|
|
244
252
|
async def test_deprecated_light_preset_attributes(dev: Device):
|
kasa/tests/test_emeter.py
CHANGED
|
@@ -10,8 +10,9 @@ from voluptuous import (
|
|
|
10
10
|
Schema,
|
|
11
11
|
)
|
|
12
12
|
|
|
13
|
-
from kasa import EmeterStatus,
|
|
14
|
-
from kasa.
|
|
13
|
+
from kasa import Device, EmeterStatus, Module
|
|
14
|
+
from kasa.interfaces.energy import Energy
|
|
15
|
+
from kasa.iot import IotDevice, IotStrip
|
|
15
16
|
from kasa.iot.modules.emeter import Emeter
|
|
16
17
|
|
|
17
18
|
from .conftest import has_emeter, has_emeter_iot, no_emeter
|
|
@@ -38,16 +39,16 @@ CURRENT_CONSUMPTION_SCHEMA = Schema(
|
|
|
38
39
|
async def test_no_emeter(dev):
|
|
39
40
|
assert not dev.has_emeter
|
|
40
41
|
|
|
41
|
-
with pytest.raises(
|
|
42
|
+
with pytest.raises(AttributeError):
|
|
42
43
|
await dev.get_emeter_realtime()
|
|
43
44
|
# Only iot devices support the historical stats so other
|
|
44
45
|
# devices will not implement the methods below
|
|
45
46
|
if isinstance(dev, IotDevice):
|
|
46
|
-
with pytest.raises(
|
|
47
|
+
with pytest.raises(AttributeError):
|
|
47
48
|
await dev.get_emeter_daily()
|
|
48
|
-
with pytest.raises(
|
|
49
|
+
with pytest.raises(AttributeError):
|
|
49
50
|
await dev.get_emeter_monthly()
|
|
50
|
-
with pytest.raises(
|
|
51
|
+
with pytest.raises(AttributeError):
|
|
51
52
|
await dev.erase_emeter_stats()
|
|
52
53
|
|
|
53
54
|
|
|
@@ -128,11 +129,11 @@ async def test_erase_emeter_stats(dev):
|
|
|
128
129
|
@has_emeter_iot
|
|
129
130
|
async def test_current_consumption(dev):
|
|
130
131
|
if dev.has_emeter:
|
|
131
|
-
x =
|
|
132
|
+
x = dev.current_consumption
|
|
132
133
|
assert isinstance(x, float)
|
|
133
134
|
assert x >= 0.0
|
|
134
135
|
else:
|
|
135
|
-
assert
|
|
136
|
+
assert dev.current_consumption is None
|
|
136
137
|
|
|
137
138
|
|
|
138
139
|
async def test_emeterstatus_missing_current():
|
|
@@ -173,3 +174,30 @@ async def test_emeter_daily():
|
|
|
173
174
|
{"day": now.day, "energy_wh": 500, "month": now.month, "year": now.year}
|
|
174
175
|
)
|
|
175
176
|
assert emeter.emeter_today == 0.500
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
@has_emeter
|
|
180
|
+
async def test_supported(dev: Device):
|
|
181
|
+
energy_module = dev.modules.get(Module.Energy)
|
|
182
|
+
assert energy_module
|
|
183
|
+
if isinstance(dev, IotDevice):
|
|
184
|
+
info = (
|
|
185
|
+
dev._last_update
|
|
186
|
+
if not isinstance(dev, IotStrip)
|
|
187
|
+
else dev.children[0].internal_state
|
|
188
|
+
)
|
|
189
|
+
emeter = info[energy_module._module]["get_realtime"]
|
|
190
|
+
has_total = "total" in emeter or "total_wh" in emeter
|
|
191
|
+
has_voltage_current = "voltage" in emeter or "voltage_mv" in emeter
|
|
192
|
+
assert (
|
|
193
|
+
energy_module.supports(Energy.ModuleFeature.CONSUMPTION_TOTAL) is has_total
|
|
194
|
+
)
|
|
195
|
+
assert (
|
|
196
|
+
energy_module.supports(Energy.ModuleFeature.VOLTAGE_CURRENT)
|
|
197
|
+
is has_voltage_current
|
|
198
|
+
)
|
|
199
|
+
assert energy_module.supports(Energy.ModuleFeature.PERIODIC_STATS) is True
|
|
200
|
+
else:
|
|
201
|
+
assert energy_module.supports(Energy.ModuleFeature.CONSUMPTION_TOTAL) is False
|
|
202
|
+
assert energy_module.supports(Energy.ModuleFeature.VOLTAGE_CURRENT) is False
|
|
203
|
+
assert energy_module.supports(Energy.ModuleFeature.PERIODIC_STATS) is False
|
kasa/tests/test_iotdevice.py
CHANGED
|
@@ -116,9 +116,16 @@ async def test_initial_update_no_emeter(dev, mocker):
|
|
|
116
116
|
dev._legacy_features = set()
|
|
117
117
|
spy = mocker.spy(dev.protocol, "query")
|
|
118
118
|
await dev.update()
|
|
119
|
-
#
|
|
119
|
+
# child calls will happen if a child has a module with a query (e.g. schedule)
|
|
120
|
+
child_calls = 0
|
|
121
|
+
for child in dev.children:
|
|
122
|
+
for module in child.modules.values():
|
|
123
|
+
if module.query():
|
|
124
|
+
child_calls += 1
|
|
125
|
+
break
|
|
126
|
+
# 2 parent are necessary as some devices crash on unexpected modules
|
|
120
127
|
# See #105, #120, #161
|
|
121
|
-
assert spy.call_count == 2
|
|
128
|
+
assert spy.call_count == 2 + child_calls
|
|
122
129
|
|
|
123
130
|
|
|
124
131
|
@device_iot
|
kasa/tests/test_smartdevice.py
CHANGED
|
@@ -9,13 +9,14 @@ from unittest.mock import patch
|
|
|
9
9
|
import pytest
|
|
10
10
|
from pytest_mock import MockerFixture
|
|
11
11
|
|
|
12
|
-
from kasa import KasaException, Module
|
|
12
|
+
from kasa import Device, KasaException, Module
|
|
13
13
|
from kasa.exceptions import SmartErrorCode
|
|
14
14
|
from kasa.smart import SmartDevice
|
|
15
15
|
|
|
16
16
|
from .conftest import (
|
|
17
17
|
device_smart,
|
|
18
18
|
get_device_for_fixture_protocol,
|
|
19
|
+
get_parent_and_child_modules,
|
|
19
20
|
)
|
|
20
21
|
|
|
21
22
|
|
|
@@ -111,6 +112,11 @@ async def test_update_module_queries(dev: SmartDevice, mocker: MockerFixture):
|
|
|
111
112
|
device_queries: dict[SmartDevice, dict[str, Any]] = {}
|
|
112
113
|
for mod in dev._modules.values():
|
|
113
114
|
device_queries.setdefault(mod._device, {}).update(mod.query())
|
|
115
|
+
# Hubs do not query child modules by default.
|
|
116
|
+
if dev.device_type != Device.Type.Hub:
|
|
117
|
+
for child in dev.children:
|
|
118
|
+
for mod in child.modules.values():
|
|
119
|
+
device_queries.setdefault(mod._device, {}).update(mod.query())
|
|
114
120
|
|
|
115
121
|
spies = {}
|
|
116
122
|
for device in device_queries:
|
|
@@ -119,7 +125,8 @@ async def test_update_module_queries(dev: SmartDevice, mocker: MockerFixture):
|
|
|
119
125
|
await dev.update()
|
|
120
126
|
for device in device_queries:
|
|
121
127
|
if device_queries[device]:
|
|
122
|
-
|
|
128
|
+
# Need assert any here because the child device updates use the parent's protocol
|
|
129
|
+
spies[device].assert_any_call(device_queries[device])
|
|
123
130
|
else:
|
|
124
131
|
spies[device].assert_not_called()
|
|
125
132
|
|
|
@@ -144,11 +151,8 @@ async def test_get_modules():
|
|
|
144
151
|
|
|
145
152
|
# Modules on child
|
|
146
153
|
module = dummy_device.modules.get("Fan")
|
|
147
|
-
assert module
|
|
148
|
-
|
|
149
|
-
assert module._device._parent == dummy_device
|
|
150
|
-
|
|
151
|
-
module = dummy_device.modules.get(Module.Fan)
|
|
154
|
+
assert module is None
|
|
155
|
+
module = next(get_parent_and_child_modules(dummy_device, "Fan"))
|
|
152
156
|
assert module
|
|
153
157
|
assert module._device != dummy_device
|
|
154
158
|
assert module._device._parent == dummy_device
|