This refactors `Discover.connect_single` by moving device instance construction into a separate device factory module.
New `SmartDevice.connect(host, *, port, timeout, credentials, device_type)` class method replaces the functionality of `connect_single`,
and also now allows constructing device instances without relying on UDP discovery for type discovery if `device_type` parameter is set.
---------
Co-authored-by: Teemu R. <tpr@iki.fi>
* 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>
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.
* 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
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.
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.
* 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
asyncio.wait_for has some underlying problems that are only fixed in cpython 3.12.
Use async_timeout instead until the minimum supported version is 3.11+ and it can be replaced with asyncio.timeout
See https://github.com/python/cpython/pull/98518
Besides some small improvements, this release:
* Adds optional dependency for for `orjson` and `kasa-crypt` to speed-up protocol handling by an order of magnitude.
* Drops Python 3.7 support as it is no longer maintained.
[Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.5.1...0.5.2)
* commented out modules that break
* added exclusion logic to smartdevice.py
* cleaning up a name
* removing test fixture that isn't related to this PR
* incorporating PR feedback
* fixed an if statement
* reduced exclusion list to just 'cloud'
* Tidy up the issue comment
Co-authored-by: Teemu R. <tpr@iki.fi>
* this seems to be what the linter whats
---------
Co-authored-by: Teemu R. <tpr@iki.fi>
* Drop python 3.7 support
* CI: drop 3.7 and add 3.11
* Remove skipifs that were required for <3.8
* Use pypy-3.8 for CI, re-enable pypy for windows to see if it works now
* Bump readthedocs to use py3.8
* Remove py3.7 failure comment
* Mark mocked fixtures as such
* Use consistent filenames including the swver
* Remove executable bit
* Remove duplicate KL130(US)
* Remove unnecessary mocks where we have real ones available
* Fix filenames in tests
* Make hue, saturation and color_temp optional for smartbulbpresets
* Adjust bulb preset attributes for effect mode
* Don't send None values on save_preset
* Add tests for save_preset payloads
This will make --json to output relevant contents even when no command is defined (i.e., when calling 'kasa --host <host> --json' or 'kasa --target <bcast> --json'.