python-kasa 0.7.0.dev4__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.
@@ -0,0 +1,350 @@
1
+ {
2
+ "component_nego": {
3
+ "component_list": [
4
+ {
5
+ "id": "device",
6
+ "ver_code": 2
7
+ },
8
+ {
9
+ "id": "light_strip",
10
+ "ver_code": 1
11
+ },
12
+ {
13
+ "id": "light_strip_lighting_effect",
14
+ "ver_code": 1
15
+ },
16
+ {
17
+ "id": "firmware",
18
+ "ver_code": 1
19
+ },
20
+ {
21
+ "id": "quick_setup",
22
+ "ver_code": 3
23
+ },
24
+ {
25
+ "id": "inherit",
26
+ "ver_code": 1
27
+ },
28
+ {
29
+ "id": "time",
30
+ "ver_code": 1
31
+ },
32
+ {
33
+ "id": "wireless",
34
+ "ver_code": 1
35
+ },
36
+ {
37
+ "id": "schedule",
38
+ "ver_code": 2
39
+ },
40
+ {
41
+ "id": "countdown",
42
+ "ver_code": 2
43
+ },
44
+ {
45
+ "id": "antitheft",
46
+ "ver_code": 1
47
+ },
48
+ {
49
+ "id": "account",
50
+ "ver_code": 1
51
+ },
52
+ {
53
+ "id": "synchronize",
54
+ "ver_code": 1
55
+ },
56
+ {
57
+ "id": "sunrise_sunset",
58
+ "ver_code": 1
59
+ },
60
+ {
61
+ "id": "brightness",
62
+ "ver_code": 1
63
+ },
64
+ {
65
+ "id": "cloud_connect",
66
+ "ver_code": 1
67
+ },
68
+ {
69
+ "id": "color_temperature",
70
+ "ver_code": 1
71
+ },
72
+ {
73
+ "id": "default_states",
74
+ "ver_code": 1
75
+ },
76
+ {
77
+ "id": "preset",
78
+ "ver_code": 3
79
+ },
80
+ {
81
+ "id": "color",
82
+ "ver_code": 1
83
+ },
84
+ {
85
+ "id": "on_off_gradually",
86
+ "ver_code": 1
87
+ },
88
+ {
89
+ "id": "device_local_time",
90
+ "ver_code": 1
91
+ },
92
+ {
93
+ "id": "iot_cloud",
94
+ "ver_code": 1
95
+ },
96
+ {
97
+ "id": "music_rhythm",
98
+ "ver_code": 2
99
+ },
100
+ {
101
+ "id": "segment",
102
+ "ver_code": 1
103
+ }
104
+ ]
105
+ },
106
+ "discovery_result": {
107
+ "device_id": "00000000000000000000000000000000",
108
+ "device_model": "L920-5(EU)",
109
+ "device_type": "SMART.TAPOBULB",
110
+ "factory_default": true,
111
+ "ip": "127.0.0.123",
112
+ "is_support_iot_cloud": true,
113
+ "mac": "1C-61-B4-00-00-00",
114
+ "mgt_encrypt_schm": {
115
+ "encrypt_type": "AES",
116
+ "http_port": 80,
117
+ "is_support_https": false
118
+ },
119
+ "obd_src": "tplink",
120
+ "owner": ""
121
+ },
122
+ "get_antitheft_rules": {
123
+ "antitheft_rule_max_count": 1,
124
+ "enable": false,
125
+ "rule_list": []
126
+ },
127
+ "get_auto_update_info": {
128
+ "enable": true,
129
+ "random_range": 120,
130
+ "time": 180
131
+ },
132
+ "get_connect_cloud_state": {
133
+ "status": 1
134
+ },
135
+ "get_countdown_rules": {
136
+ "countdown_rule_max_count": 1,
137
+ "enable": false,
138
+ "rule_list": []
139
+ },
140
+ "get_device_info": {
141
+ "avatar": "",
142
+ "brightness": 100,
143
+ "color_temp": 9000,
144
+ "color_temp_range": [
145
+ 9000,
146
+ 9000
147
+ ],
148
+ "default_states": {
149
+ "state": {
150
+ "brightness": 100,
151
+ "color_temp": 9000,
152
+ "hue": 0,
153
+ "saturation": 100
154
+ },
155
+ "type": "last_states"
156
+ },
157
+ "device_id": "0000000000000000000000000000000000000000",
158
+ "device_on": true,
159
+ "fw_id": "00000000000000000000000000000000",
160
+ "fw_ver": "1.0.7 Build 220119 Rel.221439",
161
+ "has_set_location_info": false,
162
+ "hue": 0,
163
+ "hw_id": "00000000000000000000000000000000",
164
+ "hw_ver": "1.0",
165
+ "ip": "127.0.0.123",
166
+ "lang": "",
167
+ "latitude": 0,
168
+ "lighting_effect": {
169
+ "brightness": 0,
170
+ "custom": 0,
171
+ "display_colors": [],
172
+ "enable": 1,
173
+ "id": "",
174
+ "name": "softAP"
175
+ },
176
+ "longitude": 0,
177
+ "mac": "1C-61-B4-00-00-00",
178
+ "model": "L920",
179
+ "music_rhythm_enable": false,
180
+ "music_rhythm_mode": "single_lamp",
181
+ "nickname": "I01BU0tFRF9OQU1FIw==",
182
+ "oem_id": "00000000000000000000000000000000",
183
+ "overheated": false,
184
+ "region": "",
185
+ "rssi": -46,
186
+ "saturation": 100,
187
+ "signal_level": 3,
188
+ "specs": "",
189
+ "ssid": "I01BU0tFRF9TU0lEIw==",
190
+ "time_diff": 0,
191
+ "type": "SMART.TAPOBULB"
192
+ },
193
+ "get_device_segment": {
194
+ "segment": 50
195
+ },
196
+ "get_device_time": {
197
+ "region": "",
198
+ "time_diff": 0,
199
+ "timestamp": 946771372
200
+ },
201
+ "get_fw_download_state": {
202
+ "download_progress": 0,
203
+ "reboot_time": 5,
204
+ "status": 0,
205
+ "upgrade_time": 5
206
+ },
207
+ "get_inherit_info": null,
208
+ "get_lighting_effect": {
209
+ "brightness": 0,
210
+ "custom": 0,
211
+ "direction": 1,
212
+ "display_colors": [],
213
+ "duration": 0,
214
+ "enable": 1,
215
+ "expansion_strategy": 0,
216
+ "id": "",
217
+ "name": "softAP",
218
+ "repeat_times": 0,
219
+ "segment_length": 1,
220
+ "sequence": [
221
+ [
222
+ 30,
223
+ 100,
224
+ 0
225
+ ],
226
+ [
227
+ 30,
228
+ 100,
229
+ 50
230
+ ],
231
+ [
232
+ 30,
233
+ 100,
234
+ 0
235
+ ],
236
+ [
237
+ 120,
238
+ 100,
239
+ 0
240
+ ],
241
+ [
242
+ 120,
243
+ 100,
244
+ 50
245
+ ],
246
+ [
247
+ 120,
248
+ 100,
249
+ 0
250
+ ]
251
+ ],
252
+ "spread": 8,
253
+ "transition": 400,
254
+ "type": "sequence"
255
+ },
256
+ "get_next_event": {},
257
+ "get_on_off_gradually_info": {
258
+ "enable": false
259
+ },
260
+ "get_preset_rules": {
261
+ "start_index": 0,
262
+ "states": [
263
+ {
264
+ "brightness": 50,
265
+ "color_temp": 9000,
266
+ "hue": 0,
267
+ "saturation": 100
268
+ },
269
+ {
270
+ "brightness": 100,
271
+ "color_temp": 0,
272
+ "hue": 240,
273
+ "saturation": 100
274
+ },
275
+ {
276
+ "brightness": 100,
277
+ "color_temp": 0,
278
+ "hue": 0,
279
+ "saturation": 100
280
+ },
281
+ {
282
+ "brightness": 100,
283
+ "color_temp": 0,
284
+ "hue": 120,
285
+ "saturation": 100
286
+ },
287
+ {
288
+ "brightness": 100,
289
+ "color_temp": 0,
290
+ "hue": 277,
291
+ "saturation": 86
292
+ },
293
+ {
294
+ "brightness": 100,
295
+ "color_temp": 0,
296
+ "hue": 60,
297
+ "saturation": 100
298
+ },
299
+ {
300
+ "brightness": 100,
301
+ "color_temp": 0,
302
+ "hue": 300,
303
+ "saturation": 100
304
+ }
305
+ ],
306
+ "sum": 7
307
+ },
308
+ "get_schedule_rules": {
309
+ "enable": false,
310
+ "rule_list": [],
311
+ "schedule_rule_max_count": 24,
312
+ "start_index": 0,
313
+ "sum": 0
314
+ },
315
+ "get_wireless_scan_info": {
316
+ "ap_list": [
317
+ {
318
+ "bssid": "000000000000",
319
+ "channel": 0,
320
+ "cipher_type": 2,
321
+ "key_type": "wpa2_psk",
322
+ "signal_level": 2,
323
+ "ssid": "I01BU0tFRF9TU0lEIw=="
324
+ }
325
+ ],
326
+ "start_index": 0,
327
+ "sum": 1,
328
+ "wep_supported": false
329
+ },
330
+ "qs_component_nego": {
331
+ "component_list": [
332
+ {
333
+ "id": "quick_setup",
334
+ "ver_code": 3
335
+ },
336
+ {
337
+ "id": "sunrise_sunset",
338
+ "ver_code": 1
339
+ },
340
+ {
341
+ "id": "inherit",
342
+ "ver_code": 1
343
+ }
344
+ ],
345
+ "extra_info": {
346
+ "device_model": "L920",
347
+ "device_type": "SMART.TAPOBULB"
348
+ }
349
+ }
350
+ }
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.discover", return_value={"127.0.0.1": dev})
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
- "Raised error: Managed to invoke callback without a context object of type 'Device' existing."
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 == 0
863
+ assert res.exit_code == 1
832
864
 
833
865
 
834
866
  async def test_feature_set(mocker, runner):
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, 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
@@ -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
@@ -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
- # 2 calls are necessary as some devices crash on unexpected modules
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-kasa
3
- Version: 0.7.0.dev4
3
+ Version: 0.7.0.dev5
4
4
  Summary: Python API for TP-Link Kasa Smarthome devices
5
5
  Home-page: https://github.com/python-kasa/python-kasa
6
6
  License: GPL-3.0-or-later