python-kasa 0.7.0.dev1__py3-none-any.whl → 0.7.0.dev3__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 (47) hide show
  1. kasa/__init__.py +16 -9
  2. kasa/aestransport.py +3 -4
  3. kasa/cli.py +13 -11
  4. kasa/device.py +26 -3
  5. kasa/deviceconfig.py +45 -20
  6. kasa/discover.py +106 -46
  7. kasa/feature.py +2 -1
  8. kasa/httpclient.py +24 -0
  9. kasa/iot/iotdevice.py +1 -1
  10. kasa/iot/iotlightstrip.py +3 -2
  11. kasa/iot/iotplug.py +1 -1
  12. kasa/iot/iotstrip.py +30 -1
  13. kasa/iot/modules/lighteffect.py +13 -7
  14. kasa/iot/modules/lightpreset.py +6 -1
  15. kasa/smart/modules/autooff.py +13 -8
  16. kasa/smart/modules/fan.py +3 -2
  17. kasa/smartprotocol.py +3 -1
  18. kasa/tests/device_fixtures.py +10 -1
  19. kasa/tests/discovery_fixtures.py +82 -29
  20. kasa/tests/fakeprotocol_iot.py +36 -7
  21. kasa/tests/fixtures/HS110(EU)_1.0_1.2.5.json +1 -1
  22. kasa/tests/fixtures/HS110(US)_1.0_1.2.6.json +37 -0
  23. kasa/tests/fixtures/HS220(US)_1.0_1.5.7.json +1 -1
  24. kasa/tests/fixtures/HS220(US)_2.0_1.0.3.json +1 -1
  25. kasa/tests/fixtures/HS300(US)_1.0_1.0.21.json +89 -0
  26. kasa/tests/fixtures/KL120(US)_1.0_1.8.11.json +85 -0
  27. kasa/tests/fixtures/KL430(US)_1.0_1.0.10.json +51 -12
  28. kasa/tests/fixtures/KP303(UK)_1.0_1.0.3.json +1 -1
  29. kasa/tests/fixtures/smart/L530E(EU)_3.0_1.1.6.json +1 -1
  30. kasa/tests/fixtures/smart/P115(EU)_1.0_1.2.3.json +386 -0
  31. kasa/tests/fixtures/smart/S505D(US)_1.0_1.1.0.json +262 -0
  32. kasa/tests/smart/modules/test_autooff.py +103 -0
  33. kasa/tests/smart/modules/test_fan.py +5 -0
  34. kasa/tests/test_aestransport.py +90 -2
  35. kasa/tests/test_bulb.py +9 -4
  36. kasa/tests/test_common_modules.py +1 -1
  37. kasa/tests/test_device.py +28 -6
  38. kasa/tests/test_device_factory.py +8 -8
  39. kasa/tests/test_discovery.py +61 -4
  40. kasa/tests/test_readme_examples.py +37 -22
  41. kasa/tests/test_smartprotocol.py +3 -2
  42. kasa/tests/test_strip.py +8 -0
  43. {python_kasa-0.7.0.dev1.dist-info → python_kasa-0.7.0.dev3.dist-info}/METADATA +4 -4
  44. {python_kasa-0.7.0.dev1.dist-info → python_kasa-0.7.0.dev3.dist-info}/RECORD +47 -41
  45. {python_kasa-0.7.0.dev1.dist-info → python_kasa-0.7.0.dev3.dist-info}/LICENSE +0 -0
  46. {python_kasa-0.7.0.dev1.dist-info → python_kasa-0.7.0.dev3.dist-info}/WHEEL +0 -0
  47. {python_kasa-0.7.0.dev1.dist-info → python_kasa-0.7.0.dev3.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,262 @@
1
+ {
2
+ "component_nego": {
3
+ "component_list": [
4
+ {
5
+ "id": "device",
6
+ "ver_code": 2
7
+ },
8
+ {
9
+ "id": "firmware",
10
+ "ver_code": 2
11
+ },
12
+ {
13
+ "id": "quick_setup",
14
+ "ver_code": 3
15
+ },
16
+ {
17
+ "id": "inherit",
18
+ "ver_code": 1
19
+ },
20
+ {
21
+ "id": "time",
22
+ "ver_code": 1
23
+ },
24
+ {
25
+ "id": "wireless",
26
+ "ver_code": 1
27
+ },
28
+ {
29
+ "id": "schedule",
30
+ "ver_code": 2
31
+ },
32
+ {
33
+ "id": "countdown",
34
+ "ver_code": 2
35
+ },
36
+ {
37
+ "id": "antitheft",
38
+ "ver_code": 1
39
+ },
40
+ {
41
+ "id": "account",
42
+ "ver_code": 1
43
+ },
44
+ {
45
+ "id": "synchronize",
46
+ "ver_code": 1
47
+ },
48
+ {
49
+ "id": "sunrise_sunset",
50
+ "ver_code": 1
51
+ },
52
+ {
53
+ "id": "led",
54
+ "ver_code": 1
55
+ },
56
+ {
57
+ "id": "cloud_connect",
58
+ "ver_code": 1
59
+ },
60
+ {
61
+ "id": "iot_cloud",
62
+ "ver_code": 1
63
+ },
64
+ {
65
+ "id": "device_local_time",
66
+ "ver_code": 1
67
+ },
68
+ {
69
+ "id": "default_states",
70
+ "ver_code": 1
71
+ },
72
+ {
73
+ "id": "brightness",
74
+ "ver_code": 1
75
+ },
76
+ {
77
+ "id": "preset",
78
+ "ver_code": 1
79
+ },
80
+ {
81
+ "id": "on_off_gradually",
82
+ "ver_code": 2
83
+ },
84
+ {
85
+ "id": "dimmer_calibration",
86
+ "ver_code": 1
87
+ },
88
+ {
89
+ "id": "localSmart",
90
+ "ver_code": 1
91
+ },
92
+ {
93
+ "id": "overheat_protection",
94
+ "ver_code": 1
95
+ },
96
+ {
97
+ "id": "matter",
98
+ "ver_code": 2
99
+ }
100
+ ]
101
+ },
102
+ "discovery_result": {
103
+ "device_id": "00000000000000000000000000000000",
104
+ "device_model": "S505D(US)",
105
+ "device_type": "SMART.TAPOSWITCH",
106
+ "factory_default": false,
107
+ "ip": "127.0.0.123",
108
+ "is_support_iot_cloud": true,
109
+ "mac": "48-22-54-00-00-00",
110
+ "mgt_encrypt_schm": {
111
+ "encrypt_type": "KLAP",
112
+ "http_port": 80,
113
+ "is_support_https": false,
114
+ "lv": 2
115
+ },
116
+ "obd_src": "matter",
117
+ "owner": "00000000000000000000000000000000"
118
+ },
119
+ "get_antitheft_rules": {
120
+ "antitheft_rule_max_count": 1,
121
+ "enable": false,
122
+ "rule_list": []
123
+ },
124
+ "get_auto_update_info": {
125
+ "enable": true,
126
+ "random_range": 120,
127
+ "time": 180
128
+ },
129
+ "get_connect_cloud_state": {
130
+ "status": 1
131
+ },
132
+ "get_countdown_rules": {
133
+ "countdown_rule_max_count": 1,
134
+ "enable": false,
135
+ "rule_list": []
136
+ },
137
+ "get_device_info": {
138
+ "avatar": "switch_s500d",
139
+ "brightness": 100,
140
+ "default_states": {
141
+ "re_power_type": "always_off",
142
+ "re_power_type_capability": [
143
+ "last_states",
144
+ "always_on",
145
+ "always_off"
146
+ ],
147
+ "type": "last_states"
148
+ },
149
+ "device_id": "0000000000000000000000000000000000000000",
150
+ "device_on": false,
151
+ "fw_id": "00000000000000000000000000000000",
152
+ "fw_ver": "1.1.0 Build 231024 Rel.201030",
153
+ "has_set_location_info": false,
154
+ "hw_id": "00000000000000000000000000000000",
155
+ "hw_ver": "1.0",
156
+ "ip": "127.0.0.123",
157
+ "lang": "en_US",
158
+ "latitude": 0,
159
+ "longitude": 0,
160
+ "mac": "48-22-54-00-00-00",
161
+ "model": "S505D",
162
+ "nickname": "I01BU0tFRF9OQU1FIw==",
163
+ "oem_id": "00000000000000000000000000000000",
164
+ "on_time": 0,
165
+ "overheat_status": "normal",
166
+ "region": "America/Chicago",
167
+ "rssi": -39,
168
+ "signal_level": 3,
169
+ "specs": "",
170
+ "ssid": "I01BU0tFRF9TU0lEIw==",
171
+ "time_diff": -360,
172
+ "type": "SMART.TAPOSWITCH"
173
+ },
174
+ "get_device_time": {
175
+ "region": "America/Chicago",
176
+ "time_diff": -360,
177
+ "timestamp": 952082825
178
+ },
179
+ "get_fw_download_state": {
180
+ "auto_upgrade": false,
181
+ "download_progress": 0,
182
+ "reboot_time": 5,
183
+ "status": 0,
184
+ "upgrade_time": 5
185
+ },
186
+ "get_inherit_info": null,
187
+ "get_led_info": {
188
+ "led_rule": "always",
189
+ "led_status": true,
190
+ "night_mode": {
191
+ "end_time": 420,
192
+ "night_mode_type": "sunrise_sunset",
193
+ "start_time": 1140,
194
+ "sunrise_offset": 0,
195
+ "sunset_offset": 0
196
+ }
197
+ },
198
+ "get_matter_setup_info": {
199
+ "setup_code": "00000000000",
200
+ "setup_payload": "00:-00000000000000.000"
201
+ },
202
+ "get_next_event": {},
203
+ "get_preset_rules": {
204
+ "brightness": [
205
+ 100,
206
+ 75,
207
+ 50,
208
+ 25,
209
+ 1
210
+ ]
211
+ },
212
+ "get_schedule_rules": {
213
+ "enable": false,
214
+ "rule_list": [],
215
+ "schedule_rule_max_count": 32,
216
+ "start_index": 0,
217
+ "sum": 0
218
+ },
219
+ "get_wireless_scan_info": {
220
+ "ap_list": [],
221
+ "start_index": 0,
222
+ "sum": 0,
223
+ "wep_supported": false
224
+ },
225
+ "qs_component_nego": {
226
+ "component_list": [
227
+ {
228
+ "id": "quick_setup",
229
+ "ver_code": 3
230
+ },
231
+ {
232
+ "id": "sunrise_sunset",
233
+ "ver_code": 1
234
+ },
235
+ {
236
+ "id": "ble_whole_setup",
237
+ "ver_code": 1
238
+ },
239
+ {
240
+ "id": "matter",
241
+ "ver_code": 2
242
+ },
243
+ {
244
+ "id": "iot_cloud",
245
+ "ver_code": 1
246
+ },
247
+ {
248
+ "id": "inherit",
249
+ "ver_code": 1
250
+ },
251
+ {
252
+ "id": "firmware",
253
+ "ver_code": 2
254
+ }
255
+ ],
256
+ "extra_info": {
257
+ "device_model": "S505D",
258
+ "device_type": "SMART.TAPOSWITCH",
259
+ "is_klap": true
260
+ }
261
+ }
262
+ }
@@ -0,0 +1,103 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+ from datetime import datetime
5
+ from typing import Optional
6
+
7
+ import pytest
8
+ from pytest_mock import MockerFixture
9
+
10
+ from kasa import Module
11
+ from kasa.smart import SmartDevice
12
+ from kasa.tests.device_fixtures import parametrize
13
+
14
+ autooff = parametrize(
15
+ "has autooff", component_filter="auto_off", protocol_filter={"SMART"}
16
+ )
17
+
18
+
19
+ @autooff
20
+ @pytest.mark.parametrize(
21
+ "feature, prop_name, type",
22
+ [
23
+ ("auto_off_enabled", "enabled", bool),
24
+ ("auto_off_minutes", "delay", int),
25
+ ("auto_off_at", "auto_off_at", Optional[datetime]),
26
+ ],
27
+ )
28
+ @pytest.mark.skipif(
29
+ sys.version_info < (3, 10),
30
+ reason="Subscripted generics cannot be used with class and instance checks",
31
+ )
32
+ async def test_autooff_features(
33
+ dev: SmartDevice, feature: str, prop_name: str, type: type
34
+ ):
35
+ """Test that features are registered and work as expected."""
36
+ autooff = dev.modules.get(Module.AutoOff)
37
+ assert autooff is not None
38
+
39
+ prop = getattr(autooff, prop_name)
40
+ assert isinstance(prop, type)
41
+
42
+ feat = dev.features[feature]
43
+ assert feat.value == prop
44
+ assert isinstance(feat.value, type)
45
+
46
+
47
+ @autooff
48
+ async def test_settings(dev: SmartDevice, mocker: MockerFixture):
49
+ """Test autooff settings."""
50
+ autooff = dev.modules.get(Module.AutoOff)
51
+ assert autooff
52
+
53
+ enabled = dev.features["auto_off_enabled"]
54
+ assert autooff.enabled == enabled.value
55
+
56
+ delay = dev.features["auto_off_minutes"]
57
+ assert autooff.delay == delay.value
58
+
59
+ call = mocker.spy(autooff, "call")
60
+ new_state = True
61
+
62
+ await autooff.set_enabled(new_state)
63
+ call.assert_called_with(
64
+ "set_auto_off_config", {"enable": new_state, "delay_min": delay.value}
65
+ )
66
+ call.reset_mock()
67
+ await dev.update()
68
+
69
+ new_delay = 123
70
+
71
+ await autooff.set_delay(new_delay)
72
+
73
+ call.assert_called_with(
74
+ "set_auto_off_config", {"enable": new_state, "delay_min": new_delay}
75
+ )
76
+
77
+ await dev.update()
78
+
79
+ assert autooff.enabled == new_state
80
+ assert autooff.delay == new_delay
81
+
82
+
83
+ @autooff
84
+ @pytest.mark.parametrize("is_timer_active", [True, False])
85
+ async def test_auto_off_at(
86
+ dev: SmartDevice, mocker: MockerFixture, is_timer_active: bool
87
+ ):
88
+ """Test auto-off at sensor."""
89
+ autooff = dev.modules.get(Module.AutoOff)
90
+ assert autooff
91
+
92
+ autooff_at = dev.features["auto_off_at"]
93
+
94
+ mocker.patch.object(
95
+ type(autooff),
96
+ "is_timer_active",
97
+ new_callable=mocker.PropertyMock,
98
+ return_value=is_timer_active,
99
+ )
100
+ if is_timer_active:
101
+ assert isinstance(autooff_at.value, datetime)
102
+ else:
103
+ assert autooff_at.value is None
@@ -64,6 +64,11 @@ async def test_fan_module(dev: SmartDevice, mocker: MockerFixture):
64
64
  assert fan.fan_speed_level == 1
65
65
  assert device.is_on
66
66
 
67
+ # Check that if the device is off the speed level is 0.
68
+ await device.set_state(False)
69
+ await dev.update()
70
+ assert fan.fan_speed_level == 0
71
+
67
72
  await fan.set_fan_speed_level(4)
68
73
  await dev.update()
69
74
  assert fan.fan_speed_level == 4
@@ -15,6 +15,7 @@ import aiohttp
15
15
  import pytest
16
16
  from cryptography.hazmat.primitives import serialization
17
17
  from cryptography.hazmat.primitives.asymmetric import padding as asymmetric_padding
18
+ from freezegun.api import FrozenDateTimeFactory
18
19
  from yarl import URL
19
20
 
20
21
  from ..aestransport import AesEncyptionSession, AesTransport, TransportState
@@ -24,6 +25,7 @@ from ..exceptions import (
24
25
  AuthenticationError,
25
26
  KasaException,
26
27
  SmartErrorCode,
28
+ _ConnectionError,
27
29
  )
28
30
  from ..httpclient import HttpClient
29
31
 
@@ -137,7 +139,7 @@ async def test_login_errors(mocker, inner_error_codes, expectation, call_count):
137
139
  transport._state = TransportState.LOGIN_REQUIRED
138
140
  transport._session_expire_at = time.time() + 86400
139
141
  transport._encryption_session = mock_aes_device.encryption_session
140
- mocker.patch.object(transport, "BACKOFF_SECONDS_AFTER_LOGIN_ERROR", 0)
142
+ mocker.patch.object(transport._http_client, "WAIT_BETWEEN_REQUESTS_ON_OSERROR", 0)
141
143
 
142
144
  assert transport._token_url is None
143
145
 
@@ -285,6 +287,79 @@ async def test_port_override():
285
287
  assert str(transport._app_url) == "http://127.0.0.1:12345/app"
286
288
 
287
289
 
290
+ @pytest.mark.parametrize(
291
+ "device_delay_required, should_error, should_succeed",
292
+ [
293
+ pytest.param(0, False, True, id="No error"),
294
+ pytest.param(0.125, True, True, id="Error then succeed"),
295
+ pytest.param(0.3, True, True, id="Two errors then succeed"),
296
+ pytest.param(0.7, True, False, id="No succeed"),
297
+ ],
298
+ )
299
+ async def test_device_closes_connection(
300
+ mocker,
301
+ freezer: FrozenDateTimeFactory,
302
+ device_delay_required,
303
+ should_error,
304
+ should_succeed,
305
+ ):
306
+ """Test the delay logic in http client to deal with devices that close connections after each request.
307
+
308
+ Currently only the P100 on older firmware.
309
+ """
310
+ host = "127.0.0.1"
311
+
312
+ default_delay = HttpClient.WAIT_BETWEEN_REQUESTS_ON_OSERROR
313
+
314
+ mock_aes_device = MockAesDevice(
315
+ host, 200, 0, 0, sequential_request_delay=device_delay_required
316
+ )
317
+ mocker.patch.object(aiohttp.ClientSession, "post", side_effect=mock_aes_device.post)
318
+
319
+ async def _asyncio_sleep_mock(delay, result=None):
320
+ freezer.tick(delay)
321
+ return result
322
+
323
+ mocker.patch("asyncio.sleep", side_effect=_asyncio_sleep_mock)
324
+
325
+ config = DeviceConfig(host, credentials=Credentials("foo", "bar"))
326
+ transport = AesTransport(config=config)
327
+ transport._http_client.WAIT_BETWEEN_REQUESTS_ON_OSERROR = default_delay
328
+ transport._state = TransportState.LOGIN_REQUIRED
329
+ transport._session_expire_at = time.time() + 86400
330
+ transport._encryption_session = mock_aes_device.encryption_session
331
+ transport._token_url = transport._app_url.with_query(
332
+ f"token={mock_aes_device.token}"
333
+ )
334
+ request = {
335
+ "method": "get_device_info",
336
+ "params": None,
337
+ "request_time_milis": round(time.time() * 1000),
338
+ "requestID": 1,
339
+ "terminal_uuid": "foobar",
340
+ }
341
+ error_count = 0
342
+ success = False
343
+
344
+ # If the device errors without a delay then it should error immedately ( + 1)
345
+ # and then the number of times the default delay passes within the request delay window
346
+ expected_error_count = (
347
+ 0 if not should_error else int(device_delay_required / default_delay) + 1
348
+ )
349
+ for _ in range(3):
350
+ try:
351
+ await transport.send(json_dumps(request))
352
+ except _ConnectionError:
353
+ error_count += 1
354
+ else:
355
+ success = True
356
+
357
+ assert bool(transport._http_client._wait_between_requests) == should_error
358
+ assert bool(error_count) == should_error
359
+ assert error_count == expected_error_count
360
+ assert success == should_succeed
361
+
362
+
288
363
  class MockAesDevice:
289
364
  class _mock_response:
290
365
  def __init__(self, status, json: dict):
@@ -313,6 +388,7 @@ class MockAesDevice:
313
388
  *,
314
389
  do_not_encrypt_response=False,
315
390
  send_response=None,
391
+ sequential_request_delay=0,
316
392
  ):
317
393
  self.host = host
318
394
  self.status_code = status_code
@@ -323,6 +399,9 @@ class MockAesDevice:
323
399
  self.http_client = HttpClient(DeviceConfig(self.host))
324
400
  self.inner_call_count = 0
325
401
  self.token = "".join(random.choices(string.ascii_uppercase, k=32)) # noqa: S311
402
+ self.sequential_request_delay = sequential_request_delay
403
+ self.last_request_time = None
404
+ self.sequential_error_raised = False
326
405
 
327
406
  @property
328
407
  def inner_error_code(self):
@@ -332,10 +411,19 @@ class MockAesDevice:
332
411
  return self._inner_error_code
333
412
 
334
413
  async def post(self, url: URL, params=None, json=None, data=None, *_, **__):
414
+ if self.sequential_request_delay and self.last_request_time:
415
+ now = time.time()
416
+ print(now - self.last_request_time)
417
+ if (now - self.last_request_time) < self.sequential_request_delay:
418
+ self.sequential_error_raised = True
419
+ raise aiohttp.ClientOSError("Test connection closed")
335
420
  if data:
336
421
  async for item in data:
337
422
  json = json_loads(item.decode())
338
- return await self._post(url, json)
423
+ res = await self._post(url, json)
424
+ if self.sequential_request_delay:
425
+ self.last_request_time = time.time()
426
+ return res
339
427
 
340
428
  async def _post(self, url: URL, json: dict[str, Any]):
341
429
  if json["method"] == "handshake":
kasa/tests/test_bulb.py CHANGED
@@ -283,12 +283,17 @@ async def test_ignore_default_not_set_without_color_mode_change_turn_on(
283
283
  @bulb_iot
284
284
  async def test_list_presets(dev: IotBulb):
285
285
  presets = dev.presets
286
- assert len(presets) == len(dev.sys_info["preferred_state"])
287
-
288
- for preset, raw in zip(presets, dev.sys_info["preferred_state"]):
286
+ # Light strip devices may list some light effects along with normal presets but these
287
+ # are handled by the LightEffect module so exclude preferred states with id
288
+ raw_presets = [
289
+ pstate for pstate in dev.sys_info["preferred_state"] if "id" not in pstate
290
+ ]
291
+ assert len(presets) == len(raw_presets)
292
+
293
+ for preset, raw in zip(presets, raw_presets):
289
294
  assert preset.index == raw["index"]
290
- assert preset.hue == raw["hue"]
291
295
  assert preset.brightness == raw["brightness"]
296
+ assert preset.hue == raw["hue"]
292
297
  assert preset.saturation == raw["saturation"]
293
298
  assert preset.color_temp == raw["color_temp"]
294
299
 
@@ -78,7 +78,7 @@ async def test_light_effect_module(dev: Device, mocker: MockerFixture):
78
78
  assert light_effect_module
79
79
  feat = dev.features["light_effect"]
80
80
 
81
- call = mocker.spy(light_effect_module, "call")
81
+ call = mocker.spy(dev, "_query_helper")
82
82
  effect_list = light_effect_module.effect_list
83
83
  assert "Off" in effect_list
84
84
  assert effect_list.index("Off") == 0
kasa/tests/test_device.py CHANGED
@@ -116,13 +116,11 @@ def test_deprecated_devices(device_class, use_class):
116
116
  getattr(module, use_class.__name__)
117
117
 
118
118
 
119
- @pytest.mark.parametrize(
120
- "exceptions_class, use_class", kasa.deprecated_exceptions.items()
121
- )
122
- def test_deprecated_exceptions(exceptions_class, use_class):
123
- msg = f"{exceptions_class} is deprecated, use {use_class.__name__} instead"
119
+ @pytest.mark.parametrize("deprecated_class, use_class", kasa.deprecated_classes.items())
120
+ def test_deprecated_classes(deprecated_class, use_class):
121
+ msg = f"{deprecated_class} is deprecated, use {use_class.__name__} instead"
124
122
  with pytest.deprecated_call(match=msg):
125
- getattr(kasa, exceptions_class)
123
+ getattr(kasa, deprecated_class)
126
124
  getattr(kasa, use_class.__name__)
127
125
 
128
126
 
@@ -266,3 +264,27 @@ async def test_deprecated_light_preset_attributes(dev: Device):
266
264
  IotLightPreset(index=0, hue=100, brightness=100, saturation=0, color_temp=0), # type: ignore[call-arg]
267
265
  will_raise=exc,
268
266
  )
267
+
268
+
269
+ async def test_device_type_aliases():
270
+ """Test that the device type aliases in Device work."""
271
+
272
+ def _mock_connect(config, *args, **kwargs):
273
+ mock = Mock()
274
+ mock.config = config
275
+ return mock
276
+
277
+ with patch("kasa.device_factory.connect", side_effect=_mock_connect):
278
+ dev = await Device.connect(
279
+ config=Device.Config(
280
+ host="127.0.0.1",
281
+ credentials=Device.Credentials(username="user", password="foobar"), # noqa: S106
282
+ connection_type=Device.ConnectionParameters(
283
+ device_family=Device.Family.SmartKasaPlug,
284
+ encryption_type=Device.EncryptionType.Klap,
285
+ login_version=2,
286
+ ),
287
+ )
288
+ )
289
+ assert isinstance(dev.config, DeviceConfig)
290
+ assert DeviceType.Dimmer == Device.Type.Dimmer
@@ -17,10 +17,10 @@ from kasa.device_factory import (
17
17
  get_protocol,
18
18
  )
19
19
  from kasa.deviceconfig import (
20
- ConnectionType,
21
20
  DeviceConfig,
22
- DeviceFamilyType,
23
- EncryptType,
21
+ DeviceConnectionParameters,
22
+ DeviceEncryptionType,
23
+ DeviceFamily,
24
24
  )
25
25
  from kasa.discover import DiscoveryResult
26
26
  from kasa.smart.smartdevice import SmartDevice
@@ -31,12 +31,12 @@ def _get_connection_type_device_class(discovery_info):
31
31
  device_class = Discover._get_device_class(discovery_info)
32
32
  dr = DiscoveryResult(**discovery_info["result"])
33
33
 
34
- connection_type = ConnectionType.from_values(
34
+ connection_type = DeviceConnectionParameters.from_values(
35
35
  dr.device_type, dr.mgt_encrypt_schm.encrypt_type
36
36
  )
37
37
  else:
38
- connection_type = ConnectionType.from_values(
39
- DeviceFamilyType.IotSmartPlugSwitch.value, EncryptType.Xor.value
38
+ connection_type = DeviceConnectionParameters.from_values(
39
+ DeviceFamily.IotSmartPlugSwitch.value, DeviceEncryptionType.Xor.value
40
40
  )
41
41
  device_class = Discover._get_device_class(discovery_info)
42
42
 
@@ -137,7 +137,7 @@ async def test_connect_http_client(discovery_data, mocker):
137
137
  host=host, credentials=Credentials("foor", "bar"), connection_type=ctype
138
138
  )
139
139
  dev = await connect(config=config)
140
- if ctype.encryption_type != EncryptType.Xor:
140
+ if ctype.encryption_type != DeviceEncryptionType.Xor:
141
141
  assert dev.protocol._transport._http_client.client != http_client
142
142
  await dev.disconnect()
143
143
 
@@ -148,7 +148,7 @@ async def test_connect_http_client(discovery_data, mocker):
148
148
  http_client=http_client,
149
149
  )
150
150
  dev = await connect(config=config)
151
- if ctype.encryption_type != EncryptType.Xor:
151
+ if ctype.encryption_type != DeviceEncryptionType.Xor:
152
152
  assert dev.protocol._transport._http_client.client == http_client
153
153
  await dev.disconnect()
154
154
  await http_client.close()