Commit Graph

432 Commits

Author SHA1 Message Date
J. Nick Koston
624baa0196
Merge branch 'master' into connect_single_device_type 2023-11-20 15:22:48 +01:00
sdb9696
30f217b8ab
Add klap protocol (#509)
* Add support for the new encryption protocol

This adds support for the new TP-Link discovery and encryption
protocols. It is currently incomplete - only devices without
username and password are current supported, and single device
discovery is not implemented.

Discovery should find both old and new devices. When accessing
a device by IP the --klap option can be specified on the command
line to active the new connection protocol.

sdb9696 - This commit also contains 16 later commits from Simon Wilkinson
squashed into the original

* Update klap changes 2023 to fix encryption, deal with kasa credential switching and work with new discovery changes

* Move from aiohttp to httpx

* Changes following review comments

---------

Co-authored-by: Simon Wilkinson <simon@sxw.org.uk>
2023-11-20 14:17:10 +01:00
J. Nick Koston
911ea4ed8e
strip unused 2023-11-19 11:12:05 -06:00
J. Nick Koston
38f21946ae
strip unused 2023-11-19 11:11:17 -06:00
J. Nick Koston
6f821707a0
strip unused 2023-11-19 11:10:01 -06:00
J. Nick Koston
ff756a7a79
make sure it calls discover single without type 2023-11-19 11:08:31 -06:00
J. Nick Koston
1492e14077
fix test 2023-11-19 10:58:30 -06:00
J. Nick Koston
541cd531f8
fixes 2023-11-19 10:53:34 -06:00
J. Nick Koston
5fdec8ceb6
tweak 2023-11-19 10:51:05 -06:00
J. Nick Koston
f55428549f
tweaks 2023-11-19 10:47:21 -06:00
J. Nick Koston
0dfb322c5c
make sure its a thin wrapper 2023-11-19 10:08:16 -06:00
J. Nick Koston
0f463862a7
make sure its a thin wrapper 2023-11-19 10:07:53 -06:00
J. Nick Koston
9030a3ea77
relo 2023-11-19 10:04:30 -06:00
J. Nick Koston
542554e5d4
typing 2023-11-19 10:00:55 -06:00
J. Nick Koston
c076bc72ff
typing 2023-11-19 10:00:34 -06:00
J. Nick Koston
e135289ed7
preen 2023-11-19 09:59:10 -06:00
J. Nick Koston
a9ae4f028f
tweak 2023-11-19 09:58:43 -06:00
J. Nick Koston
88d3b5e32b
tweaks 2023-11-19 09:56:59 -06:00
J. Nick Koston
418e5088ad
move method 2023-11-19 09:56:23 -06:00
J. Nick Koston
8ca64177e2
Merge branch 'master' into connect_single_device_type 2023-11-19 09:44:57 -06:00
Teemu R
bde07d117f
Add some more external links to README (#541)
This updates the README to include more resources for developers intersted as well as some tapo-related links.
2023-11-07 02:15:57 +01:00
sdb9696
26502982a0
Update discover single to handle hostnames (#539) 2023-11-07 02:15:41 +01:00
J. Nick Koston
bcdcd5f982
adjust per review 2023-11-02 18:01:09 -05:00
J. Nick Koston
6573ee0f8a
Update smartdevice.py 2023-10-31 21:20:54 -05:00
J. Nick Koston
1dcb5e72ab
match names to cli 2023-10-31 20:07:40 -05:00
J. Nick Koston
a63e0bed2d
match names to cli 2023-10-31 20:06:02 -05:00
J. Nick Koston
5e290633ed
fix test 2023-10-31 16:21:51 -05:00
J. Nick Koston
e638c7b189
Update connect_single to allow passing in the device type 2023-10-31 16:11:23 -05:00
Teemu R
805e4b8588
Release 0.5.4 (#536)
The highlights of this maintenance release:

* Support to the alternative discovery protocol and foundational work to support other communication protocols, thanks to @sdb9696.
* Reliability improvements by avoiding overflowing device buffers, thanks to @cobryan05.
* Optimizations for downstream device accesses, thanks to @bdraco.
* Support for both pydantic v1 and v2.
2023-10-30 00:57:29 +01:00
Teemu R
87dcd42861
Add python3.12 and pypy-3.10 to CI (#532)
* Add python3.12 and pypy-3.10 to CI

Also, cleanup the action file a bit:
* Update action versions
* Remove commented out yaml
* Disable fail_ci_if_error for codecov

* Fix typo
2023-10-30 00:22:30 +01:00
Teemu R
c431dbb832
Use ruff and ruff format (#534)
Replaces the previously used linting and code formatting tools with ruff.
2023-10-29 23:15:42 +01:00
Teemu R
0061668c9f
Use trusted publisher for publishing to pypi (#531) 2023-10-29 16:30:37 +01:00
Teemu R
af37e83db1
Fix on_since for smartstrip sockets (#529) 2023-10-16 19:37:55 +02:00
J. Nick Koston
85c8410c3d
Add a connect_single method to Discover to avoid the need for UDP (#528)
This should equate to a significant reliability improvement for networks with poor wifi (edge of range)/udp.
2023-10-08 02:29:22 +02:00
J. Nick Koston
528f5e9e07
Remove code to detect event loop change (#526)
The code should always be called from the same thread that
created the object or we have a thread safety problem.
2023-10-08 00:36:51 +02:00
J. Nick Koston
9930311b54
Parse features only during updates (#527)
Every time emeter functions were called features had to be re-parsed. For power strips, thats a lot of re-parses. Only parse them when we update.
2023-10-07 21:18:47 +02:00
J. Nick Koston
0ec0826cc7
Make timeout adjustable (#494) 2023-10-07 20:58:00 +02:00
J. Nick Koston
20b3f7a771
Fix every other query tries to fetch known unsupported features (#520)
* Fix every other query tries to fetch known unsupported features

* ensure modules not being updated are preserved
2023-10-05 22:50:54 +02:00
Teemu R
84a501bcdc
Show an error if both --alias and --host are defined (#513)
Display an error if both --alias and --host are defined to avoid ambiguous target device:
```
❯ kasa --host 123 --alias 123 state
Usage: kasa [OPTIONS] COMMAND [ARGS]...
Try 'kasa --help' for help.

Error: Use either --alias or --host, not both.
```

Also, use `click.BadOptionUsage` consistently for other errors, like when only `--username` or `--password` is given.
2023-10-04 23:35:26 +02:00
cobryan05
a2444da9df
Split queries to avoid overflowing device buffers (#502)
Several KASA devices seem to have pretty strict buffer size limitations on incoming/outgoing data transfers.

Testing on KL125-US and HL103 has shown that sending a request size larger than about ~768 bytes will immediately crash the device. Additionally, a query that generates a response larger than ~4096 bytes will crash the KL125-US. I was unable to generate such a large response to test the HL103.

The KL125-US will only return such large queries when its monthly usage stats have been populated. This means that a new bulb would work fine, but after a month of data collection the bulb would break the 4K limit and start to crash.

To work around this issue, an estimated worst-case response size is calculated before sending a request by summing up all modules estimated response size. If the estimated size is greater than the device's max_response_payload_size then the query will be split into multiple queries.

This PR implements splitting queries expected to have large responses and also removes the module 'skip list' which was a previous workaround to the crash (which worked by simply reducing the number of modules queried, which prevented the overflow) since it is no longer necessary.

This PR does not attempt to address the "input buffer size limit." Thus far this limit has not been an issue.
2023-09-14 20:51:40 +02:00
sdb9696
7bb4a456a2
Add plumbing for passing credentials to devices (#507)
* Add plumbing for passing credentials as far as discovery

* Pass credentials to Smart devices

* Rename authentication exception

* Fix tests failure due to test_json_output leaving echo as nop

* Fix test_credentials test

* Do not print credentials, fix echo function bug and improve get type parameter

* Add device class constructor test

* Add comment for echo handling and move assignment
2023-09-13 15:46:38 +02:00
Chip Schweiss
f7c22f0a0c
Mark KS2{20}M as partially supported (#508) 2023-09-13 13:58:19 +02:00
sdb9696
6055c29d74
Add support for alternative discovery protocol (20002/udp) (#488)
This will broadcast the new discovery message on the new port and log any responses received as unsupported devices.
2023-08-29 15:04:28 +02:00
Teemu R
53021f07fe
Add support for pydantic v2 using v1 shims (#504) 2023-08-28 17:48:49 +02:00
Teemu R
0cb6f21d36
Convert readthedocs config to v2 (#505) 2023-08-28 17:43:12 +02:00
Teemu R
fad6ae5d10
Add devtools script to create module fixtures (#404) 2023-08-27 19:53:36 +02:00
Norman Rasmussen
4b99351dd6
Add toggle command to cli (#498) 2023-08-26 14:21:38 +02:00
Teemu R
24da24efad
Document cli tool --target for discovery (#497)
This adds rudimentary documentation on the `--target` option of the cli tool.
2023-08-14 14:32:24 +02:00
sdb9696
064e3fe560
Add discovery timeout parameter (#486)
* Add discovery timeout parameter

* Rename variable to be more pythonic
2023-08-03 14:24:46 +02:00
sdb9696
176ced9e6e
Add new HS100(UK) fixture (#489) 2023-08-03 13:20:09 +02:00