Commit Graph

410 Commits

Author SHA1 Message Date
J. Nick Koston
d0b4fe3fc6
handle cancellation 2024-01-12 16:17:53 -10:00
J. Nick Koston
84dd2984ea
handle cancellation 2024-01-12 16:17:02 -10:00
J. Nick Koston
8868c9b70d
handle cancellation 2024-01-12 16:06:34 -10:00
J. Nick Koston
e0c614cf62
handle cancellation 2024-01-12 15:59:47 -10:00
J. Nick Koston
bd285a9fb0
handle cancellation 2024-01-12 15:56:22 -10:00
J. Nick Koston
8e51fa7d31
Add additional debug logging 2024-01-12 15:33:24 -10: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
sdb9696
ceb42e5583
Update pyproject.toml isort profile, dev group header and poetry.lock (#487) 2023-08-03 13:19:31 +02:00
Teemu R
e98475a1b2
Release 0.5.3 (#485)
This release adds support for defining the device port and introduces dependency on async-timeout which improves timeout handling.

[Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.5.2...0.5.3)
2023-07-23 15:49:27 +02:00
J. Nick Koston
677ef9c3ef
Add tests for KP200 (#483)
* Add tests for KP200

This one worked out of the box sans the OUI not being in the list

https://github.com/home-assistant/core/pull/97062

* it is a strip
2023-07-22 23:55:42 +02:00
J. Nick Koston
117a7ac64a
Replace asyncio.wait_for with async-timeout (#480)
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
2023-07-21 11:50:54 +02:00
J. Nick Koston
c9faa1f78f
Only update pyyaml instead of pinning it as a dep (#482) 2023-07-21 11:13:36 +02:00
Viktar Karpach
9b039d8374
Make device port configurable (#471) 2023-07-10 01:55:27 +02:00
Teemu R
6199521269
Release 0.5.2 (#475)
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)
2023-07-02 16:26:29 +02:00
J. Nick Koston
fde156c859
Add benchmarks for speedups (#473)
* Add benchmarks for speedups

* Update README.md

* Update README.md

Co-authored-by: Teemu R. <tpr@iki.fi>

* relo

* Update README.md

* document benchmark

* Update README.md

---------

Co-authored-by: Teemu R. <tpr@iki.fi>
2023-07-02 01:03:50 +02:00
xinud190
b83986bd51
Add fixture for KP405 Smart Dimmer Plug (#470)
* Add files via upload

* Add to KP405 to dimmers, update README

---------

Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
2023-06-30 02:53:23 +02:00
J. Nick Koston
afd54d11d3
Add optional kasa-crypt dependency for speedups (#464)
If installed, use the optimized protocol encryption procedures implemented as a C extension by kasa-crypt (https://pypi.org/project/kasa-crypt/
2023-06-30 02:43:01 +02:00
J. Nick Koston
2d42ca301f
Use orjson when already installed or with speedups extra (#466)
* Use orjson when already installed

* Use orjson when already installed

* fix patch target

* fix patch target

* add speedups extra

* Update README.md

* Update README.md
2023-06-18 01:03:04 +02:00
Brian Davis
9550cbd2f7
Exclude querying certain modules for KL125(US) which cause crashes (#451)
* 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>
2023-05-18 17:04:24 +02:00
Teemu R
39310f3f02
Remove importlib-metadata dependency (#457)
This is no longer needed, as python 3.8 has native importlib.metadata
2023-05-17 20:33:02 +02:00
Teemu R
ce58cc1a6a
Add methods to configure dimmer settings (#429) 2023-05-17 20:10:39 +02:00
Teemu R
18ce40b6bb
Add inactivity setting for the motion module (#453)
* Add inactivity setting for the motion module

* Fix set_cold_time payload

Co-authored-by: Matt Whitlock <whitslack@users.noreply.github.com>

* Add mention about "smart control"

---------

Co-authored-by: Matt Whitlock <whitslack@users.noreply.github.com>
2023-05-17 20:08:05 +02:00
Teemu R
ce5821a35f
Drop python 3.7 support (#455)
* 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
2023-05-17 20:03:08 +02:00
Teemu R
e7b7f1de94
Update dependencies to fix CI (#454)
* Update dependencies

* Update pre-commit dependencies
2023-05-17 19:15:52 +02:00
Teemu R
233f1c9534
Cleanup fixture filenames (#448)
* 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
2023-04-01 17:10:46 +02:00
Teemu R
505b63dd55
Allow effect presets seen on light strips (#440)
* 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
2023-04-01 16:15:58 +02:00
Teemu R
4d514f983b
Return result objects for cli discover and implicit 'state' (#446)
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'.
2023-03-30 01:53:38 +02:00
Teemu R
6be2f387f0
Prepare 0.5.1 (#434) 2023-02-18 22:40:42 +01:00
Teemu R
02c857d472
Some release preparation janitoring (#432)
* Use myst-parser for readme.md doc injection

* Relax version pins

* Define bug tracker and doc links for pypi

* Update pre-commit hooks
2023-02-18 22:09:35 +01:00