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 — Add protocol and transport documentation (#663) · python-kasa/python-kasa@6b0a72d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/source
    • design.rst
  • kasa
    • 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
+83Lines changed: 83 additions & 0 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
@@ -61,6 +63,42 @@ You can get the list of supported modules for a given device instance using :att
6163
If you only need some module-specific information,
6264
you can call the wanted method on the module to avoid using :meth:`~kasa.SmartDevice.update`.
6365

66+
Protocols and Transports
67+
************************
68+
69+
The library supports two different TP-Link protocols, ``IOT`` and ``SMART``.
70+
``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.
73+
Confusingly TP-Link originally called the Kasa line "Kasa Smart" and hence this library used "Smart" in a lot of the
74+
module and class names but actually they were built to work with the ``IOT`` protocol.
75+
76+
In 2021 TP-Link started updating the underlying communication transport used by Kasa devices to make them more secure.
77+
It switched from a TCP connection with static XOR type of encryption to a transport called ``KLAP`` which communicates
78+
over http and uses handshakes to negotiate a dynamic encryption cipher.
79+
This automatic update was put on hold and only seemed to affect UK HS100 models.
80+
81+
In 2023 TP-Link started updating the underlying communication transport used by Tapo devices to make them more secure.
82+
It switched from AES encryption via public key exchange to use ``KLAP`` encryption and negotiation due to concerns
83+
around impersonation with AES.
84+
The encryption cipher is the same as for Kasa KLAP but the handshake seeds are slightly different.
85+
Also in 2023 TP-Link started releasing newer Kasa branded devices using the ``SMART`` protocol.
86+
This appears to be driven by hardware version rather than firmware.
87+
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.
91+
The classes providing this functionality are:
92+
93+
- :class:`BaseProtocol <kasa.protocol.BaseProtocol>`
94+
- :class:`IotProtocol <kasa.iotprotocol.IotProtocol>`
95+
- :class:`SmartProtocol <kasa.smartprotocol.SmartProtocol>`
96+
97+
- :class:`BaseTransport <kasa.protocol.BaseTransport>`
98+
- :class:`AesTransport <kasa.aestransport.AesTransport>`
99+
- :class:`KlapTransport <kasa.klaptransport.KlapTransport>`
100+
- :class:`KlapTransportV2 <kasa.klaptransport.KlapTransportV2>`
101+
64102

65103
API documentation for modules
66104
*****************************
@@ -70,3 +108,48 @@ API documentation for modules
70108
:members:
71109
:inherited-members:
72110
:undoc-members:
111+
112+
113+
114+
API documentation for protocols and transports
115+
**********************************************
116+
117+
.. autoclass:: kasa.protocol.BaseProtocol
118+
:members:
119+
:inherited-members:
120+
:undoc-members:
121+
122+
.. autoclass:: kasa.iotprotocol.IotProtocol
123+
:members:
124+
:inherited-members:
125+
:undoc-members:
126+
127+
.. autoclass:: kasa.smartprotocol.SmartProtocol
128+
:members:
129+
:inherited-members:
130+
:undoc-members:
131+
132+
.. autoclass:: kasa.protocol.BaseTransport
133+
:members:
134+
:inherited-members:
135+
:undoc-members:
136+
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
153+
:members:
154+
:inherited-members:
155+
:undoc-members:
Collapse file

‎kasa/protocol.py‎

Copy file name to clipboardExpand all lines: kasa/protocol.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
"""

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.