1
- """Implementation of the TP-Link cleartext transport.
1
+ """Implementation of the clear-text ssl transport.
2
2
3
3
This transport does not encrypt the payloads at all, but requires login to function.
4
4
This has been seen on some devices (like robovacs) with self-signed HTTPS certificates.
12
12
import logging
13
13
import time
14
14
from enum import Enum , auto
15
- from typing import TYPE_CHECKING , Any , Dict , cast
15
+ from typing import TYPE_CHECKING , Any , cast
16
16
17
17
from yarl import URL
18
18
19
- from .credentials import Credentials
20
- from .deviceconfig import DeviceConfig
21
- from .exceptions import (
19
+ from kasa .credentials import DEFAULT_CREDENTIALS , Credentials , get_default_credentials
20
+ from kasa .deviceconfig import DeviceConfig
21
+ from kasa .exceptions import (
22
22
SMART_AUTHENTICATION_ERRORS ,
23
23
SMART_RETRYABLE_ERRORS ,
24
24
AuthenticationError ,
27
27
SmartErrorCode ,
28
28
_RetryableError ,
29
29
)
30
- from .httpclient import HttpClient
31
- from .json import dumps as json_dumps
32
- from .json import loads as json_loads
E30A
33
- from . protocol import DEFAULT_CREDENTIALS , BaseTransport , get_default_credentials
30
+ from kasa .httpclient import HttpClient
31
+ from kasa .json import dumps as json_dumps
32
+ from kasa .json import loads as json_loads
33
+ from kasa . transports import BaseTransport
34
34
35
35
_LOGGER = logging .getLogger (__name__ )
36
36
@@ -52,7 +52,7 @@ class TransportState(Enum):
52
52
ESTABLISHED = auto () # Ready to send requests
53
53
54
54
55
- class CleartextTransport (BaseTransport ):
55
+ class SslTransport (BaseTransport ):
56
56
"""Implementation of the cleartext transport protocol.
57
57
58
58
This transport uses HTTPS without any further payload encryption.
@@ -91,7 +91,7 @@ def __init__(
91
91
self ._app_url = URL (f"https://{ self ._host } :{ self ._port } /app" )
92
92
self ._token_url : URL | None = None
93
93
94
- _LOGGER .debug ("Created cleartext transport for %s" , self ._host )
94
+ _LOGGER .debug ("Created ssltransport for %s" , self ._host )
95
95
96
96
@property
97
97
def default_port (self ) -> int :
@@ -138,7 +138,7 @@ def _handle_response_error_code(self, resp_dict: Any, msg: str) -> None:
138
138
raise DeviceError (msg , error_code = error_code )
139
139
140
140
async def send_cleartext_request (self , request : str ) -> dict [str , Any ]:
141
- """Send encrypted message as passthrough ."""
141
+ """Send request ."""
142
142
if self ._state is TransportState .ESTABLISHED and self ._token_url :
143
143
url = self ._token_url
144
144
else :
@@ -152,6 +152,7 @@ async def send_cleartext_request(self, request: str) -> dict[str, Any]:
152
152
headers = self .COMMON_HEADERS ,
153
153
)
154
154
_LOGGER .debug ("Response with %s: %r" , status_code , resp )
155
+ resp = cast (bytes , resp )
155
156
resp_dict = json_loads (resp )
156
157
157
158
if status_code != 200 :
@@ -165,11 +166,11 @@ async def send_cleartext_request(self, request: str) -> dict[str, Any]:
165
166
)
166
167
167
168
if TYPE_CHECKING :
168
- resp_dict = cast (Dict [str , Any ], resp_dict )
169
+ resp_dict = cast (dict [str , Any ], resp_dict )
169
170
170
171
return resp_dict # type: ignore[return-value]
171
172
172
- async def perform_login (self ):
173
+ async def perform_login (self ) -> None :
173
174
"""Login to the device."""
174
175
try :
175
176
await self .try_login (self ._login_params )
@@ -215,7 +216,7 @@ async def try_login(self, login_params: dict[str, Any]) -> None:
215
216
time .time () + ONE_DAY_SECONDS - SESSION_EXPIRE_BUFFER_SECONDS
216
217
)
217
218
218
- def _session_expired (self ):
219
+ def _session_expired (self ) -> bool :
219
220
"""Return true if session has expired."""
220
221
return (
221
222
self ._session_expire_at is None
0 commit comments