8000 Rename cleartexttransport to ssltransport, move into transports package · python-kasa/python-kasa@69369f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 69369f7

Browse files
committed
Rename cleartexttransport to ssltransport, move into transports package
1 parent fd8c3d5 commit 69369f7

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

kasa/device_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import time
77
from typing import Any
88

9-
from .cleartexttransport import CleartextTransport
109
from .device import Device
1110
from .device_type import DeviceType
1211
from .deviceconfig import DeviceConfig
@@ -33,6 +32,7 @@
3332
BaseTransport,
3433
KlapTransport,
3534
KlapTransportV2,
35+
SslTransport,
3636
XorTransport,
3737
)
3838
from .transports.sslaestransport import SslAesTransport
@@ -192,7 +192,7 @@ def get_protocol(
192192
"SMART.AES": (SmartProtocol, AesTransport),
193193
"SMART.KLAP": (SmartProtocol, KlapTransportV2),
194194
"SMART.AES.HTTPS": (SmartCamProtocol, SslAesTransport),
195-
"SMART.CLEAR": (SmartProtocol, CleartextTokenTransport),
195+
"SMART.CLEAR": (SmartProtocol, SslTransport),
196196
}
197197
if not (prot_tran_cls := supported_device_protocols.get(protocol_transport_key)):
198198
return None

kasa/transports/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from .aestransport import AesEncyptionSession, AesTransport
44
from .basetransport import BaseTransport
55
from .klaptransport import KlapTransport, KlapTransportV2
6+
from .ssltransport import SslTransport
67
from .xortransport import XorEncryption, XorTransport
78

89
__all__ = [
910
"AesTransport",
1011
"AesEncyptionSession",
12+
"SslTransport",
1113
"BaseTransport",
1214
"KlapTransport",
1315
"KlapTransportV2",

kasa/cleartexttransport.py renamed to kasa/transports/ssltransport.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Implementation of the TP-Link cleartext transport.
1+
"""Implementation of the clear-text ssl transport.
22
33
This transport does not encrypt the payloads at all, but requires login to function.
44
This has been seen on some devices (like robovacs) with self-signed HTTPS certificates.
@@ -12,13 +12,13 @@
1212
import logging
1313
import time
1414
from enum import Enum, auto
15-
from typing import TYPE_CHECKING, Any, Dict, cast
15+
from typing import TYPE_CHECKING, Any, cast
1616

1717
from yarl import URL
1818

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 (
2222
SMART_AUTHENTICATION_ERRORS,
2323
SMART_RETRYABLE_ERRORS,
2424
AuthenticationError,
@@ -27,10 +27,10 @@
2727
SmartErrorCode,
2828
_RetryableError,
2929
)
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
3434

3535
_LOGGER = logging.getLogger(__name__)
3636

@@ -52,7 +52,7 @@ class TransportState(Enum):
5252
ESTABLISHED = auto() # Ready to send requests
5353

5454

55-
class CleartextTransport(BaseTransport):
55+
class SslTransport(BaseTransport):
5656
"""Implementation of the cleartext transport protocol.
5757
5858
This transport uses HTTPS without any further payload encryption.
@@ -91,7 +91,7 @@ def __init__(
9191
self._app_url = URL(f"https://{self._host}:{self._port}/app")
9292
self._token_url: URL | None = None
9393

94-
_LOGGER.debug("Created cleartext transport for %s", self._host)
94+
_LOGGER.debug("Created ssltransport for %s", self._host)
9595

9696
@property
9797
def default_port(self) -> int:
@@ -138,7 +138,7 @@ def _handle_response_error_code(self, resp_dict: Any, msg: str) -> None:
138138
raise DeviceError(msg, error_code=error_code)
139139

140140
async def send_cleartext_request(self, request: str) -> dict[str, Any]:
141-
"""Send encrypted message as passthrough."""
141+
"""Send request."""
142142
if self._state is TransportState.ESTABLISHED and self._token_url:
143143
url = self._token_url
144144
else:
@@ -152,6 +152,7 @@ async def send_cleartext_request(self, request: str) -> dict[str, Any]:
152152
headers=self.COMMON_HEADERS,
153153
)
154154
_LOGGER.debug("Response with %s: %r", status_code, resp)
155+
resp = cast(bytes, resp)
155156
resp_dict = json_loads(resp)
156157

157158
if status_code != 200:
@@ -165,11 +166,11 @@ async def send_cleartext_request(self, request: str) -> dict[str, Any]:
165166
)
166167

167168
if TYPE_CHECKING:
168-
resp_dict = cast(Dict[str, Any], resp_dict)
169+
resp_dict = cast(dict[str, Any], resp_dict)
169170

170171
return resp_dict # type: ignore[return-value]
171172

172-
async def perform_login(self):
173+
async def perform_login(self) -> None:
173174
"""Login to the device."""
174175
try:
175176
await self.try_login(self._login_params)
@@ -215,7 +216,7 @@ async def try_login(self, login_params: dict[str, Any]) -> None:
215216
time.time() + ONE_DAY_SECONDS - SESSION_EXPIRE_BUFFER_SECONDS
216217
)
217218

218-
def _session_expired(self):
219+
def _session_expired(self) -> bool:
219220
"""Return true if session has expired."""
220221
return (
221222
self._session_expire_at is None

0 commit comments

Comments
 (0)
0