python-kasa 0.7.0.dev4__py3-none-any.whl → 0.7.0.1__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.
Files changed (55) hide show
  1. kasa/aestransport.py +6 -2
  2. kasa/cli.py +117 -66
  3. kasa/device.py +126 -33
  4. kasa/discover.py +2 -1
  5. kasa/feature.py +90 -14
  6. kasa/httpclient.py +1 -1
  7. kasa/interfaces/__init__.py +2 -0
  8. kasa/interfaces/energy.py +187 -0
  9. kasa/interfaces/light.py +61 -1
  10. kasa/interfaces/lighteffect.py +41 -1
  11. kasa/interfaces/lightpreset.py +70 -2
  12. kasa/iot/iotbulb.py +1 -1
  13. kasa/iot/iotdevice.py +32 -102
  14. kasa/iot/iotstrip.py +125 -62
  15. kasa/iot/modules/emeter.py +30 -89
  16. kasa/iot/modules/led.py +5 -0
  17. kasa/iot/modules/lightpreset.py +2 -1
  18. kasa/module.py +41 -4
  19. kasa/smart/modules/alarm.py +1 -0
  20. kasa/smart/modules/autooff.py +3 -1
  21. kasa/smart/modules/childdevice.py +39 -1
  22. kasa/smart/modules/energy.py +58 -60
  23. kasa/smart/modules/firmware.py +4 -1
  24. kasa/smart/modules/frostprotection.py +0 -22
  25. kasa/smart/modules/humiditysensor.py +1 -0
  26. kasa/smart/modules/led.py +1 -1
  27. kasa/smart/modules/lightpreset.py +2 -1
  28. kasa/smart/modules/lightstripeffect.py +14 -4
  29. kasa/smart/modules/lighttransition.py +8 -0
  30. kasa/smart/modules/reportmode.py +2 -0
  31. kasa/smart/modules/temperaturecontrol.py +3 -2
  32. kasa/smart/modules/temperaturesensor.py +3 -2
  33. kasa/smart/modules/time.py +10 -3
  34. kasa/smart/modules/waterleaksensor.py +2 -0
  35. kasa/smart/smartdevice.py +29 -51
  36. kasa/tests/device_fixtures.py +1 -1
  37. kasa/tests/discovery_fixtures.py +3 -1
  38. kasa/tests/fakeprotocol_smart.py +2 -2
  39. kasa/tests/fixtures/smart/L920-5(EU)_1.0_1.0.7.json +350 -0
  40. kasa/tests/smart/modules/test_firmware.py +12 -1
  41. kasa/tests/test_cli.py +55 -8
  42. kasa/tests/test_device.py +16 -7
  43. kasa/tests/test_emeter.py +44 -16
  44. kasa/tests/test_feature.py +6 -2
  45. kasa/tests/test_httpclient.py +2 -2
  46. kasa/tests/test_iotdevice.py +14 -6
  47. kasa/tests/test_readme_examples.py +59 -0
  48. kasa/tests/test_smartdevice.py +4 -3
  49. kasa/tests/test_strip.py +15 -2
  50. kasa/xortransport.py +3 -3
  51. {python_kasa-0.7.0.dev4.dist-info → python_kasa-0.7.0.1.dist-info}/METADATA +102 -129
  52. {python_kasa-0.7.0.dev4.dist-info → python_kasa-0.7.0.1.dist-info}/RECORD +55 -53
  53. {python_kasa-0.7.0.dev4.dist-info → python_kasa-0.7.0.1.dist-info}/LICENSE +0 -0
  54. {python_kasa-0.7.0.dev4.dist-info → python_kasa-0.7.0.1.dist-info}/WHEEL +0 -0
  55. {python_kasa-0.7.0.dev4.dist-info → python_kasa-0.7.0.1.dist-info}/entry_points.txt +0 -0
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,
@@ -56,7 +57,15 @@ def runner():
56
57
  return runner
57
58
 
58
59
 
59
- async def test_update_called_by_cli(dev, mocker, runner):
60
+ @pytest.mark.parametrize(
61
+ ("device_family", "encrypt_type"),
62
+ [
63
+ pytest.param(None, None, id="No connect params"),
64
+ pytest.param("SMART.TAPOPLUG", None, id="Only device_family"),
65
+ pytest.param(None, "KLAP", id="Only encrypt_type"),
66
+ ],
67
+ )
68
+ async def test_update_called_by_cli(dev, mocker, runner, device_family, encrypt_type):
60
69
  """Test that device update is called on main."""
61
70
  update = mocker.patch.object(dev, "update")
62
71
 
@@ -75,6 +84,10 @@ async def test_update_called_by_cli(dev, mocker, runner):
75
84
  "foo",
76
85
  "--password",
77
86
  "bar",
87
+ "--device-family",
88
+ device_family,
89
+ "--encrypt-type",
90
+ encrypt_type,
78
91
  ],
79
92
  catch_exceptions=False,
80
93
  )
@@ -260,6 +273,37 @@ async def test_update_credentials(dev, runner):
260
273
  )
261
274
 
262
275
 
276
+ async def test_time_get(dev, runner):
277
+ """Test time get command."""
278
+ res = await runner.invoke(
279
+ time,
280
+ obj=dev,
281
+ )
282
+ assert res.exit_code == 0
283
+ assert "Current time: " in res.output
284
+
285
+
286
+ @device_smart
287
+ async def test_time_sync(dev, mocker, runner):
288
+ """Test time sync command.
289
+
290
+ Currently implemented only for SMART.
291
+ """
292
+ update = mocker.patch.object(dev, "update")
293
+ set_time_mock = mocker.spy(dev.modules[Module.Time], "set_time")
294
+ res = await runner.invoke(
295
+ time,
296
+ ["sync"],
297
+ obj=dev,
298
+ )
299
+ set_time_mock.assert_called()
300
+ update.assert_called()
301
+
302
+ assert res.exit_code == 0
303
+ assert "Old time: " in res.output
304
+ assert "New time: " in res.output
305
+
306
+
263
307
  async def test_emeter(dev: Device, mocker, runner):
264
308
  res = await runner.invoke(emeter, obj=dev)
265
309
  if not dev.has_emeter:
@@ -429,12 +473,12 @@ async def test_led(dev: Device, runner: CliRunner):
429
473
 
430
474
  async def test_json_output(dev: Device, mocker, runner):
431
475
  """Test that the json output produces correct output."""
432
- mocker.patch("kasa.Discover.discover", return_value={"127.0.0.1": dev})
433
- # These will mock the features to avoid accessing non-existing
476
+ mocker.patch("kasa.Discover.discover_single", return_value=dev)
477
+ # These will mock the features to avoid accessing non-existing ones
434
478
  mocker.patch("kasa.device.Device.features", return_value={})
435
479
  mocker.patch("kasa.iot.iotdevice.IotDevice.features", return_value={})
436
480
 
437
- res = await runner.invoke(cli, ["--json", "state"], obj=dev)
481
+ res = await runner.invoke(cli, ["--host", "127.0.0.1", "--json", "state"], obj=dev)
438
482
  assert res.exit_code == 0
439
483
  assert json.loads(res.output) == dev.internal_state
440
484
 
@@ -757,7 +801,7 @@ async def test_errors(mocker, runner):
757
801
  )
758
802
  assert res.exit_code == 1
759
803
  assert (
760
- "Raised error: Managed to invoke callback without a context object of type 'Device' existing."
804
+ "Only discover is available without --host or --alias"
761
805
  in res.output.replace("\n", "") # Remove newlines from rich formatting
762
806
  )
763
807
  assert isinstance(res.exception, SystemExit)
@@ -795,7 +839,10 @@ async def test_features_all(discovery_mock, mocker, runner):
795
839
  ["--host", "127.0.0.123", "--debug", "feature"],
796
840
  catch_exceptions=False,
797
841
  )
798
- assert "== Features ==" in res.output
842
+ assert "== Primary features ==" in res.output
843
+ assert "== Information ==" in res.output
844
+ assert "== Configuration ==" in res.output
845
+ assert "== Debug ==" in res.output
799
846
  assert res.exit_code == 0
800
847
 
801
848
 
@@ -828,7 +875,7 @@ async def test_feature_missing(mocker, runner):
828
875
  )
829
876
  assert "No feature by name 'missing'" in res.output
830
877
  assert "== Features ==" not in res.output
831
- assert res.exit_code == 0
878
+ assert res.exit_code == 1
832
879
 
833
880
 
834
881
  async def test_feature_set(mocker, runner):
@@ -846,7 +893,7 @@ async def test_feature_set(mocker, runner):
846
893
  )
847
894
 
848
895
  led_setter.assert_called_with(True)
849
- assert "Changing led from False to True" in res.output
896
+ assert "Changing led from True to True" in res.output
850
897
  assert res.exit_code == 0
851
898
 
852
899
 
kasa/tests/test_device.py CHANGED
@@ -6,6 +6,7 @@ import importlib
6
6
  import inspect
7
7
  import pkgutil
8
8
  import sys
9
+ from contextlib import AbstractContextManager
9
10
  from unittest.mock import Mock, patch
10
11
 
11
12
  import pytest
@@ -161,14 +162,9 @@ async def _test_attribute(
161
162
  dev: Device, attribute_name, is_expected, module_name, *args, will_raise=False
162
163
  ):
163
164
  if is_expected and will_raise:
164
- ctx = pytest.raises(will_raise)
165
+ ctx: AbstractContextManager = pytest.raises(will_raise)
165
166
  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
- )
167
+ ctx = pytest.deprecated_call(match=(f"{attribute_name} is deprecated, use:"))
172
168
  else:
173
169
  ctx = pytest.raises(
174
170
  AttributeError, match=f"Device has no attribute '{attribute_name}'"
@@ -239,6 +235,19 @@ async def test_deprecated_other_attributes(dev: Device):
239
235
 
240
236
  await _test_attribute(dev, "led", bool(led_module), "Led")
241
237
  await _test_attribute(dev, "set_led", bool(led_module), "Led", True)
238
+ await _test_attribute(dev, "supported_modules", True, None)
239
+
240
+
241
+ async def test_deprecated_emeter_attributes(dev: Device):
242
+ energy_module = dev.modules.get(Module.Energy)
243
+
244
+ await _test_attribute(dev, "get_emeter_realtime", bool(energy_module), "Energy")
245
+ await _test_attribute(dev, "emeter_realtime", bool(energy_module), "Energy")
246
+ await _test_attribute(dev, "emeter_today", bool(energy_module), "Energy")
247
+ await _test_attribute(dev, "emeter_this_month", bool(energy_module), "Energy")
248
+ await _test_attribute(dev, "current_consumption", bool(energy_module), "Energy")
249
+ await _test_attribute(dev, "get_emeter_daily", bool(energy_module), "Energy")
250
+ await _test_attribute(dev, "get_emeter_monthly", bool(energy_module), "Energy")
242
251
 
243
252
 
244
253
  async def test_deprecated_light_preset_attributes(dev: Device):
kasa/tests/test_emeter.py CHANGED
@@ -5,13 +5,14 @@ import pytest
5
5
  from voluptuous import (
6
6
  All,
7
7
  Any,
8
- Coerce, # type: ignore
8
+ Coerce,
9
9
  Range,
10
10
  Schema,
11
11
  )
12
12
 
13
- from kasa import EmeterStatus, KasaException
14
- from kasa.iot import IotDevice
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
@@ -20,14 +21,14 @@ CURRENT_CONSUMPTION_SCHEMA = Schema(
20
21
  Any(
21
22
  {
22
23
  "voltage": Any(All(float, Range(min=0, max=300)), None),
23
- "power": Any(Coerce(float, Range(min=0)), None),
24
- "total": Any(Coerce(float, Range(min=0)), None),
25
- "current": Any(All(float, Range(min=0)), None),
24
+ "power": Any(Coerce(float), None),
25
+ "total": Any(Coerce(float), None),
26
+ "current": Any(All(float), None),
26
27
  "voltage_mv": Any(All(float, Range(min=0, max=300000)), int, None),
27
- "power_mw": Any(Coerce(float, Range(min=0)), None),
28
- "total_wh": Any(Coerce(float, Range(min=0)), None),
29
- "current_ma": Any(All(float, Range(min=0)), int, None),
30
- "slot_id": Any(Coerce(int, Range(min=0)), None),
28
+ "power_mw": Any(Coerce(float), None),
29
+ "total_wh": Any(Coerce(float), None),
30
+ "current_ma": Any(All(float), int, None),
31
+ "slot_id": Any(Coerce(int), None),
31
32
  },
32
33
  None,
33
34
  )
@@ -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(KasaException):
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(KasaException):
47
+ with pytest.raises(AttributeError):
47
48
  await dev.get_emeter_daily()
48
- with pytest.raises(KasaException):
49
+ with pytest.raises(AttributeError):
49
50
  await dev.get_emeter_monthly()
50
- with pytest.raises(KasaException):
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 = await dev.current_consumption()
132
+ x = dev.current_consumption
132
133
  assert isinstance(x, float)
133
134
  assert x >= 0.0
134
135
  else:
135
- assert await dev.current_consumption() is None
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
@@ -44,8 +44,11 @@ def test_feature_api(dummy_feature: Feature):
44
44
  assert dummy_feature.unit == "dummyunit"
45
45
 
46
46
 
47
- def test_feature_missing_type():
48
- """Test that creating a feature with a setter but without type causes an error."""
47
+ @pytest.mark.parametrize(
48
+ "read_only_type", [Feature.Type.Sensor, Feature.Type.BinarySensor]
49
+ )
50
+ def test_feature_setter_on_sensor(read_only_type):
51
+ """Test that creating a sensor feature with a setter causes an error."""
49
52
  with pytest.raises(ValueError):
50
53
  Feature(
51
54
  device=DummyDevice(), # type: ignore[arg-type]
@@ -53,6 +56,7 @@ def test_feature_missing_type():
53
56
  name="dummy error",
54
57
  attribute_getter="dummygetter",
55
58
  attribute_setter="dummysetter",
59
+ type=read_only_type,
56
60
  )
57
61
 
58
62
 
@@ -38,7 +38,7 @@ from ..httpclient import HttpClient
38
38
  ),
39
39
  (Exception(), KasaException, "Unable to query the device: "),
40
40
  (
41
- aiohttp.ServerFingerprintMismatch("exp", "got", "host", 1),
41
+ aiohttp.ServerFingerprintMismatch(b"exp", b"got", "host", 1),
42
42
  KasaException,
43
43
  "Unable to query the device: ",
44
44
  ),
@@ -84,7 +84,7 @@ async def test_httpclient_errors(mocker, error, error_raises, error_message, moc
84
84
  client = HttpClient(DeviceConfig(host))
85
85
  # Exceptions with parameters print with double quotes, without use single quotes
86
86
  full_msg = (
87
- "\(" # type: ignore
87
+ re.escape("(")
88
88
  + "['\"]"
89
89
  + re.escape(f"{error_message}{host}: {error}")
90
90
  + "['\"]"
@@ -91,9 +91,10 @@ async def test_state_info(dev):
91
91
  @pytest.mark.requires_dummy
92
92
  @device_iot
93
93
  async def test_invalid_connection(mocker, dev):
94
- with mocker.patch.object(
95
- FakeIotProtocol, "query", side_effect=KasaException
96
- ), pytest.raises(KasaException):
94
+ with (
95
+ mocker.patch.object(FakeIotProtocol, "query", side_effect=KasaException),
96
+ pytest.raises(KasaException),
97
+ ):
97
98
  await dev.update()
98
99
 
99
100
 
@@ -116,9 +117,16 @@ async def test_initial_update_no_emeter(dev, mocker):
116
117
  dev._legacy_features = set()
117
118
  spy = mocker.spy(dev.protocol, "query")
118
119
  await dev.update()
119
- # 2 calls are necessary as some devices crash on unexpected modules
120
+ # child calls will happen if a child has a module with a query (e.g. schedule)
121
+ child_calls = 0
122
+ for child in dev.children:
123
+ for module in child.modules.values():
124
+ if module.query():
125
+ child_calls += 1
126
+ break
127
+ # 2 parent are necessary as some devices crash on unexpected modules
120
128
  # See #105, #120, #161
121
- assert spy.call_count == 2
129
+ assert spy.call_count == 2 + child_calls
122
130
 
123
131
 
124
132
  @device_iot
@@ -200,7 +208,7 @@ async def test_mac(dev):
200
208
 
201
209
  @device_iot
202
210
  async def test_representation(dev):
203
- pattern = re.compile("<DeviceType\..+ at .+? - .*? \(.+?\)>")
211
+ pattern = re.compile(r"<DeviceType\..+ at .+? - .*? \(.+?\)>")
204
212
  assert pattern.match(str(dev))
205
213
 
206
214
 
@@ -69,6 +69,7 @@ def test_discovery_examples(readmes_mock):
69
69
  """Test discovery examples."""
70
70
  res = xdoctest.doctest_module("kasa.discover", "all")
71
71
  assert res["n_passed"] > 0
72
+ assert res["n_warned"] == 0
72
73
  assert not res["failed"]
73
74
 
74
75
 
@@ -76,6 +77,63 @@ def test_deviceconfig_examples(readmes_mock):
76
77
  """Test discovery examples."""
77
78
  res = xdoctest.doctest_module("kasa.deviceconfig", "all")
78
79
  assert res["n_passed"] > 0
80
+ assert res["n_warned"] == 0
81
+ assert not res["failed"]
82
+
83
+
84
+ def test_device_examples(readmes_mock):
85
+ """Test device examples."""
86
+ res = xdoctest.doctest_module("kasa.device", "all")
87
+ assert res["n_passed"] > 0
88
+ assert res["n_warned"] == 0
89
+ assert not res["failed"]
90
+
91
+
92
+ def test_light_examples(readmes_mock):
93
+ """Test device examples."""
94
+ res = xdoctest.doctest_module("kasa.interfaces.light", "all")
95
+ assert res["n_passed"] > 0
96
+ assert res["n_warned"] == 0
97
+ assert not res["failed"]
98
+
99
+
100
+ def test_light_preset_examples(readmes_mock):
101
+ """Test device examples."""
102
+ res = xdoctest.doctest_module("kasa.interfaces.lightpreset", "all")
103
+ assert res["n_passed"] > 0
104
+ assert res["n_warned"] == 0
105
+ assert not res["failed"]
106
+
107
+
108
+ def test_light_effect_examples(readmes_mock):
109
+ """Test device examples."""
110
+ res = xdoctest.doctest_module("kasa.interfaces.lighteffect", "all")
111
+ assert res["n_passed"] > 0
112
+ assert res["n_warned"] == 0
113
+ assert not res["failed"]
114
+
115
+
116
+ def test_child_examples(readmes_mock):
117
+ """Test device examples."""
118
+ res = xdoctest.doctest_module("kasa.smart.modules.childdevice", "all")
119
+ assert res["n_passed"] > 0
120
+ assert res["n_warned"] == 0
121
+ assert not res["failed"]
122
+
123
+
124
+ def test_module_examples(readmes_mock):
125
+ """Test device examples."""
126
+ res = xdoctest.doctest_module("kasa.module", "all")
127
+ assert res["n_passed"] > 0
128
+ assert res["n_warned"] == 0
129
+ assert not res["failed"]
130
+
131
+
132
+ def test_feature_examples(readmes_mock):
133
+ """Test device examples."""
134
+ res = xdoctest.doctest_module("kasa.feature", "all")
135
+ assert res["n_passed"] > 0
136
+ assert res["n_warned"] == 0
79
137
  assert not res["failed"]
80
138
 
81
139
 
@@ -83,6 +141,7 @@ def test_tutorial_examples(readmes_mock):
83
141
  """Test discovery examples."""
84
142
  res = xdoctest.doctest_module("docs/tutorial.py", "all")
85
143
  assert res["n_passed"] > 0
144
+ assert res["n_warned"] == 0
86
145
  assert not res["failed"]
87
146
 
88
147
 
@@ -38,9 +38,10 @@ async def test_update_no_device_info(dev: SmartDevice, mocker: MockerFixture):
38
38
  "get_device_time": {},
39
39
  }
40
40
  msg = f"get_device_info not found in {mock_response} for device 127.0.0.123"
41
- with mocker.patch.object(
42
- dev.protocol, "query", return_value=mock_response
43
- ), pytest.raises(KasaException, match=msg):
41
+ with (
42
+ mocker.patch.object(dev.protocol, "query", return_value=mock_response),
43
+ pytest.raises(KasaException, match=msg),
44
+ ):
44
45
  await dev.update()
45
46
 
46
47
 
kasa/tests/test_strip.py CHANGED
@@ -2,10 +2,10 @@ from datetime import datetime
2
2
 
3
3
  import pytest
4
4
 
5
- from kasa import KasaException
5
+ from kasa import Device, KasaException, Module
6
6
  from kasa.iot import IotStrip
7
7
 
8
- from .conftest import handle_turn_on, strip, turn_on
8
+ from .conftest import handle_turn_on, strip, strip_iot, turn_on
9
9
 
10
10
 
11
11
  @strip
@@ -147,3 +147,16 @@ def test_children_api(dev):
147
147
  first = dev.children[0]
148
148
  first_by_get_child_device = dev.get_child_device(first.device_id)
149
149
  assert first == first_by_get_child_device
150
+
151
+
152
+ @strip_iot
153
+ async def test_children_energy(dev: Device):
154
+ if Module.Energy not in dev.modules:
155
+ pytest.skip(f"skipping device {dev.model} does not support energy")
156
+
157
+ for plug in dev.children:
158
+ # For now all known strips with energy support these
159
+ energy = plug.modules[Module.Energy]
160
+ assert "voltage" in energy._module_features
161
+ assert "current" in energy._module_features
162
+ assert "current_consumption" in energy._module_features
kasa/xortransport.py CHANGED
@@ -18,8 +18,8 @@ import errno
18
18
  import logging
19
19
  import socket
20
20
  import struct
21
+ from collections.abc import Generator
21
22
  from pprint import pformat as pf
22
- from typing import Generator
23
23
 
24
24
  # When support for cpython older than 3.11 is dropped
25
25
  # async_timeout can be replaced with asyncio.timeout
@@ -229,7 +229,7 @@ class XorEncryption:
229
229
  try:
230
230
  from kasa_crypt import decrypt, encrypt
231
231
 
232
- XorEncryption.decrypt = decrypt # type: ignore[method-assign]
233
- XorEncryption.encrypt = encrypt # type: ignore[method-assign]
232
+ XorEncryption.decrypt = decrypt # type: ignore[assignment]
233
+ XorEncryption.encrypt = encrypt # type: ignore[assignment]
234
234
  except ImportError:
235
235
  pass