GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update post review and rename TPLinkProtocol to BaseProtocol · python-kasa/python-kasa@809c54f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/source
    • design.rst
  • kasa
    • __init__.py
    • device_factory.py
    • iotprotocol.py
    • protocol.py
    • smartbulb.py
    • smartdevice.py
    • smartdimmer.py
    • smartlightstrip.py
    • smartplug.py
    • smartprotocol.py
    • smartstrip.py
    • tapo
      • tapodevice.py
      • tapoplug.py
    • tests
      • test_protocol.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/source/design.rst‎

Copy file name to clipboardExpand all lines: docs/source/design.rst
+37-21Lines changed: 37 additions & 21 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.. py:module:: kasa.modules
22
3+
34
.. _library_design:
45

56
Library Design & Modules
@@ -46,6 +47,7 @@ While the properties are designed to provide a nice API to use for common use ca
4647
you may sometimes want to access the raw, cached data as returned by the device.
4748
This can be done using the :attr:`~kasa.SmartDevice.internal_state` property.
4849

50+
4951
.. _modules:
5052

5153
Modules
@@ -66,12 +68,14 @@ Protocols and Transports
6668

6769
The library supports two different TP-Link protocols, ``IOT`` and ``SMART``.
6870
``IOT`` is the original Kasa protocol and ``SMART`` is the newer protocol supported by TAPO devices and newer KASA devices.
71+
The original protocol has a ``target``, ``command``, ``args`` interface whereas the new protocol uses a different set of
72+
commands and has a ``method``, ``parameters`` interface.
6973
Confusingly TP-Link originally called the Kasa line "Kasa Smart" and hence this library used "Smart" in a lot of the
7074
module and class names but actually they were built to work with the ``IOT`` protocol.
7175

7276
In 2021 TP-Link started updating the underlying communication transport used by Kasa devices to make them more secure.
7377
It switched from a TCP connection with static XOR type of encryption to a transport called ``KLAP`` which communicates
74-
over http and uses handshakes to negotiate a dynamic encrpytion cipher.
78+
over http and uses handshakes to negotiate a dynamic encryption cipher.
7579
This automatic update was put on hold and only seemed to affect UK HS100 models.
7680

7781
In 2023 TP-Link started updating the underlying communication transport used by Tapo devices to make them more secure.
@@ -81,19 +85,19 @@ The encryption cipher is the same as for Kasa KLAP but the handshake seeds are s
8185
Also in 2023 TP-Link started releasing newer Kasa branded devices using the ``SMART`` protocol.
8286
This appears to be driven by hardware version rather than firmware.
8387

84-
In order to support these different configurations the library is migrating from a single :class:`~TPLinkSmartHomeProtocol`
85-
that support XOR encryption and the IOT protocol to seperate transports and protocols.
88+
89+
In order to support these different configurations the library migrated from a single :class:`TPLinkSmartHomeProtocol <kasa.protocol.TPLinkSmartHomeProtocol>`
90+
to support pluggable transports and protocols.
8691
The classes providing this functionality are:
8792

88-
- :class:`~kasa.BaseProtocol`
89-
- :class:`~kasa.IotProtocol`
90-
- :class:`~kasa.SmartProtocol`
93+
- :class:`BaseProtocol <kasa.protocol.BaseProtocol>`
94+
- :class:`IotProtocol <kasa.iotprotocol.IotProtocol>`
95+
- :class:`SmartProtocol <kasa.smartprotocol.SmartProtocol>`
9196

92-
- :class:`~kasa.BaseTransport`
93-
- :class:`~kasa.XorTransport`
94-
- :class:`~kasa.AesTransport`
95-
- :class:`~kasa.KlapTransport`
96-
- :class:`~kasa.KlapTransportV2`
97+
- :class:`BaseTransport <kasa.protocol.BaseTransport>`
98+
- :class:`AesTransport <kasa.aestransport.AesTransport>`
99+
- :class:`KlapTransport <kasa.klaptransport.KlapTransport>`
100+
- :class:`KlapTransportV2 <kasa.klaptransport.KlapTransportV2>`
97101

98102

99103
API documentation for modules
@@ -105,35 +109,47 @@ API documentation for modules
105109
:inherited-members:
106110
:undoc-members:
107111

112+
113+
108114
API documentation for protocols and transports
109115
**********************************************
110116

111-
.. automodule:: kasa.protocol
112-
:noindex:
117+
.. autoclass:: kasa.protocol.BaseProtocol
113118
:members:
114119
:inherited-members:
115120
:undoc-members:
116121

117-
.. automodule:: kasa.klaptransport
118-
:noindex:
122+
.. autoclass:: kasa.iotprotocol.IotProtocol
119123
:members:
120124
:inherited-members:
121125
:undoc-members:
122126

123-
.. automodule:: kasa.aestransport
124-
:noindex:
127+
.. autoclass:: kasa.smartprotocol.SmartProtocol
125128
:members:
126129
:inherited-members:
127130
:undoc-members:
128131

129-
.. automodule:: kasa.iotprotocol
130-
:noindex:
132+
.. autoclass:: kasa.protocol.BaseTransport
131133
:members:
132134
:inherited-members:
133135
:undoc-members:
134136

135-
.. automodule:: kasa.smartprotocol
136-
:noindex:
137+
.. autoclass:: kasa.klaptransport.KlapTransport
138+
:members:
139+
:inherited-members:
140+
:undoc-members:
141+
142+
.. autoclass:: kasa.klaptransport.KlapTransportV2
143+
:members:
144+
:inherited-members:
145+
:undoc-members:
146+
147+
.. autoclass:: kasa.aestransport.AesTransport
148+
:members:
149+
:inherited-members:
150+
:undoc-members:
151+
152+
.. autoclass:: kasa.protocol.TPLinkSmartHomeProtocol
137153
:members:
138154
:inherited-members:
139155
:undoc-members:
Collapse file

‎kasa/__init__.py‎

Copy file name to clipboardExpand all lines: kasa/__init__.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
UnsupportedDeviceException,
3030
)
3131
from kasa.iotprotocol import IotProtocol
32-
from kasa.protocol import TPLinkProtocol, TPLinkSmartHomeProtocol
32+
from kasa.protocol import BaseProtocol, TPLinkSmartHomeProtocol
3333
from kasa.smartbulb import SmartBulb, SmartBulbPreset, TurnOnBehavior, TurnOnBehaviors
3434
from kasa.smartdevice import DeviceType, SmartDevice
3535
from kasa.smartdimmer import SmartDimmer
@@ -44,7 +44,7 @@
4444
__all__ = [
4545
"Discover",
4646
"TPLinkSmartHomeProtocol",
47-
"TPLinkProtocol",
47+
"BaseProtocol",
4848
"IotProtocol",
4949
"SmartProtocol",
5050
"SmartBulb",
Collapse file

‎kasa/device_factory.py‎

Copy file name to clipboardExpand all lines: kasa/device_factory.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from .iotprotocol import IotProtocol
1010
from .klaptransport import KlapTransport, KlapTransportV2
1111
from .protocol import (
12+
BaseProtocol,
1213
BaseTransport,
13-
TPLinkProtocol,
1414
TPLinkSmartHomeProtocol,
1515
_XorTransport,
1616
)
@@ -141,14 +141,14 @@ def get_device_class_from_family(device_type: str) -> Optional[Type[SmartDevice]
141141

142142
def get_protocol(
143143
config: DeviceConfig,
144-
) -> Optional[TPLinkProtocol]:
144+
) -> Optional[BaseProtocol]:
145145
"""Return the protocol from the connection name."""
146146
protocol_name = config.connection_type.device_family.value.split(".")[0]
147147
protocol_transport_key = (
148148
protocol_name + "." + config.connection_type.encryption_type.value
149149
)
150150
supported_device_protocols: Dict[
151-
str, Tuple[Type[TPLinkProtocol], Type[BaseTransport]]
151+
str, Tuple[Type[BaseProtocol], Type[BaseTransport]]
152152
] = {
153153
"IOT.XOR": (TPLinkSmartHomeProtocol, _XorTransport),
154154
"IOT.KLAP": (IotProtocol, KlapTransport),
Collapse file

‎kasa/iotprotocol.py‎

Copy file name to clipboardExpand all lines: kasa/iotprotocol.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
TimeoutException,
1212
)
1313
from .json import dumps as json_dumps
14-
from .protocol import BaseTransport, TPLinkProtocol
14+
from .protocol import BaseProtocol, BaseTransport
1515

1616
_LOGGER = logging.getLogger(__name__)
1717

1818

19-
class IotProtocol(TPLinkProtocol):
19+
class IotProtocol(BaseProtocol):
2020
"""Class for the legacy TPLink IOT KASA Protocol."""
2121

2222
BACKOFF_SECONDS_AFTER_TIMEOUT = 1
Collapse file

‎kasa/protocol.py‎

Copy file name to clipboardExpand all lines: kasa/protocol.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async def close(self) -> None:
7979
"""Close the transport. Abstract method to be overriden."""
8080

8181

82-
class TPLinkProtocol(ABC):
82+
class BaseProtocol(ABC):
8383
"""Base class for all TP-Link Smart Home communication."""
8484

8585
def __init__(
@@ -140,7 +140,7 @@ async def close(self) -> None:
140140
"""Close the transport. Abstract method to be overriden."""
141141

142142

143-
class TPLinkSmartHomeProtocol(TPLinkProtocol):
143+
class TPLinkSmartHomeProtocol(BaseProtocol):
144144
"""Implementation of the TP-Link Smart Home protocol."""
145145

146146
INITIALIZATION_VECTOR = 171
@@ -168,7 +168,7 @@ async def query(self, request: Union[str, Dict], retry_count: int = 3) -> Dict:
168168
169169
:param str host: host name or ip address of the device
170170
:param request: command to send to the device (can be either dict or
171-
json string)
171+
json string)
172172
:param retry_count: how many retries to do in case of failure
173173
:return: response dict
174174
"""
Collapse file

‎kasa/smartbulb.py‎

Copy file name to clipboardExpand all lines: kasa/smartbulb.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from .deviceconfig import DeviceConfig
1313
from .modules import Antitheft, Cloud, Countdown, Emeter, Schedule, Time, Usage
14-
from .protocol import TPLinkProtocol
14+
from .protocol import BaseProtocol
1515
from .smartdevice import DeviceType, SmartDevice, SmartDeviceException, requires_update
1616

1717

@@ -222,7 +222,7 @@ def __init__(
222222
host: str,
223223
*,
224224
config: Optional[DeviceConfig] = None,
225-
protocol: Optional[TPLinkProtocol] = None,
225+
protocol: Optional[BaseProtocol] = None,
226226
) -> None:
227227
super().__init__(host=host, config=config, protocol=protocol)
228228
self._device_type = DeviceType.Bulb
Collapse file

‎kasa/smartdevice.py‎

Copy file name to clipboardExpand all lines: kasa/smartdevice.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .emeterstatus import EmeterStatus
2626
from .exceptions import SmartDeviceException
2727
from .modules import Emeter, Module
28-
from .protocol import TPLinkProtocol, TPLinkSmartHomeProtocol, _XorTransport
28+
from .protocol import BaseProtocol, TPLinkSmartHomeProtocol, _XorTransport
2929

3030
_LOGGER = logging.getLogger(__name__)
3131

@@ -196,15 +196,15 @@ def __init__(
196196
host: str,
197197
*,
198198
config: Optional[DeviceConfig] = None,
199-
protocol: Optional[TPLinkProtocol] = None,
199+
protocol: Optional[BaseProtocol] = None,
200200
) -> None:
201201
"""Create a new SmartDevice instance.
202202
203203
:param str host: host name or ip address on which the device listens
204204
"""
205205
if config and protocol:
206206
protocol._transport._config = config
207-
self.protocol: TPLinkProtocol = protocol or TPLinkSmartHomeProtocol(
207+
self.protocol: BaseProtocol = protocol or TPLinkSmartHomeProtocol(
208208
transport=_XorTransport(config=config or DeviceConfig(host=host)),
209209
)
210210
_LOGGER.debug("Initializing %s of type %s", self.host, type(self))
Collapse file

‎kasa/smartdimmer.py‎

Copy file name to clipboardExpand all lines: kasa/smartdimmer.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from kasa.deviceconfig import DeviceConfig
66
from kasa.modules import AmbientLight, Motion
7-
from kasa.protocol import TPLinkProtocol
7+
from kasa.protocol import BaseProtocol
88
from kasa.smartdevice import DeviceType, SmartDeviceException, requires_update
99
from kasa.smartplug import SmartPlug
1010

@@ -70,7 +70,7 @@ def __init__(
7070
host: str,
7171
*,
7272
config: Optional[DeviceConfig] = None,
73-
protocol: Optional[TPLinkProtocol] = None,
73+
protocol: Optional[BaseProtocol] = None,
7474
) -> None:
7575
super().__init__(host=host, config=config, protocol=protocol)
7676
self._device_type = DeviceType.Dimmer
Collapse file

‎kasa/smartlightstrip.py‎

Copy file name to clipboardExpand all lines: kasa/smartlightstrip.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from .deviceconfig import DeviceConfig
55
from .effects import EFFECT_MAPPING_V1, EFFECT_NAMES_V1
6-
from .protocol import TPLinkProtocol
6+
from .protocol import BaseProtocol
77
from .smartbulb import SmartBulb
88
from .smartdevice import DeviceType, SmartDeviceException, requires_update
99

@@ -48,7 +48,7 @@ def __init__(
4848
host: str,
4949
*,
5050
config: Optional[DeviceConfig] = None,
51-
protocol: Optional[TPLinkProtocol] = None,
51+
protocol: Optional[BaseProtocol] = None,
5252
) -> None:
5353
super().__init__(host=host, config=config, protocol=protocol)
5454
self._device_type = DeviceType.LightStrip
Collapse file

‎kasa/smartplug.py‎

Copy file name to clipboardExpand all lines: kasa/smartplug.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from kasa.deviceconfig import DeviceConfig
66
from kasa.modules import Antitheft, Cloud, Schedule, Time, Usage
7-
from kasa.protocol import TPLinkProtocol
7+
from kasa.protocol import BaseProtocol
88
from kasa.smartdevice import DeviceType, SmartDevice, requires_update
99

1010
_LOGGER = logging.getLogger(__name__)
@@ -45,7 +45,7 @@ def __init__(
4545
host: str,
4646
*,
4747
config: Optional[DeviceConfig] = None,
48-
protocol: Optional[TPLinkProtocol] = None,
48+
protocol: Optional[BaseProtocol] = None,
4949
) -> None:
5050
super().__init__(host=host, config=config, protocol=protocol)
5151
self._device_type = DeviceType.Plug

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.