Commit Graph

896 Commits

Author SHA1 Message Date
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
Teemu R
016f4dfd19
Add support for json output (#430)
* Add json support

* Add tests

* Check if test_json_output works on ci using py3.8+

* Add a proper note why py3.7 test for json_output are disabled
2023-02-18 21:41:08 +01:00
Teemu R
1212715dde
Minor fixes to smartbulb docs (#431) 2023-02-18 21:17:19 +01:00
Julian Davis
43ed47eca8
Return usage.get_{monthstat,daystat} in expected format (#394)
* Basic fix for issue: https://github.com/python-kasa/python-kasa/issues/373
Change usage module get_daystat and get_monthat to return dictionaries of date index: time values as spec'd instead of raw usage data. Output matches emeter module get_daystat and get_monthstat

* Fixed some formatting and lint warnings to comply with black/flake8
Use the new _convert function in emeter for all conversions rather than the one in smartdevice.py
Removed unused function _emeter_convert_emeter_data from smartdevice.py

* Added a first pass test module for testing the new usage conversion function

* Changes based on PR feedback
Tidied up some doc string comments
Added a check for explicit values from conversion function

* Rebase on top of current master, fix docstrings

---------

Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
2023-02-18 20:53:02 +01:00
Teemu R
12c98eb58d
Add transition parameter to lightstrip's set_effect (#416) 2023-02-18 18:03:54 +01:00
Teemu R
92636fe82d
Pretty-print all exceptions from cli commands (#428)
Print out the repr of captured exception instead of full traceback
2023-02-18 17:32:03 +01:00
Teemu R
dd044130d4
Use rich for prettier output, if available (#403)
Use rich for prettier output, if available.

This does not add a new dependency, but rather uses rich if it's installed.
2023-02-18 17:31:06 +01:00
Julian Davis
334ba1713a
Added .gitattributes file to retain LF only EOL markers when checking out on Windows (#399) 2023-02-18 17:20:06 +01:00
Teemu R
6e7a588d40
Add brightness to lightstrip's set_effect (#415)
* Add brightness parameter to lightstrip's set_effect

* Use None as default as effects have different default brightnesses
2023-01-21 00:25:59 +01:00
dependabot[bot]
bfafbf9512
Bump certifi from 2021.10.8 to 2022.12.7 (#409)
Bumps [certifi](https://github.com/certifi/python-certifi) from 2021.10.8 to 2022.12.7.
- [Release notes](https://github.com/certifi/python-certifi/releases)
- [Commits](https://github.com/certifi/python-certifi/compare/2021.10.08...2022.12.07)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-11 19:28:28 +01:00
Teemu R
362c60d7b1
Add FUNDING.yml (#402) 2022-11-15 19:12:38 +01:00
Teemu R
327efb6c65
Update pre-commit hooks (#401)
* Update pre-commit hooks

* Fix implicit optionals
2022-11-15 19:05:08 +01:00
Teemu R
ad5b5c2230
Update pre-commit url for flake8 (#400) 2022-11-15 18:26:23 +01:00
Julian Davis
866c8d6db5
Fix pytest warnings about asyncio (#397)
Turn on ayncio auto mode for pytest and remove the global async marking flag
2022-11-13 23:34:47 +01:00
Teemu R
9cb2a56405
Add a note that transition is not supported by all devices (#398) 2022-11-11 21:06:54 +01:00