Commit Graph

978 Commits

Author SHA1 Message Date
Steven B.
7bba9926ed
Allow erroring modules to recover (#1080)
Re-query failed modules after some delay instead of immediately disabling them.
Changes to features so they can still be created when modules are erroring.
2024-07-30 19:23:07 +01:00
Steven B.
445f74eed7
Merge patch into master (#1088) 2024-07-29 12:28:48 +01:00
Steven B
9076e79f07
Merge patch into local master 2024-07-29 11:27:40 +01:00
Steven B.
60be6e03b7
Bump project version to 0.7.0.5 (#1087) 2024-07-29 10:51:21 +01:00
Steven B.
91bf9bb73d
Fix generate_supported pre commit to run in venv (#1085)
I noticed after building a new linux instance that running `git commit`
when the virtual environment is not active causes the pre-commit to
fail, as the `generate_supported` hook is not explicitly configured to
run in the virtual env. This PR calls `generate_supported` via the
`run-in-env.sh` script.
2024-07-28 20:41:33 +02:00
Steven B.
7416e855f1
Fix mypy pre-commit hook on windows (#1081) 2024-07-25 09:11:48 +01:00
Steven B.
1c83675e57
Fix intermittently failing decryption error test (#1082) 2024-07-24 18:58:37 +01:00
Teemu R.
055bbcc0c9
Add support for T100 motion sensor (#1079)
Add support for T100 motion sensor.
Thanks to @DarthSonic for the fixture file!
2024-07-24 15:48:33 +02:00
Teemu R.
dc0aedad20
Expose reboot action (#1073)
Expose reboot through the feature interface.
This can be useful in situations where one wants to reboot the device,
e.g., in recent cases where frequent update calls will render the device
unresponsive after a specific amount of time.
2024-07-24 15:47:38 +02:00
Steven B.
ed033679e5
Split out main cli module into lazily loaded submodules (#1039) 2024-07-23 19:13:52 +01:00
Steven B.
58afeb28a1
Update smart request parameter handling (#1061)
Changes to the smart request handling:
- Do not send params if null
- Drop the requestId parameter
- get_preset_rules doesn't send parameters for preset component version less than 3
- get_led_info no longer sends the wrong parameters
- get_on_off_gradually_info no longer sends an empty {} parameter
2024-07-23 19:02:20 +01:00
Steven B.
06ff598d9c
Raise KasaException on decryption errors (#1078)
Currently if the library encounters an invalid decryption error it
raises a value error. This PR wraps it in a KasaException so consumers
such as HA can catch an expected library exception.
2024-07-22 20:33:31 +02:00
Steven B.
7266d70223
0.7.0.5 (#1077)
## [0.7.0.5](https://github.com/python-kasa/python-kasa/tree/0.7.0.5) (2024-07-18)

[Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.7.0.4...0.7.0.5)

A critical bugfix for an issue with some L530 Series devices and a redactor for sensitive info from debug logs.

**Fixed bugs:**

- Only refresh smart LightEffect module daily [\#1064](https://github.com/python-kasa/python-kasa/pull/1064)

**Project maintenance:**

- Redact sensitive info from debug logs [\#1069](https://github.com/python-kasa/python-kasa/pull/1069)
2024-07-18 16:43:28 +01:00
sdb9696
82cff1346d
Prepare 0.7.0.5 2024-07-18 09:47:37 +01:00
Steven B
c4a9a19d5b
Redact sensitive info from debug logs (#1069)
Redacts sensitive data when debug logging device responses such as mac,
location and usernames
2024-07-18 09:47:34 +01:00
Steven B
a97d2c92bb
Only refresh smart LightEffect module daily (#1064)
Fixes an issue with L530 bulbs on HW version 1.0 whereby the light effect
query causes the device to crash with JSON_ENCODE_FAIL_ERROR after
approximately 60 calls.
2024-07-18 09:47:14 +01:00
Steven B.
c4f015a2fb
Redact sensitive info from debug logs (#1069)
Redacts sensitive data when debug logging device responses such as mac,
location and usernames
2024-07-17 19:57:09 +02: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
Steven B.
e17ca21a83
Only refresh smart LightEffect module daily (#1064)
Fixes an issue with L530 bulbs on HW version 1.0 whereby the light effect
query causes the device to crash with JSON_ENCODE_FAIL_ERROR after
approximately 60 calls.
2024-07-17 08:28:11 +01:00
Steven B.
b220beb811
Use monotonic time for query timing (#1070)
To fix intermittent issues with [windows
CI](https://github.com/python-kasa/python-kasa/actions/runs/9952477932/job/27493918272?pr=1068).
Probably better to use monotonic here anyway.

```
FAILED kasa/tests/test_smartdevice.py::test_update_module_update_delays[L530E(EU)_3.0_1.1.6.json-SMART] - ValueError: Clock moved backwards. Refusing to generate ID.
```
2024-07-16 14:25:32 +02: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
daleye
a2b7daa069
Add fixture file for KP405 fw 1.0.6 (#1063) 2024-07-14 16:31:31 +02:00
Steven B
84192a0d77
Bump version to 0.7.0.4 (#1060) 2024-07-12 17:45:37 +01:00
Steven B
448efd7e4c
Prepare 0.7.0.4 (#1059)
## [0.7.0.4](https://github.com/python-kasa/python-kasa/tree/0.7.0.4) (2024-07-011)

[Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.7.0.3...0.7.0.4)

Critical bugfixes for issues with P100s and thermostats.

**Fixed bugs:**

- Use first known thermostat state as main state (pick #1054) [\#1057](https://github.com/python-kasa/python-kasa/pull/1057)
- Defer module updates for less volatile modules (pick 1052) [\#1056](https://github.com/python-kasa/python-kasa/pull/1056)
2024-07-11 17:30:14 +01:00
Steven B
377fa06d39
Use first known thermostat state as main state (pick #1054) (#1057)
Pick commit a044063526 from #1054 

Instead of trying to use the first state when multiple are reported,
iterate over the known states and pick the first matching.
This will fix an issue where the device reports extra states (like
`low_battery`) while having a known mode active.

Related to home-assistant/core#121335
2024-07-11 17:05:40 +01:00
Steven B
5dac092227
Defer module updates for less volatile modules (pick 1052) (#1056)
Pick commit 7fd5c213e6 from 1052

Addresses stability issues on older hw device versions

 - Handles module timeout errors better by querying modules individually on errors and disabling problematic modules like Firmware that go out to the internet to get updates.
- Addresses an issue with the Led module on P100 hardware version 1.0 which appears to have a memory leak and will cause the device to crash after approximately 500 calls.
- Delays updates of modules that do not have regular changes like LightPreset and LightEffect and enables them to be updated on the next update cycle only if required values have changed.
2024-07-11 16:54:15 +01:00
Steven B
7fd5c213e6
Defer module updates for less volatile modules (#1052)
Addresses stability issues on older hw device versions

 - Handles module timeout errors better by querying modules individually on errors and disabling problematic modules like Firmware that go out to the internet to get updates.
- Addresses an issue with the Led module on P100 hardware version 1.0 which appears to have a memory leak and will cause the device to crash after approximately 500 calls.
- Delays updates of modules that do not have regular changes like LightPreset and LightEffect and enables them to be updated on the next update cycle only if required values have changed.
2024-07-11 16:21:59 +01:00
Teemu R
a044063526
Use first known thermostat state as main state (#1054)
Instead of trying to use the first state when multiple are reported,
iterate over the known states and pick the first matching.
This will fix an issue where the device reports extra states (like
`low_battery`) while having a known mode active.

Related to https://github.com/home-assistant/core/issues/121335
2024-07-11 15:11:50 +02:00
Steven B
239b5dd267
Bump project version to 0.7.0.3 (#1053) 2024-07-11 14:26:33 +02:00
gimpy88
abb5d0d412
Add KP400(US) v1.0.4 fixture (#1051) 2024-07-07 14:23:24 +02:00
Steven B
4b77db31d0
Add new HS220 kasa aes fixture (#1050)
Many thanks to @pjarbit for making the device available for a fixture!
2024-07-07 14:22:43 +02:00
gimpy88
6e0bbd8720
Add KS205(US) v1.1.0 fixture (#1049) 2024-07-07 09:16:07 +01:00
Steven B
7888f4904a
Fix light preset module when list contains lighting effects (#1048)
Fixes the residual issues with the light preset module not handling
unexpected `lighting_effect` items in the presets list.

Completes the fixes started with PR
https://github.com/python-kasa/python-kasa/pull/1043 to fix
https://github.com/python-kasa/python-kasa/issues/1040, [HA
#121115](https://github.com/home-assistant/core/issues/121115) and [HA
#121119](https://github.com/home-assistant/core/issues/121119)

With this PR affected devices will no longer have the light preset
functionality disabled. As this is a new feature this does not warrant a
hotfix so will go into the next release.

Updated fixture for testing thanks to @szssamuel, many thanks!
2024-07-04 17:22:47 +02: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
gimpy88
7427a88570
Add KP400 v1.0.3 fixture (#1037) 2024-07-04 12:21:03 +01:00
Steven B
88df7f9ba6
Add KS200M(US) v1.0.11 fixture (#1047) 2024-07-04 12:02:47 +01:00
Steven B
fd4d084839
Add KS225(US) v1.1.0 fixture (#1046) 2024-07-04 11:48:18 +01:00
Steven B
407cedf781
Prepare 0.7.0.3 (#1045)
## [0.7.0.3](https://github.com/python-kasa/python-kasa/tree/0.7.0.3) (2024-07-04)

[Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.7.0.2...0.7.0.3)

Critical bugfix for issue #1033 with ks225 and S505D light preset module errors.
Partially fixes light preset module errors with L920 and L930.

**Fixed bugs:**

Handle module errors more robustly and add query params to light preset and transition [\#1043](https://github.com/python-kasa/python-kasa/pull/1043)
2024-07-04 09:43:45 +01:00
Steven B
fe116eaefb
Handle module errors more robustly and add query params to light preset and transition (#1043)
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.
Cherry pick of [#1036](https://github.com/python-kasa/python-kasa/pull/1036) to patch
2024-07-04 08:29:53 +01:00
Steven B
2f24797033
Enable CI on the patch branch (#1042) 2024-07-04 08:14:01 +01: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
9cffbe9e48
Support child devices in all applicable cli commands (#1020)
Adds a new decorator that adds child options to a command and gets the
child device if the options are set.

- Single definition of options and error handling
- Adds options automatically to command
- Backwards compatible with `--index` and `--name`
- `--child` allows for id and alias for ease of use
- Omitting a value for `--child` gives an interactive prompt

Implements private `_update` to allow the CLI to patch a child `update`
method to call the parent device `update`.

Example help output:
```
$ kasa brightness --help
Usage: kasa brightness [OPTIONS] [BRIGHTNESS]

  Get or set brightness.

Options:
  --transition INTEGER
  --child, --name TEXT            Child ID or alias for controlling sub-
                                  devices. If no value provided will show an
                                  interactive prompt allowing you to select a
                                  child.
  --child-index, --index INTEGER  Child index controlling sub-devices
  --help                          Show this message and exit.
```

Fixes #769
2024-07-02 15:11:19 +02:00
Steven B
b8a87f1c57
Fix credential hash to return None on empty credentials (#1029)
If discovery is triggered without credentials and discovers devices requiring authentication,
blank credentials are used to initialise the protocols and no connection is actually made.
In this instance we should not return the credentials_hash for blank credentials as it will be invalid.
2024-07-02 13:43:37 +01:00
Teemu R
e5b959e4a9
Add L920(EU) v1.1.3 fixture (#1031) 2024-07-02 13:36:57 +01:00
Steven B
1bf6d80b2a
Update changelog generator config (#1030)
Move the static command line options into the config file for
consistency and remove `--no-issues` in favour of
`issues-wo-labels=false` to fix the problem where `release-summary`
issues are being excluded from the changelog.
2024-07-02 13:30:43 +02:00
Steven B
38a8c964b2
Prepare 0.7.0.2 (#1028)
## [0.7.0.2](https://github.com/python-kasa/python-kasa/tree/0.7.0.2) (2024-07-01)

[Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.7.0.1...0.7.0.2)

This patch release fixes some minor issues found out during testing against all new homeassistant platforms.

**Fixed bugs:**

- Disable multi-request on unknown errors [\#1027](https://github.com/python-kasa/python-kasa/pull/1027) (@sdb9696)
- Disable multi requests on json decode error during multi-request [\#1025](https://github.com/python-kasa/python-kasa/pull/1025) (@sdb9696)
- Fix changing brightness when effect is active [\#1019](https://github.com/python-kasa/python-kasa/pull/1019) (@rytilahti)
- Update light transition module to work with child devices [\#1017](https://github.com/python-kasa/python-kasa/pull/1017) (@sdb9696)
- Handle unknown error codes gracefully [\#1016](https://github.com/python-kasa/python-kasa/pull/1016) (@rytilahti)

**Project maintenance:**

- Make parent attribute on device consistent across iot and smart [\#1023](https://github.com/python-kasa/python-kasa/pull/1023) (@sdb9696)
- Cache SmartErrorCode creation [\#1022](https://github.com/python-kasa/python-kasa/pull/1022) (@bdraco)
2024-07-01 15:02:21 +01:00
Steven B
03f72b8be0
Disable multi-request on unknown errors (#1027)
Another P100 fix
2024-07-01 14:33:28 +01:00
Steven B
8d1a4a4229
Disable multi requests on json decode error during multi-request (#1025)
Issue affecting some P100 devices
2024-07-01 13:57:13 +01:00
Teemu R
b31a2ede7f
Fix changing brightness when effect is active (#1019)
This PR changes the behavior of `brightness` module if an effect is
active.
Currently, changing the brightness disables the effect when the
brightness is changed, this fixes that.
This will also improve the `set_effect` interface to use the current
brightness when an effect is activated.

* light_strip_effect: passing `bAdjusted` with the changed properties
changes the brightness.
* light_effect: the brightness is stored only in the rule, so we modify
it when adjusting the brightness. This is also done during the initial
effect activation.

---------

Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
2024-07-01 13:59:24 +02:00
Steven B
2687c71c4b
Make parent attribute on device consistent across iot and smart (#1023)
Both device types now have an internal `_parent` and a public property getter
2024-07-01 11:51:06 +01:00