python-kasa 0.9.0__py3-none-any.whl → 0.9.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.
- kasa/cli/discover.py +1 -1
- kasa/exceptions.py +1 -0
- kasa/feature.py +2 -0
- kasa/protocols/iotprotocol.py +14 -0
- kasa/protocols/smartcamprotocol.py +11 -6
- kasa/protocols/smartprotocol.py +24 -8
- kasa/smart/smartchilddevice.py +1 -0
- kasa/smartcam/modules/babycrydetection.py +1 -1
- kasa/smartcam/modules/motiondetection.py +1 -1
- kasa/smartcam/modules/persondetection.py +1 -1
- kasa/smartcam/modules/tamperdetection.py +1 -1
- kasa/transports/klaptransport.py +8 -5
- kasa/transports/sslaestransport.py +149 -15
- kasa/transports/xortransport.py +13 -0
- {python_kasa-0.9.0.dist-info → python_kasa-0.9.1.dist-info}/METADATA +2 -2
- {python_kasa-0.9.0.dist-info → python_kasa-0.9.1.dist-info}/RECORD +19 -19
- {python_kasa-0.9.0.dist-info → python_kasa-0.9.1.dist-info}/WHEEL +0 -0
- {python_kasa-0.9.0.dist-info → python_kasa-0.9.1.dist-info}/entry_points.txt +0 -0
- {python_kasa-0.9.0.dist-info → python_kasa-0.9.1.dist-info}/licenses/LICENSE +0 -0
kasa/cli/discover.py
CHANGED
|
@@ -283,7 +283,7 @@ def _echo_discovery_info(discovery_info) -> None:
|
|
|
283
283
|
_conditional_echo("HW Ver", dr.hw_ver)
|
|
284
284
|
_conditional_echo("HW Ver", dr.hardware_version)
|
|
285
285
|
_conditional_echo("Supports IOT Cloud", dr.is_support_iot_cloud)
|
|
286
|
-
_conditional_echo("OBD Src", dr.
|
|
286
|
+
_conditional_echo("OBD Src", dr.obd_src)
|
|
287
287
|
_conditional_echo("Factory Default", dr.factory_default)
|
|
288
288
|
_conditional_echo("Encrypt Type", dr.encrypt_type)
|
|
289
289
|
if mgt_encrypt_schm := dr.mgt_encrypt_schm:
|
kasa/exceptions.py
CHANGED
kasa/feature.py
CHANGED
|
@@ -295,6 +295,8 @@ class Feature:
|
|
|
295
295
|
if self.precision_hint is not None and isinstance(value, float):
|
|
296
296
|
value = round(value, self.precision_hint)
|
|
297
297
|
|
|
298
|
+
if isinstance(value, Enum):
|
|
299
|
+
value = repr(value)
|
|
298
300
|
s = f"{self.name} ({self.id}): {value}"
|
|
299
301
|
if self.unit is not None:
|
|
300
302
|
s += f" {self.unit}"
|
kasa/protocols/iotprotocol.py
CHANGED
|
@@ -98,12 +98,26 @@ class IotProtocol(BaseProtocol):
|
|
|
98
98
|
)
|
|
99
99
|
raise auex
|
|
100
100
|
except _RetryableError as ex:
|
|
101
|
+
if retry == 0:
|
|
102
|
+
_LOGGER.debug(
|
|
103
|
+
"Device %s got a retryable error, will retry %s times: %s",
|
|
104
|
+
self._host,
|
|
105
|
+
retry_count,
|
|
106
|
+
ex,
|
|
107
|
+
)
|
|
101
108
|
await self._transport.reset()
|
|
102
109
|
if retry >= retry_count:
|
|
103
110
|
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
|
|
104
111
|
raise ex
|
|
105
112
|
continue
|
|
106
113
|
except TimeoutError as ex:
|
|
114
|
+
if retry == 0:
|
|
115
|
+
_LOGGER.debug(
|
|
116
|
+
"Device %s got a timeout error, will retry %s times: %s",
|
|
117
|
+
self._host,
|
|
118
|
+
retry_count,
|
|
119
|
+
ex,
|
|
120
|
+
)
|
|
107
121
|
await self._transport.reset()
|
|
108
122
|
if retry >= retry_count:
|
|
109
123
|
_LOGGER.debug("Giving up on %s after %s retries", self._host, retry)
|
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import logging
|
|
6
6
|
from dataclasses import dataclass
|
|
7
7
|
from pprint import pformat as pf
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any, cast
|
|
9
9
|
|
|
10
10
|
from ..exceptions import (
|
|
11
11
|
AuthenticationError,
|
|
@@ -49,10 +49,13 @@ class SingleRequest:
|
|
|
49
49
|
class SmartCamProtocol(SmartProtocol):
|
|
50
50
|
"""Class for SmartCam Protocol."""
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
self,
|
|
54
|
-
) ->
|
|
55
|
-
|
|
52
|
+
def _get_list_request(
|
|
53
|
+
self, method: str, params: dict | None, start_index: int
|
|
54
|
+
) -> dict:
|
|
55
|
+
# All smartcam requests have params
|
|
56
|
+
params = cast(dict, params)
|
|
57
|
+
module_name = next(iter(params))
|
|
58
|
+
return {method: {module_name: {"start_index": start_index}}}
|
|
56
59
|
|
|
57
60
|
def _handle_response_error_code(
|
|
58
61
|
self, resp_dict: dict, method: str, raise_on_error: bool = True
|
|
@@ -147,7 +150,9 @@ class SmartCamProtocol(SmartProtocol):
|
|
|
147
150
|
if len(request) == 1 and method in {"get", "set", "do", "multipleRequest"}:
|
|
148
151
|
single_request = self._get_smart_camera_single_request(request)
|
|
149
152
|
else:
|
|
150
|
-
return await self._execute_multiple_query(
|
|
153
|
+
return await self._execute_multiple_query(
|
|
154
|
+
request, retry_count, iterate_list_pages
|
|
155
|
+
)
|
|
151
156
|
else:
|
|
152
157
|
single_request = self._make_smart_camera_single_request(request)
|
|
153
158
|
|
kasa/protocols/smartprotocol.py
CHANGED
|
@@ -180,7 +180,9 @@ class SmartProtocol(BaseProtocol):
|
|
|
180
180
|
# make mypy happy, this should never be reached..
|
|
181
181
|
raise KasaException("Query reached somehow to unreachable")
|
|
182
182
|
|
|
183
|
-
async def _execute_multiple_query(
|
|
183
|
+
async def _execute_multiple_query(
|
|
184
|
+
self, requests: dict, retry_count: int, iterate_list_pages: bool
|
|
185
|
+
) -> dict:
|
|
184
186
|
debug_enabled = _LOGGER.isEnabledFor(logging.DEBUG)
|
|
185
187
|
multi_result: dict[str, Any] = {}
|
|
186
188
|
smart_method = "multipleRequest"
|
|
@@ -275,9 +277,11 @@ class SmartProtocol(BaseProtocol):
|
|
|
275
277
|
response, method, raise_on_error=raise_on_error
|
|
276
278
|
)
|
|
277
279
|
result = response.get("result", None)
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
280
|
+
request_params = rp if (rp := requests.get(method)) else None
|
|
281
|
+
if iterate_list_pages and result:
|
|
282
|
+
await self._handle_response_lists(
|
|
283
|
+
result, method, request_params, retry_count=retry_count
|
|
284
|
+
)
|
|
281
285
|
multi_result[method] = result
|
|
282
286
|
|
|
283
287
|
# Multi requests don't continue after errors so requery any missing.
|
|
@@ -303,7 +307,9 @@ class SmartProtocol(BaseProtocol):
|
|
|
303
307
|
smart_method = next(iter(request))
|
|
304
308
|
smart_params = request[smart_method]
|
|
305
309
|
else:
|
|
306
|
-
return await self._execute_multiple_query(
|
|
310
|
+
return await self._execute_multiple_query(
|
|
311
|
+
request, retry_count, iterate_list_pages
|
|
312
|
+
)
|
|
307
313
|
else:
|
|
308
314
|
smart_method = request
|
|
309
315
|
smart_params = None
|
|
@@ -330,12 +336,21 @@ class SmartProtocol(BaseProtocol):
|
|
|
330
336
|
result = response_data.get("result")
|
|
331
337
|
if iterate_list_pages and result:
|
|
332
338
|
await self._handle_response_lists(
|
|
333
|
-
result, smart_method, retry_count=retry_count
|
|
339
|
+
result, smart_method, smart_params, retry_count=retry_count
|
|
334
340
|
)
|
|
335
341
|
return {smart_method: result}
|
|
336
342
|
|
|
343
|
+
def _get_list_request(
|
|
344
|
+
self, method: str, params: dict | None, start_index: int
|
|
345
|
+
) -> dict:
|
|
346
|
+
return {method: {"start_index": start_index}}
|
|
347
|
+
|
|
337
348
|
async def _handle_response_lists(
|
|
338
|
-
self,
|
|
349
|
+
self,
|
|
350
|
+
response_result: dict[str, Any],
|
|
351
|
+
method: str,
|
|
352
|
+
params: dict | None,
|
|
353
|
+
retry_count: int,
|
|
339
354
|
) -> None:
|
|
340
355
|
if (
|
|
341
356
|
response_result is None
|
|
@@ -355,8 +370,9 @@ class SmartProtocol(BaseProtocol):
|
|
|
355
370
|
)
|
|
356
371
|
)
|
|
357
372
|
while (list_length := len(response_result[response_list_name])) < list_sum:
|
|
373
|
+
request = self._get_list_request(method, params, list_length)
|
|
358
374
|
response = await self._execute_query(
|
|
359
|
-
|
|
375
|
+
request,
|
|
360
376
|
retry_count=retry_count,
|
|
361
377
|
iterate_list_pages=False,
|
|
362
378
|
)
|
kasa/smart/smartchilddevice.py
CHANGED
|
@@ -24,6 +24,7 @@ class SmartChildDevice(SmartDevice):
|
|
|
24
24
|
|
|
25
25
|
CHILD_DEVICE_TYPE_MAP = {
|
|
26
26
|
"plug.powerstrip.sub-plug": DeviceType.Plug,
|
|
27
|
+
"subg.plugswitch.switch": DeviceType.WallSwitch,
|
|
27
28
|
"subg.trigger.contact-sensor": DeviceType.Sensor,
|
|
28
29
|
"subg.trigger.temp-hmdt-sensor": DeviceType.Sensor,
|
|
29
30
|
"subg.trigger.water-leak-sensor": DeviceType.Sensor,
|
kasa/transports/klaptransport.py
CHANGED
|
@@ -214,8 +214,8 @@ class KlapTransport(BaseTransport):
|
|
|
214
214
|
|
|
215
215
|
if default_credentials_seed_auth_hash == server_hash:
|
|
216
216
|
_LOGGER.debug(
|
|
217
|
-
"
|
|
218
|
-
"but an authentication with %s default credentials
|
|
217
|
+
"Device response did not match our expected hash on ip %s,"
|
|
218
|
+
"but an authentication with %s default credentials worked",
|
|
219
219
|
self._host,
|
|
220
220
|
key,
|
|
221
221
|
)
|
|
@@ -235,13 +235,16 @@ class KlapTransport(BaseTransport):
|
|
|
235
235
|
|
|
236
236
|
if blank_seed_auth_hash == server_hash:
|
|
237
237
|
_LOGGER.debug(
|
|
238
|
-
"
|
|
239
|
-
"but an authentication with blank credentials
|
|
238
|
+
"Device response did not match our expected hash on ip %s, "
|
|
239
|
+
"but an authentication with blank credentials worked",
|
|
240
240
|
self._host,
|
|
241
241
|
)
|
|
242
242
|
return local_seed, remote_seed, self._blank_auth_hash # type: ignore
|
|
243
243
|
|
|
244
|
-
msg =
|
|
244
|
+
msg = (
|
|
245
|
+
f"Device response did not match our challenge on ip {self._host}, "
|
|
246
|
+
f"check that your e-mail and password (both case-sensitive) are correct. "
|
|
247
|
+
)
|
|
245
248
|
_LOGGER.debug(msg)
|
|
246
249
|
raise AuthenticationError(msg)
|
|
247
250
|
|
|
@@ -126,6 +126,7 @@ class SslAesTransport(BaseTransport):
|
|
|
126
126
|
self._password = ch["pwd"]
|
|
127
127
|
self._username = ch["un"]
|
|
128
128
|
self._local_nonce: str | None = None
|
|
129
|
+
self._send_secure = True
|
|
129
130
|
|
|
130
131
|
_LOGGER.debug("Created AES transport for %s", self._host)
|
|
131
132
|
|
|
@@ -162,7 +163,13 @@ class SslAesTransport(BaseTransport):
|
|
|
162
163
|
return error_code
|
|
163
164
|
|
|
164
165
|
def _get_response_inner_error(self, resp_dict: Any) -> SmartErrorCode | None:
|
|
166
|
+
# Device blocked errors have 'data' element at the root level, other inner
|
|
167
|
+
# errors are inside 'result'
|
|
165
168
|
error_code_raw = resp_dict.get("data", {}).get("code")
|
|
169
|
+
|
|
170
|
+
if error_code_raw is None:
|
|
171
|
+
error_code_raw = resp_dict.get("result", {}).get("data", {}).get("code")
|
|
172
|
+
|
|
166
173
|
if error_code_raw is None:
|
|
167
174
|
return None
|
|
168
175
|
try:
|
|
@@ -208,6 +215,10 @@ class SslAesTransport(BaseTransport):
|
|
|
208
215
|
else:
|
|
209
216
|
url = self._app_url
|
|
210
217
|
|
|
218
|
+
_LOGGER.debug(
|
|
219
|
+
"Sending secure passthrough from %s",
|
|
220
|
+
self._host,
|
|
221
|
+
)
|
|
211
222
|
encrypted_payload = self._encryption_session.encrypt(request.encode()) # type: ignore
|
|
212
223
|
passthrough_request = {
|
|
213
224
|
"method": "securePassthrough",
|
|
@@ -292,6 +303,34 @@ class SslAesTransport(BaseTransport):
|
|
|
292
303
|
) from ex
|
|
293
304
|
return ret_val # type: ignore[return-value]
|
|
294
305
|
|
|
306
|
+
async def send_unencrypted(self, request: str) -> dict[str, Any]:
|
|
307
|
+
"""Send encrypted message as passthrough."""
|
|
308
|
+
url = cast(URL, self._token_url)
|
|
309
|
+
|
|
310
|
+
_LOGGER.debug(
|
|
311
|
+
"Sending unencrypted to %s",
|
|
312
|
+
self._host,
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
status_code, resp_dict = await self._http_client.post(
|
|
316
|
+
url,
|
|
317
|
+
json=request,
|
|
318
|
+
headers=self._headers,
|
|
319
|
+
ssl=await self._get_ssl_context(),
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
if status_code != 200:
|
|
323
|
+
raise KasaException(
|
|
324
|
+
f"{self._host} responded with an unexpected "
|
|
325
|
+
+ f"status code {status_code} to unencrypted send"
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
self._handle_response_error_code(resp_dict, "Error sending message")
|
|
329
|
+
|
|
330
|
+
if TYPE_CHECKING:
|
|
331
|
+
resp_dict = cast(dict[str, Any], resp_dict)
|
|
332
|
+
return resp_dict
|
|
333
|
+
|
|
295
334
|
@staticmethod
|
|
296
335
|
def generate_confirm_hash(
|
|
297
336
|
local_nonce: str, server_nonce: str, pwd_hash: str
|
|
@@ -340,8 +379,50 @@ class SslAesTransport(BaseTransport):
|
|
|
340
379
|
|
|
341
380
|
async def perform_handshake(self) -> None:
|
|
342
381
|
"""Perform the handshake."""
|
|
343
|
-
|
|
344
|
-
|
|
382
|
+
result = await self.perform_handshake1()
|
|
383
|
+
if result:
|
|
384
|
+
local_nonce, server_nonce, pwd_hash = result
|
|
385
|
+
await self.perform_handshake2(local_nonce, server_nonce, pwd_hash)
|
|
386
|
+
|
|
387
|
+
async def try_perform_less_secure_login(self, username: str, password: str) -> bool:
|
|
388
|
+
"""Perform the md5 login."""
|
|
389
|
+
_LOGGER.debug("Performing less secure login...")
|
|
390
|
+
|
|
391
|
+
pwd_hash = _md5_hash(password.encode())
|
|
392
|
+
body = {
|
|
393
|
+
"method": "login",
|
|
394
|
+
"params": {
|
|
395
|
+
"hashed": True,
|
|
396
|
+
"password": pwd_hash,
|
|
397
|
+
"username": username,
|
|
398
|
+
},
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
status_code, resp_dict = await self._http_client.post(
|
|
402
|
+
self._app_url,
|
|
403
|
+
json=body,
|
|
404
|
+
headers=self._headers,
|
|
405
|
+
ssl=await self._get_ssl_context(),
|
|
406
|
+
)
|
|
407
|
+
if status_code != 200:
|
|
408
|
+
raise KasaException(
|
|
409
|
+
f"{self._host} responded with an unexpected "
|
|
410
|
+
+ f"status code {status_code} to login"
|
|
411
|
+
)
|
|
412
|
+
resp_dict = cast(dict, resp_dict)
|
|
413
|
+
if resp_dict.get("error_code") == 0 and (
|
|
414
|
+
stok := resp_dict.get("result", {}).get("stok")
|
|
415
|
+
):
|
|
416
|
+
_LOGGER.debug(
|
|
417
|
+
"Succesfully logged in to %s with less secure passthrough", self._host
|
|
418
|
+
)
|
|
419
|
+
self._send_secure = False
|
|
420
|
+
self._token_url = URL(f"{str(self._app_url)}/stok={stok}/ds")
|
|
421
|
+
self._pwd_hash = pwd_hash
|
|
422
|
+
return True
|
|
423
|
+
|
|
424
|
+
_LOGGER.debug("Unable to log in to %s with less secure login", self._host)
|
|
425
|
+
return False
|
|
345
426
|
|
|
346
427
|
async def perform_handshake2(
|
|
347
428
|
self, local_nonce: str, server_nonce: str, pwd_hash: str
|
|
@@ -393,13 +474,50 @@ class SslAesTransport(BaseTransport):
|
|
|
393
474
|
self._state = TransportState.ESTABLISHED
|
|
394
475
|
_LOGGER.debug("Handshake2 complete ...")
|
|
395
476
|
|
|
396
|
-
|
|
477
|
+
def _pwd_to_hash(self) -> str:
|
|
478
|
+
"""Return the password to hash."""
|
|
479
|
+
if self._credentials and self._credentials != Credentials():
|
|
480
|
+
return self._credentials.password
|
|
481
|
+
|
|
482
|
+
if self._username and self._password:
|
|
483
|
+
return self._password
|
|
484
|
+
|
|
485
|
+
return self._default_credentials.password
|
|
486
|
+
|
|
487
|
+
def _is_less_secure_login(self, resp_dict: dict[str, Any]) -> bool:
|
|
488
|
+
result = (
|
|
489
|
+
self._get_response_error(resp_dict) is SmartErrorCode.SESSION_EXPIRED
|
|
490
|
+
and (data := resp_dict.get("result", {}).get("data", {}))
|
|
491
|
+
and (encrypt_type := data.get("encrypt_type"))
|
|
492
|
+
and (encrypt_type != ["3"])
|
|
493
|
+
)
|
|
494
|
+
if result:
|
|
495
|
+
_LOGGER.debug(
|
|
496
|
+
"Received encrypt_type %s for %s, trying less secure login",
|
|
497
|
+
encrypt_type,
|
|
498
|
+
self._host,
|
|
499
|
+
)
|
|
500
|
+
return result
|
|
501
|
+
|
|
502
|
+
async def perform_handshake1(self) -> tuple[str, str, str] | None:
|
|
397
503
|
"""Perform the handshake1."""
|
|
398
504
|
resp_dict = None
|
|
399
505
|
if self._username:
|
|
400
506
|
local_nonce = secrets.token_bytes(8).hex().upper()
|
|
401
507
|
resp_dict = await self.try_send_handshake1(self._username, local_nonce)
|
|
402
508
|
|
|
509
|
+
if (
|
|
510
|
+
resp_dict
|
|
511
|
+
and self._is_less_secure_login(resp_dict)
|
|
512
|
+
and self._get_response_inner_error(resp_dict)
|
|
513
|
+
is not SmartErrorCode.BAD_USERNAME
|
|
514
|
+
and await self.try_perform_less_secure_login(
|
|
515
|
+
cast(str, self._username), self._pwd_to_hash()
|
|
516
|
+
)
|
|
517
|
+
):
|
|
518
|
+
self._state = TransportState.ESTABLISHED
|
|
519
|
+
return None
|
|
520
|
+
|
|
403
521
|
# Try the default username. If it fails raise the original error_code
|
|
404
522
|
if (
|
|
405
523
|
not resp_dict
|
|
@@ -407,19 +525,30 @@ class SslAesTransport(BaseTransport):
|
|
|
407
525
|
is not SmartErrorCode.INVALID_NONCE
|
|
408
526
|
or "nonce" not in resp_dict["result"].get("data", {})
|
|
409
527
|
):
|
|
528
|
+
_LOGGER.debug("Trying default credentials to %s", self._host)
|
|
410
529
|
local_nonce = secrets.token_bytes(8).hex().upper()
|
|
411
530
|
default_resp_dict = await self.try_send_handshake1(
|
|
412
531
|
self._default_credentials.username, local_nonce
|
|
413
532
|
)
|
|
533
|
+
# INVALID_NONCE means device should perform secure login
|
|
414
534
|
if (
|
|
415
535
|
default_error_code := self._get_response_error(default_resp_dict)
|
|
416
536
|
) is SmartErrorCode.INVALID_NONCE and "nonce" in default_resp_dict[
|
|
417
537
|
"result"
|
|
418
538
|
].get("data", {}):
|
|
419
|
-
_LOGGER.debug("Connected to
|
|
539
|
+
_LOGGER.debug("Connected to %s with default username", self._host)
|
|
420
540
|
self._username = self._default_credentials.username
|
|
421
541
|
error_code = default_error_code
|
|
422
542
|
resp_dict = default_resp_dict
|
|
543
|
+
# Otherwise could be less secure login
|
|
544
|
+
elif self._is_less_secure_login(
|
|
545
|
+
default_resp_dict
|
|
546
|
+
) and await self.try_perform_less_secure_login(
|
|
547
|
+
self._default_credentials.username, self._pwd_to_hash()
|
|
548
|
+
):
|
|
549
|
+
self._username = self._default_credentials.username
|
|
550
|
+
self._state = TransportState.ESTABLISHED
|
|
551
|
+
return None
|
|
423
552
|
|
|
424
553
|
# If the default login worked it's ok not to provide credentials but if
|
|
425
554
|
# it didn't raise auth error here.
|
|
@@ -451,12 +580,8 @@ class SslAesTransport(BaseTransport):
|
|
|
451
580
|
|
|
452
581
|
server_nonce = resp_dict["result"]["data"]["nonce"]
|
|
453
582
|
device_confirm = resp_dict["result"]["data"]["device_confirm"]
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
elif self._username and self._password:
|
|
457
|
-
pwd_hash = _sha256_hash(self._password.encode())
|
|
458
|
-
else:
|
|
459
|
-
pwd_hash = _sha256_hash(self._default_credentials.password.encode())
|
|
583
|
+
|
|
584
|
+
pwd_hash = _sha256_hash(self._pwd_to_hash().encode())
|
|
460
585
|
|
|
461
586
|
expected_confirm_sha256 = self.generate_confirm_hash(
|
|
462
587
|
local_nonce, server_nonce, pwd_hash
|
|
@@ -468,7 +593,9 @@ class SslAesTransport(BaseTransport):
|
|
|
468
593
|
if TYPE_CHECKING:
|
|
469
594
|
assert self._credentials
|
|
470
595
|
assert self._credentials.password
|
|
471
|
-
|
|
596
|
+
|
|
597
|
+
pwd_hash = _md5_hash(self._pwd_to_hash().encode())
|
|
598
|
+
|
|
472
599
|
expected_confirm_md5 = self.generate_confirm_hash(
|
|
473
600
|
local_nonce, server_nonce, pwd_hash
|
|
474
601
|
)
|
|
@@ -476,13 +603,17 @@ class SslAesTransport(BaseTransport):
|
|
|
476
603
|
_LOGGER.debug("Credentials match")
|
|
477
604
|
return local_nonce, server_nonce, pwd_hash
|
|
478
605
|
|
|
479
|
-
msg =
|
|
606
|
+
msg = (
|
|
607
|
+
f"Device response did not match our challenge on ip {self._host}, "
|
|
608
|
+
f"check that your e-mail and password (both case-sensitive) are correct. "
|
|
609
|
+
)
|
|
480
610
|
_LOGGER.debug(msg)
|
|
611
|
+
|
|
481
612
|
raise AuthenticationError(msg)
|
|
482
613
|
|
|
483
614
|
async def try_send_handshake1(self, username: str, local_nonce: str) -> dict:
|
|
484
615
|
"""Perform the handshake."""
|
|
485
|
-
_LOGGER.debug("
|
|
616
|
+
_LOGGER.debug("Sending handshake1...")
|
|
486
617
|
|
|
487
618
|
body = {
|
|
488
619
|
"method": "login",
|
|
@@ -501,7 +632,7 @@ class SslAesTransport(BaseTransport):
|
|
|
501
632
|
ssl=await self._get_ssl_context(),
|
|
502
633
|
)
|
|
503
634
|
|
|
504
|
-
_LOGGER.debug("Device responded with: %s", resp_dict)
|
|
635
|
+
_LOGGER.debug("Device responded with status %s: %s", status_code, resp_dict)
|
|
505
636
|
|
|
506
637
|
if status_code != 200:
|
|
507
638
|
raise KasaException(
|
|
@@ -516,7 +647,10 @@ class SslAesTransport(BaseTransport):
|
|
|
516
647
|
if self._state is TransportState.HANDSHAKE_REQUIRED:
|
|
517
648
|
await self.perform_handshake()
|
|
518
649
|
|
|
519
|
-
|
|
650
|
+
if self._send_secure:
|
|
651
|
+
return await self.send_secure_passthrough(request)
|
|
652
|
+
|
|
653
|
+
return await self.send_unencrypted(request)
|
|
520
654
|
|
|
521
655
|
async def close(self) -> None:
|
|
522
656
|
"""Close the http client and reset internal state."""
|
kasa/transports/xortransport.py
CHANGED
|
@@ -23,6 +23,7 @@ from collections.abc import Generator
|
|
|
23
23
|
|
|
24
24
|
from kasa.deviceconfig import DeviceConfig
|
|
25
25
|
from kasa.exceptions import KasaException, _RetryableError
|
|
26
|
+
from kasa.exceptions import TimeoutError as KasaTimeoutError
|
|
26
27
|
from kasa.json import loads as json_loads
|
|
27
28
|
|
|
28
29
|
from .basetransport import BaseTransport
|
|
@@ -126,6 +127,12 @@ class XorTransport(BaseTransport):
|
|
|
126
127
|
# This is especially import when there are multiple tplink devices being polled.
|
|
127
128
|
try:
|
|
128
129
|
await self._connect(self._timeout)
|
|
130
|
+
except TimeoutError as ex:
|
|
131
|
+
await self.reset()
|
|
132
|
+
raise KasaTimeoutError(
|
|
133
|
+
f"Timeout after {self._timeout} seconds connecting to the device:"
|
|
134
|
+
f" {self._host}:{self._port}: {ex}"
|
|
135
|
+
) from ex
|
|
129
136
|
except ConnectionRefusedError as ex:
|
|
130
137
|
await self.reset()
|
|
131
138
|
raise KasaException(
|
|
@@ -159,6 +166,12 @@ class XorTransport(BaseTransport):
|
|
|
159
166
|
assert self.writer is not None # noqa: S101
|
|
160
167
|
async with asyncio_timeout(self._timeout):
|
|
161
168
|
return await self._execute_send(request)
|
|
169
|
+
except TimeoutError as ex:
|
|
170
|
+
await self.reset()
|
|
171
|
+
raise KasaTimeoutError(
|
|
172
|
+
f"Timeout after {self._timeout} seconds sending request to the device"
|
|
173
|
+
f" {self._host}:{self._port}: {ex}"
|
|
174
|
+
) from ex
|
|
162
175
|
except Exception as ex:
|
|
163
176
|
await self.reset()
|
|
164
177
|
raise _RetryableError(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-kasa
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Summary: Python API for TP-Link Kasa and Tapo devices
|
|
5
5
|
Project-URL: Homepage, https://github.com/python-kasa/python-kasa
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/python-kasa/python-kasa/issues
|
|
@@ -235,7 +235,7 @@ The following devices have been tested and confirmed as working. If your device
|
|
|
235
235
|
|
|
236
236
|
- **Plugs**: P100, P110, P110M, P115, P125M, P135, TP15
|
|
237
237
|
- **Power Strips**: P210M, P300, P304M, P306, TP25
|
|
238
|
-
- **Wall Switches**: S500D, S505, S505D
|
|
238
|
+
- **Wall Switches**: S210, S220, S500D, S505, S505D
|
|
239
239
|
- **Bulbs**: L510B, L510E, L530E, L630
|
|
240
240
|
- **Light Strips**: L900-10, L900-5, L920-5, L930-5
|
|
241
241
|
- **Cameras**: C100, C210, C225, C325WB, C520WS, TC65, TC70
|
|
@@ -7,8 +7,8 @@ kasa/device_type.py,sha256=gI0tVPNkxojY6MpINl4jGf6FTBtvNf0GPDGPfhb7RQ4,788
|
|
|
7
7
|
kasa/deviceconfig.py,sha256=2dqRpwEkaWZyRusqaMyXv28aUHydMF0Z3GLzv-0Hies,6381
|
|
8
8
|
kasa/discover.py,sha256=Pv0BDsVOtz_Y0oWMnwEpQKQuvrwf8eUiSt1uF1LW-DQ,35809
|
|
9
9
|
kasa/emeterstatus.py,sha256=5JtJFWQcpaqquHxvYD9-TsbAbdHGEJiuT7wxVueDV_M,2558
|
|
10
|
-
kasa/exceptions.py,sha256=
|
|
11
|
-
kasa/feature.py,sha256=
|
|
10
|
+
kasa/exceptions.py,sha256=yz7BtgroV9fXMeaSrm4KYHYXpPUSO0Cpwz6sUzj1zmQ,5841
|
|
11
|
+
kasa/feature.py,sha256=A6jkOZeJjDXrTOY8qQhLzSv8MLGFlC35y2KPfgjsrt4,10958
|
|
12
12
|
kasa/httpclient.py,sha256=tb8yZjBtBubvfOtV2F_Gr8qvHkFcXsAc8j5mytoib2Q,6288
|
|
13
13
|
kasa/json.py,sha256=KMJh-A5nQR2Uny8nKRzJEJc2o-JRewTarok_nqS7hX4,1021
|
|
14
14
|
kasa/module.py,sha256=uLE6YA0FVs_OauMbYxOO6kXYFX_w9s-xuL4Dx0JLdbo,10527
|
|
@@ -19,7 +19,7 @@ kasa/cli/__init__.py,sha256=S8z6xs4EPXXtF2wLwuvDLjcuy46c0jWaG0wiqqU5FiY,27
|
|
|
19
19
|
kasa/cli/__main__.py,sha256=B5nsKIZhYL1upQHrrKXnqE3t261v8nthD52e8m3DAgY,88
|
|
20
20
|
kasa/cli/common.py,sha256=gk2C_QKAikmBBJ_waJ04d-lU1psjDp11zPup6CMK4aw,8443
|
|
21
21
|
kasa/cli/device.py,sha256=6MoDRqxDO17NAHfD83fB-J_uBQGYfNo1yGvx1Pk2BV4,5730
|
|
22
|
-
kasa/cli/discover.py,sha256=
|
|
22
|
+
kasa/cli/discover.py,sha256=bXn8-wmHtOcIjDsFVfKVknEHcsqhy7an9kI_732dUsc,11140
|
|
23
23
|
kasa/cli/feature.py,sha256=NigOqrgPvvYvbBJvMogqFbcZjeFTYTl2bH-4iBBvmK0,3717
|
|
24
24
|
kasa/cli/lazygroup.py,sha256=czORArKYmOUlSxMsQxkLUwNpIUZK2yf_7DraiPh1Www,2555
|
|
25
25
|
kasa/cli/light.py,sha256=gIwHTFZ8xRAdl6G4AHRreRiy9tk5M3cQwtLkz_3J-fo,7561
|
|
@@ -64,13 +64,13 @@ kasa/iot/modules/schedule.py,sha256=r9MbXp4CRV8qKPlSXWY5RpHqkT6ULdLGLg8P857sEqI,
|
|
|
64
64
|
kasa/iot/modules/time.py,sha256=vyEuNCK-knLXWW4oGTXRDXEwE0HxFBw2vJRNdJ3ulVM,2773
|
|
65
65
|
kasa/iot/modules/usage.py,sha256=3AwukXG1Ypb9bp7YB1AEaxmgiTFlCFJ5TmWvLww2ZaQ,4025
|
|
66
66
|
kasa/protocols/__init__.py,sha256=KnYWXtdpF2AXM0pZ7JSMTDnYs6sfSB1du7juX_WY8tU,348
|
|
67
|
-
kasa/protocols/iotprotocol.py,sha256=
|
|
67
|
+
kasa/protocols/iotprotocol.py,sha256=vAkzdxg1I8ErC3jSt4UfJiqOFkeomu2Yg262YlLpeMM,6729
|
|
68
68
|
kasa/protocols/protocol.py,sha256=oy4Rqrp6pn6mG77xjiGv3Xq2pxHRm8_-D_LXx7y3ScM,3133
|
|
69
|
-
kasa/protocols/smartcamprotocol.py,sha256=
|
|
70
|
-
kasa/protocols/smartprotocol.py,sha256=
|
|
69
|
+
kasa/protocols/smartcamprotocol.py,sha256=jsX7H9SYsrXhsVUEgKkxyPvbptzPKdtuer8UdaERthM,8859
|
|
70
|
+
kasa/protocols/smartprotocol.py,sha256=bfYM8phXHhcqi45jR4QZOebNggNL1YqZAhScR269RMM,19161
|
|
71
71
|
kasa/smart/__init__.py,sha256=gdmi-Doe7dnv7e8ab_892lr9IdOXeFa3XlU3u_CePCk,198
|
|
72
72
|
kasa/smart/effects.py,sha256=J_mkX2L-7IJSaL5K4CpBaOdk-humx3cVxg7yioGhtF4,11498
|
|
73
|
-
kasa/smart/smartchilddevice.py,sha256=
|
|
73
|
+
kasa/smart/smartchilddevice.py,sha256=6Ykok85koowg3ySz1PBC3-YRkm15ZH-vmmesPDmOvlo,5356
|
|
74
74
|
kasa/smart/smartdevice.py,sha256=IaJJcoxbZ5PSzbFMkDm2drQfLCV6mKijV7k8dM5Z_1A,30635
|
|
75
75
|
kasa/smart/smartmodule.py,sha256=0FELWoz3U-SMdOXlhhd6slPpbi2zzZrTG5RyAGT0hus,8457
|
|
76
76
|
kasa/smart/modules/__init__.py,sha256=ekJ-9gbDhDMjZELqp3GxkxseC2Twzbb58B_yUSOdSSQ,1912
|
|
@@ -112,7 +112,7 @@ kasa/smartcam/smartcamdevice.py,sha256=sS5vhZEb5xFpFcnztWJw3dwCz6iMC-kADz410Y1X4
|
|
|
112
112
|
kasa/smartcam/smartcammodule.py,sha256=WzZ8ItkohLFdgL5cE9GM65wjrkOI62ZXk6nCA7gaByU,3994
|
|
113
113
|
kasa/smartcam/modules/__init__.py,sha256=ZGuHY7Jxhc8Dmj5W8rjfmr_G02RYiGv-96gOiww9GFc,758
|
|
114
114
|
kasa/smartcam/modules/alarm.py,sha256=OZu0Vfi8sBwK9Z1IF2UwhrgkTfGBq9sk7EODtCId9kc,5336
|
|
115
|
-
kasa/smartcam/modules/babycrydetection.py,sha256=
|
|
115
|
+
kasa/smartcam/modules/babycrydetection.py,sha256=HkZvFqG-eSeECukIyhJ4MCf6jw0qf4Yk6Xpkv9564y4,1437
|
|
116
116
|
kasa/smartcam/modules/camera.py,sha256=R0Ui5pUtwxRPCPdwMtLMUOwVyNZ7pUCbUS5041Ervds,4178
|
|
117
117
|
kasa/smartcam/modules/childdevice.py,sha256=vUf70rFtVggOKw-M6whoInHTPi60Oo33V1t8OYNDKvE,901
|
|
118
118
|
kasa/smartcam/modules/device.py,sha256=9bcpkuQwa-RFJR9m5j3LIzDrfZlp4l_6wpcmHxn8C60,2613
|
|
@@ -120,21 +120,21 @@ kasa/smartcam/modules/homekit.py,sha256=ot3InYNtCSxYbqXYcl7xJdX47a2TdOhF7u4a-Wbn
|
|
|
120
120
|
kasa/smartcam/modules/led.py,sha256=Qu6ky3S6MePHSaB-b3q_r6uvHg_lH34CM2MJD589vbE,820
|
|
121
121
|
kasa/smartcam/modules/lensmask.py,sha256=_iduCni9ozfcqhTxXVRbCawUlNq_S7XrVNJZtfvdE-A,876
|
|
122
122
|
kasa/smartcam/modules/matter.py,sha256=P6Nup5dTcagIH0xoIUR2BLb4UU7A6XCSPlQ8UhD7-_c,1308
|
|
123
|
-
kasa/smartcam/modules/motiondetection.py,sha256=
|
|
123
|
+
kasa/smartcam/modules/motiondetection.py,sha256=Ax3CJoaFMSb_6C_cVwZ8WCfRWD_czMTLSu7HaRsXJiU,1451
|
|
124
124
|
kasa/smartcam/modules/pantilt.py,sha256=lb5dIN6f57MY3p9VvgFJSLtYASk2TWY70M2quzYSdQs,3114
|
|
125
|
-
kasa/smartcam/modules/persondetection.py,sha256=
|
|
126
|
-
kasa/smartcam/modules/tamperdetection.py,sha256=
|
|
125
|
+
kasa/smartcam/modules/persondetection.py,sha256=47yunxWmnaTGE3V0AAUTJKDc68PjaXhboZ0BqKHjP4Q,1466
|
|
126
|
+
kasa/smartcam/modules/tamperdetection.py,sha256=oo8R5IOHA_I4UqW_86Ze8-5icz8rXu2NW_O3Olz0KDY,1469
|
|
127
127
|
kasa/smartcam/modules/time.py,sha256=emWpMtvEP30fbkvaDLRNPcKbVPWcES6c-4AZC3Y_PiY,3105
|
|
128
128
|
kasa/transports/__init__.py,sha256=JRY_-AfZ9y4e3HN9sEH76kStPFW7Gg_rymw8NtzRQZs,632
|
|
129
129
|
kasa/transports/aestransport.py,sha256=fMvwCe4Mw3qSIrdS4k_ITbjO0qDbrcc8bum7m9b-tsI,18481
|
|
130
130
|
kasa/transports/basetransport.py,sha256=h4RJkPUBEzEZu_Ycv2UDTN1lnda2YdVYFZF692L5RgA,1495
|
|
131
|
-
kasa/transports/klaptransport.py,sha256=
|
|
131
|
+
kasa/transports/klaptransport.py,sha256=lSgtyi7tqKZAUY4kIPyBXK5_zr8mvluoIEqpsalu0PI,19218
|
|
132
132
|
kasa/transports/linkietransport.py,sha256=o_gcAMqDvy5Rc-a6Raf_7uwJvs_ttgmD2v-QyP5dEqU,4736
|
|
133
|
-
kasa/transports/sslaestransport.py,sha256=
|
|
133
|
+
kasa/transports/sslaestransport.py,sha256=qHLV4lrUQbm-GkIAjdW8mhaNp8VvqYK8-6-zozzrWPw,24193
|
|
134
134
|
kasa/transports/ssltransport.py,sha256=2A7baZyyToX5DDCv7Z8AvTy5-gC-B_m6UfPdmkP7XC4,7777
|
|
135
|
-
kasa/transports/xortransport.py,sha256=
|
|
136
|
-
python_kasa-0.9.
|
|
137
|
-
python_kasa-0.9.
|
|
138
|
-
python_kasa-0.9.
|
|
139
|
-
python_kasa-0.9.
|
|
140
|
-
python_kasa-0.9.
|
|
135
|
+
kasa/transports/xortransport.py,sha256=4CGADSp_HinlhuM1h-w3ZOGGFuSCQ7tKK6zu61VcHfE,8922
|
|
136
|
+
python_kasa-0.9.1.dist-info/METADATA,sha256=A8_koxtqHN1Ta1aoOyE1cUotfOlh9Q3oML4HGj1EB-A,12070
|
|
137
|
+
python_kasa-0.9.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
138
|
+
python_kasa-0.9.1.dist-info/entry_points.txt,sha256=gTVS_oUcmt4q77WSkppQofMelqufh0zeXvvUkmBPRJA,47
|
|
139
|
+
python_kasa-0.9.1.dist-info/licenses/LICENSE,sha256=Klt9aEsei738epLgYqeikhpdBWwMvU1VAli14Bxlc5c,33218
|
|
140
|
+
python_kasa-0.9.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|