Commit Graph

54 Commits

Author SHA1 Message Date
Steven B.
7416e855f1
Fix mypy pre-commit hook on windows (#1081) 2024-07-25 09:11:48 +01:00
Steven B.
c19389f236
Fix parse_pcap_klap on windows and support default credentials (#1068)
- Fixes issue running pyshark on new thread in windows
- Fixes bug if handshake repeated during capture
- Tries the default tplink hardcoded credentials as per the library
2024-07-17 08:34:12 +01:00
Carter Strickland
7e9b1687d0
Decrypt KLAP data from PCAP files (#1041)
Allows for decryption of pcap files capturing klap communication with devices.
2024-07-15 13:18:43 +01:00
Steven B
983aacbc24
Structure cli into a package (#1038)
PR with just the initial structural changes for the cli to be a package.
Subsequent PR will break out `main.py` into modules. Doing it in two
stages ensure that the commit history will be continuous for `cli.py` >
`cli/main.py`
2024-07-04 14:52:01 +02:00
Steven B
905a14895d
Handle module errors more robustly and add query params to light preset and transition (#1036)
Ensures that all modules try to access their data in `_post_update_hook` in a safe manner and disable themselves if there's an error.
Also adds parameters to get_preset_rules and get_on_off_gradually_info to fix issues with recent firmware updates.
[#1033](https://github.com/python-kasa/python-kasa/issues/1033)
2024-07-04 08:02:50 +01:00
Steven B
416d3118bf
Configure mypy to run in virtual environment and fix resulting issues (#989)
For some time I've noticed that my IDE is reporting mypy errors that the
pre-commit hook is not picking up. This is because [mypy
mirror](https://github.com/pre-commit/mirrors-mypy) runs in an isolated
pre-commit environment which does not have dependencies installed and it
enables `--ignore-missing-imports` to avoid errors.

This is [advised against by
mypy](https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-library-stubs-or-py-typed-marker)
for obvious reasons:

> We recommend avoiding --ignore-missing-imports if possible: it’s
equivalent to adding a # type: ignore to all unresolved imports in your
codebase.

This PR configures the mypy pre-commit hook to run in the virtual
environment and addresses the additional errors identified as a result.
It also introduces a minimal mypy config into the `pyproject.toml`

[mypy errors identified without the fixes in this
PR](https://github.com/user-attachments/files/15896693/mypyerrors.txt)
2024-06-19 15:07:59 +02:00
Steven B
be5202ccb7
Make device initialisation easier by reducing required imports (#936)
Adds username and password arguments to discovery to remove the need to import Credentials.
Creates TypeAliases in Device for connection configuration classes and DeviceType.
Using the API with these changes will only require importing either Discover or Device
depending on whether using Discover.discover() or Device.connect() to 
initialize and interact with the API.
2024-06-03 19:06:54 +01:00
Teemu R
30e37038d7
Fix passing custom port for dump_devinfo (#938) 2024-06-03 16:46:38 +01:00
Steven B
9473d97ad2
Create common interfaces for remaining device types (#895)
Introduce common module interfaces across smart and iot devices and provide better typing implementation for getting modules to support this.
2024-05-10 19:29:28 +01:00
Steven B
f063c83378
Add child devices from hubs to generated list of supported devices (#898)
Updates generate_supported hook to include child devices of hubs in the list of supported devices.
2024-05-07 07:48:47 +01:00
Teemu R
88381f270f
Use Path.save for saving the fixtures (#894)
This might fix saving of fixture files on Windows, but it's a good
practice to use pathlib where possible.
2024-05-03 13:57:43 +02:00
Steven B
6724506fab
Update dump_devinfo to print original exception stack on errors. (#882) 2024-04-29 14:33:46 +01:00
Steven B
03a0ef3cc3
Include component_nego with child fixtures (#858) 2024-04-22 19:17:11 +02:00
Steven B
203bd79253
Enable and convert to future annotations (#838) 2024-04-17 15:39:24 +02:00
Steven B
da441bc697
Update poetry locks and pre-commit hooks (#837)
Also updates CI pypy versions to be 3.9 and 3.10 which are the currently
[supported
versions](https://www.pypy.org/posts/2024/01/pypy-v7315-release.html).
Otherwise latest cryptography doesn't ship with pypy3.8 wheels and is
unable to build on windows.

Also updates the `codecov-action` to v4 which fixed some intermittent
uploading errors.
2024-04-16 20:21:20 +02:00
Steven B
ced879498b
Put child fixtures in subfolder (#809)
This should prevent child fixtures from hubs breaking tests due to
missing discovery info. To get these devices in `filter_fixtures`
include protocol string of `SMART.CHILD`.
2024-03-06 15:54:55 +01:00
Steven B
fcad0d2344
Add WallSwitch device type and autogenerate supported devices docs (#758) 2024-03-01 18:32:45 +00:00
Steven B
24344b71f5
Update dump_devinfo to collect child device info (#796)
Will create separate fixture files if the model of the child devices
differs from the parent (i.e. hubs). Otherwise the child device info
will be under `child_devices`
2024-02-28 17:04:57 +01:00
Teemu R
a73e2a9ede
Add H100 fixtures (#737)
One direct out of the box, another with upgraded fw & t315
2024-02-24 00:12:19 +01:00
Benjamin Ness
f965b14021
Add feature for ambient light sensor (#787) 2024-02-22 19:11:30 +01:00
Steven B
8c39e81a40
Rename and deprecate exception classes (#739)
# Public #
SmartDeviceException -> KasaException
UnsupportedDeviceException(SmartDeviceException) -> UnsupportedDeviceError(KasaException)
TimeoutException(SmartDeviceException, asyncio.TimeoutError) -> TimeoutError(KasaException, asyncio.TimeoutError)

Add new exception for error codes -> DeviceError(KasaException)
AuthenticationException(SmartDeviceException) -> AuthenticationError(DeviceError)

# Internal #
RetryableException(SmartDeviceException) -> _RetryableError(DeviceError)
ConnectionException(SmartDeviceException) -> _ConnectionError(KasaException)
2024-02-21 16:52:55 +01:00
Teemu R
e86dcb6bf5
Fix dump_devinfo scrubbing for ks240 (#765) 2024-02-19 00:08:39 +01:00
Steven B
57835276e3
Fix devtools for P100 and add fixture (#753) 2024-02-14 19:43:10 +00:00
Steven B
0d119e63d0
Refactor devices into subpackages and deprecate old names (#716)
* Refactor devices into subpackages and deprecate old names

* Tweak and add tests

* Fix linting

* Remove duplicate implementations affecting project coverage

* Update post review

* Add device base class attributes and rename subclasses

* Rename Module to BaseModule

* Remove has_emeter_history

* Fix missing _time in init

* Update post review

* Fix test_readmeexamples

* Fix erroneously duped files

* Clean up iot and smart imports

* Update post latest review

* Tweak Device docstring
2024-02-04 16:20:08 +01:00
Teemu R
1acf4e86da
Retain last two chars for children device_id (#733) 2024-02-01 19:27:01 +01:00
Steven B
0d0f56414c
Switch from TPLinkSmartHomeProtocol to IotProtocol/XorTransport (#710)
* Switch from TPLinkSmartHomeProtocol to IotProtocol/XorTransport

* Add test

* Update docs

* Fix ruff deleting deprecated import
2024-01-26 09:11:31 +00:00
Steven B
f7c04bcef8
Add --batch-size hint to timeout errors in dump_devinfo (#696)
* Add --batch-size hint to timeout errors in dump_devinfo

* Add _echo_error function for displaying critical errors
2024-01-24 10:40:36 +01:00
Teemu R
3f40410db3
Update readme fixture checker and readme (#699) 2024-01-24 09:36:45 +01:00
Steven B
1db955b05e
Make request batch size configurable and avoid multiRequest if 1 (#681) 2024-01-23 11:33:07 +01:00
Teemu R
c1f2f8fe67
Check README for supported models (#684)
* Check README for supported models

* Use poetry for running due to imports

* Update README
2024-01-23 10:14:59 +00:00
Teemu R
f77e87dc5d
dump_devinfo improvements (#657)
* dump_devinfo improvements

* Scrub only the last three bytes for mac addresses
* Add --target to allow creating fixtures based on discovery
* Save fixtures directly to correct location, add --basedir to allow defining the location of repository root
* Add --autosave to disable prompting for saving

* Update fixtures for devices I have

* Add fixture for HS110 hw 4.0 fw 1.0.4

* Improve help strings

* Fix tests

* Update devtools README

* Default to discovery if no host/target given
2024-01-20 14:20:08 +01:00
Steven B
3b1b0a3c21
Encapsulate http client dependency (#642)
* Encapsulate http client dependency

* Store cookie dict as variable

* Update post-review
2024-01-18 10:57:33 +01:00
Steven B
897db674c2
Add L900-10 fixture and it's additional component requests (#629) 2024-01-10 19:40:36 +01:00
Teemu R
7e6eaf4ab2
Use consistent envvars for dump_devinfo credentials (#618) 2024-01-04 19:28:59 +01:00
sdb9696
ae5ad3e8c6
Add known smart requests to dump_devinfo (#597)
* Add known smart requests to dump_devinfo

* Move smartrequest.py to devtools

* Update post-review
2024-01-02 18:20:53 +01:00
sdb9696
1b7914277d
Fix dump_devinfo for unauthenticated (#593) 2023-12-29 20:42:02 +01:00
sdb9696
b27a31a8a9
Add new methods to dump_devinfo and mask aliases (#574) 2023-12-08 14:29:07 +01:00
Teemu R
f9b5003da2
Add support for tapo bulbs (#558)
* Add support for tapo light bulbs

* Use TapoDevice for on/off

* Add tapobulbs to discovery

* Add partial support for effects

Activating the effect does not work as I thought it would,
but this implements rest of the interface from SmartLightStrip.

* Add missing __init__ for tapo package

* Make mypy happy

* Add docstrings to make ruff happy

* Implement state_information and has_emeter

* Import tapoplug from kasa.tapo package

* Add tapo L530 fixture

* Enable tests for L530 fixture

* Make ruff happy

* Update fixture filename

* Raise exceptions on invalid parameters

* Return results in a wrapped dict

* Implement set_*

* Reorganize bulbs to iot&smart, fix tests for smarts

* Fix linting

* Fix BULBS_LIGHT_STRIP back to LIGHT_STRIPS
2023-12-05 20:07:10 +01:00
sdb9696
5e2fcd2cca
Re-add regional suffix to TAPO/SMART fixtures (#566) 2023-12-05 16:45:09 +01:00
sdb9696
a6b7d73d79
Update dump_devinfo to produce new TAPO/SMART fixtures (#561) 2023-12-02 17:33:35 +01:00
sdb9696
9de3f69033
Update dump_devinfo to include 20002 discovery results (#556)
* Fix dump_devinfo and add discovery_result to json

* Update following review.  Do not serialize aliases.

* Delete kasa/tests/fixtures/HS100(UK)_1.0_1.2.6.json
2023-11-29 20:01:20 +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
fad6ae5d10
Add devtools script to create module fixtures (#404) 2023-08-27 19:53:36 +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
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
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
mrbetta
5bf6fda7ee
Added a fixture file for KS220M (#273)
* Added motion and light sensor for KS220M

* Added fixture file for ks220m

* Remove dump_devinfo and add the extra queries to devtools/dump_devinfo

* Test KS220M as a dimmer

* Add empty modules to baseproto to make the tests pass

Co-authored-by: mrbetta <bettale@gmail.com>
Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
2022-01-29 18:28:14 +01:00
Teemu R
8a4068c623
Add script to check supported devices, update README (#242)
* check_readme_vs_fixtures.py checks if a device with a fixture is listed in the README
* Add missing entries to README.md
2021-10-25 10:17:35 +03:00
Teemu R
d75e1adaba
Add perftest to devtools (#236)
* Add perftest to devtools

* Add example output from the perf script

* Rename to avoid pytest collection

* Fix git mv failing to remove the original file..
2021-10-13 19:22:24 +02:00
J. Nick Koston
e31cc6662c
Keep connection open and lock to prevent duplicate requests (#213)
* Keep connection open and lock to prevent duplicate requests

* option to not update children

* tweaks

* typing

* tweaks

* run tests in the same event loop

* memorize model

* Update kasa/protocol.py

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

* Update kasa/protocol.py

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

* Update kasa/protocol.py

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

* Update kasa/protocol.py

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

* dry

* tweaks

* warn when the event loop gets switched out from under us

* raise on unable to connect multiple times

* fix patch target

* tweaks

* isrot

* reconnect test

* prune

* fix mocking

* fix mocking

* fix test under python 3.7

* fix test under python 3.7

* less patching

* isort

* use mocker to patch

* disable on old python since mocking doesnt work

* avoid disconnect/reconnect cycles

* isort

* Fix hue validation

* Fix latitude_i/longitude_i units

Co-authored-by: Teemu R. <tpr@iki.fi>
2021-09-24 23:25:43 +02:00