Commit Graph

887 Commits

Author SHA1 Message Date
Steven B
b8c1b39cf0
Fix switching off light effects for iot lights strips (#961)
Fixes the newly implemented method to turn off active effects on iot devices
2024-06-07 11:29:26 +01:00
Steven B
e1e2a396b8
Add state features to iot strip sockets (#960)
Fixes iot strip sockets not creating their own state and on_since features.
2024-06-07 10:52:11 +01:00
Steven B
5befe51c42
Ensure http delay logic works during default login attempt (#959)
Ensures retryable exceptions are raised on failure to login with default login credentials.
2024-06-06 17:01:58 +01:00
Steven B
40e40522f9
Fix fan speed level when off and derive smart fan module from common fan interface (#957)
Picked this up while updating the [Fan platform
PR](https://github.com/home-assistant/core/pull/116605) for HA. The
smart fan module was not correctly deriving from the common interface
and the speed_level is reported as >0 when off.
2024-06-06 15:18:34 +02:00
Steven B
39fc21a124
Use freezegun for testing aes http client delays (#954) 2024-06-05 18:13:10 +01:00
Teemu R
8a0edbe2c5
Update release playbook (#932)
Updates the RELEASING.md runbook with more steps and scripts.
Excludes dev release tags for prior releases.
Updates github_changelog_generator config to exclude pull requests
with the release-prep label from the changelog.

Co-authored-by: sdb9696
2024-06-05 17:48:47 +01:00
Steven B
9deadaa520
Prepare 0.7.0.dev2 (#952)
## [0.7.0.dev2](https://github.com/python-kasa/python-kasa/tree/0.7.0.dev2) (2024-06-05)

[Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.7.0.dev1...0.7.0.dev2)

**Implemented enhancements:**

- Make device initialisation easier by reducing required imports [\#936](https://github.com/python-kasa/python-kasa/pull/936) (@sdb9696)

**Fixed bugs:**

- Do not raise on multi-request errors on child devices [\#949](https://github.com/python-kasa/python-kasa/pull/949) (@rytilahti)
- Do not show a zero error code when cli exits from showing help [\#935](https://github.com/python-kasa/python-kasa/pull/935) (@rytilahti)
- Initialize autooff features only when data is available [\#933](https://github.com/python-kasa/python-kasa/pull/933) (@rytilahti)
- Fix P100 errors on multi-requests [\#930](https://github.com/python-kasa/python-kasa/pull/930) (@sdb9696)

**Documentation updates:**

- Update documentation structure and start migrating to markdown [\#934](https://github.com/python-kasa/python-kasa/pull/934) (@sdb9696)

**Closed issues:**

- Simplify instance creation API [\#927](https://github.com/python-kasa/python-kasa/issues/927)

**Merged pull requests:**

- Add P115 fixture [\#950](https://github.com/python-kasa/python-kasa/pull/950) (@rytilahti)
- Add some device fixtures [\#948](https://github.com/python-kasa/python-kasa/pull/948) (@rytilahti)
- Add fixture for S505D [\#947](https://github.com/python-kasa/python-kasa/pull/947) (@rytilahti)
- Fix passing custom port for dump\_devinfo [\#938](https://github.com/python-kasa/python-kasa/pull/938) (@rytilahti)
2024-06-05 08:59:01 +01:00
Steven B
91de5e20ba
Fix P100 errors on multi-requests (#930)
Fixes an issue reported by @bdraco with the P100 not working in the
latest branch:

`[Errno None] Can not write request body for HOST_REDACTED,
ClientOSError(None, 'Can not write request body for
URL_REDACTED'))`

Issue caused by the number of multi requests going above the default
batch of 5 and the P100 not being able to handle the second multi
request happening immediately as it closes the connection after each
query (See https://github.com/python-kasa/python-kasa/pull/690 for
similar issue). This introduces a small wait time on concurrent requests
once the device has raised a ClientOSError.
2024-06-04 19:49:01 +02:00
Teemu R
40f2263770
Add some device fixtures (#948)
Adds some device fixtures by courtesy of @jimboca, thanks!
This is a slightly patched and rebased version of #441.

---------

Co-authored-by: JimBo <jimboca3@gmail.com>
Co-authored-by: sdb9696 <steven.beth@gmail.com>
2024-06-04 19:24:53 +02:00
Teemu R
f890fcedc7
Add P115 fixture (#950) 2024-06-04 19:18:23 +02:00
Teemu R
22347381bc
Do not raise on multi-request errors on child devices (#949)
This will avoid crashing when some commands return an error on
multi-requests on child devices.

Idea from
https://github.com/python-kasa/python-kasa/pull/900/files#r1624803457
2024-06-03 20:41:55 +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
bfba7a347f
Add fixture for S505D (#947)
By courtesy of @steveredden:
https://github.com/python-kasa/python-kasa/issues/888#issuecomment-2145193072
2024-06-03 18:52:15 +02:00
Teemu R
30e37038d7
Fix passing custom port for dump_devinfo (#938) 2024-06-03 16:46:38 +01:00
Steven B
6616d68d42
Update documentation structure and start migrating to markdown (#934)
Starts structuring the documentation library usage into Tutorials, Guides, Explanations and Reference.
Continues migrating new docs from rst to markdown.
Extends the test framework discovery mocks to allow easy writing and testing of code examples.
2024-06-03 10:14:10 +01:00
Teemu R
767156421b
Initialize autooff features only when data is available (#933)
For power strips, the autooff data needs to be requested from the
children.
Until we do that, we should not create these features to avoid crashing
during switch platform initialization.

This also ports the module to use `_initialize_features` and add tests.
2024-05-24 19:39:10 +02:00
Teemu R
b217811096
Do not show a zero error code when cli exits from showing help (#935)
asyncclick raises a custom runtime exception when exiting help. This suppresses reporting it.
2024-05-23 19:35:41 +01:00
Teemu R
c1e14832ef
Prepare 0.7.0.dev1 (#931)
[Full
Changelog](https://github.com/python-kasa/python-kasa/compare/0.7.0.dev0...0.7.0.dev1)

**Implemented enhancements:**

- Fix set\_state for common light modules
[\#929](https://github.com/python-kasa/python-kasa/pull/929) (@sdb9696)
- Add state feature for iot devices
[\#924](https://github.com/python-kasa/python-kasa/pull/924)
(@rytilahti)
2024-05-22 17:37:28 +02:00
Teemu R
23c5ee089a
Add state feature for iot devices (#924)
This is allows a generic implementation for the switch platform in the
homeassistant integration.

Also elevates set_state(bool) to be part of the standard API.
2024-05-22 16:52:00 +02:00
Steven B
db6e335346
Fix set_state for common light modules (#929)
PR contains a number of fixes from testing with HA devices:

- Fixes a bug with turning the light on and off via `set_state`
- Aligns `set_brightness` behaviour across `smart` and `iot` devices
such that a value of 0 is off.
- Aligns `set_brightness` behaviour for `IotDimmer` such that setting
the brightness turns on the device with a transition of 1ms. ([HA
comment](https://github.com/home-assistant/core/pull/117839#discussion_r1608720006))
- Fixes a typing issue in `LightState`.
- Adds `ColorTempRange` and `HSV` to `__init__.py`
- Adds a `state` property to the interface returning `LightState` for
validating `set_state` changes.
- Adds tests for `set_state`
2024-05-22 15:33:55 +02:00
Teemu R
5e619af29f
Prepare 0.7.0.dev0 (#922)
First dev release for 0.7.0: add module support for SMART devices,
support for introspectable device features and refactoring the library
2024-05-19 20:00:57 +02:00
Steven B
273c541fcc
Add light presets common module to devices. (#907)
Adds light preset common module for switching to presets and saving presets.
Deprecates the `presets` attribute and `save_preset` method from the `bulb` 
interface in favour of the modular approach.  Allows setting preset for `iot` 
which was not previously supported.
2024-05-19 11:20:18 +01:00
Steven B
1ba5c73279
Fix potential infinite loop if incomplete lists returned (#920)
Fixes the test framework to handle fixtures with incomplete lists better by checking for completeness and overriding the sum. Also adds a pytest-timeout dev dependency with timeout set to 10 seconds. Finally fixes smartprotocol to prevent an infinite loop if incomplete lists ever happens in the real world.

Co-authored-by: Teemu R. <tpr@iki.fi>
2024-05-19 10:34:52 +01:00
Steven B
9989d0f6ec
Add post update hook to module and use in smart LightEffect (#921)
Adds a post update hook to modules so they can calculate values and collections once rather than on each property access
2024-05-19 10:18:17 +01:00
Steven B
3490a1ef84
Add tutorial doctest module and enable top level await (#919)
Add a tutorial module with examples that can be tested with `doctest`.

In order to simplify the examples they can be run with doctest allowing
top level await statements by adding a fixture to patch the builtins
that xdoctest uses to test code.

---------

Co-authored-by: Teemu R. <tpr@iki.fi>
2024-05-16 18:13:44 +02:00
Steven B
a2e8d2c4e8
Deprecate device level light, effect and led attributes (#916)
Deprecates the attributes at device level for light, light effects, and led. i.e. device.led, device.is_color. Will continue to support consumers using these attributes and emit a warning.
2024-05-15 18:49:08 +01:00
Steven B
133a839f22
Add LightEffect module for smart light strips (#918)
Implements the `light_strip_lighting_effect` components for
`smart` devices. Uses a new list of effects captured from a L900 which
are similar to the `iot` effects but include some additional properties
and a few extra effects.

Assumes that a device only implements `light_strip_lighting_effect` or
`light_effect` but not both.
2024-05-15 06:16:57 +01:00
Steven B
67b5d7de83
Update cli to use common modules and remove iot specific cli testing (#913) 2024-05-14 08:38:21 +01:00
Steven B
ef49f44eac
Deprecate is_something attributes (#912)
Deprecates the is_something attributes like is_bulb and is_dimmable in favour of the modular approach.
2024-05-13 18:52:08 +01:00
Steven B
33d839866e
Make Light and Fan a common module interface (#911) 2024-05-13 17:34:44 +01:00
Steven B
d7b00336f4
Rename bulb interface to light and move fan and light interface to interfaces (#910)
Also rename BulbPreset to LightPreset.
2024-05-11 19:40:08 +01:00
Steven B
f259a8f162
Make module names consistent and remove redundant module casting (#909)
Address the inconsistent naming of smart modules by removing all "Module" suffixes and aligning filenames with class names. Removes the casting of modules to the correct module type now that is is redundant. Update the adding of iot modules to use the ModuleName class rather than a free string.
2024-05-11 19:28:18 +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
Teemu R
7d4dc4c710
Improve smartdevice update module (#791)
* Expose current and latest firmware as features
* Provide API to get information about available firmware updates (e.g., changelog, release date etc.)
* Implement updating the firmware
2024-05-09 01:43:07 +02:00
Teemu R
1e8e289ac7
Move contribution instructions into docs (#901)
Moves the instructions away from README.md to keep it simpler, and
extend the documentation to be up-to-date and easier to approach.

---------

Co-authored-by: Steven B. <51370195+sdb9696@users.noreply.github.com>
2024-05-08 15:25:22 +02:00
Teemu R
353e84438c
Add support for contact sensor (T110) (#877)
Initial support for T110 contact sensor & T110 fixture by courtesy of @ngaertner.
2024-05-07 20:58:18 +02:00
Teemu R
7f98acd477
Add 'battery_percentage' only when it's available (#906)
At least some firmware versions of T110 are known not to report this.
2024-05-07 20:56:24 +02:00
Teemu R
b66a337f40
Add H100 1.5.10 and KE100 2.4.0 fixtures (#905) 2024-05-07 20:56:03 +02:00
Teemu R
253287c7b7
Add warning about tapo watchdog (#902) 2024-05-07 14:46:59 +02:00
Teemu R
55653d0346
Improve categorization of features (#904)
This updates the categorization of features and makes the id mandatory for features
2024-05-07 10:13:35 +01:00
Teemu R
50b5107f75
Add missing alarm volume 'normal' (#899)
Also logs a warning in feature repr if value not in choices and fixes the returned string to be consistent with valid values.
2024-05-07 09:38:09 +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
Steven B
c5d65b624b
Make get_module return typed module (#892)
Passing in a string still works and returns either `IotModule` or
`SmartModule` type when called on `IotDevice` or `SmartDevice`
respectively. When calling on `Device` will return `Module` type.

Passing in a module type is then typed to that module, i.e.:
```py
smartdev.get_module(FanModule)  # type is FanModule
smartdev.get_module("FanModule")  # type is SmartModule
```
Only thing this doesn't do is check that you can't pass an `IotModule`
to a `SmartDevice.get_module()`. However there is a runtime check which
will return null if the passed `ModuleType` is not a subclass of
`SmartModule`.

Many thanks to @cdce8p for helping with this.
2024-05-03 17:01:21 +02:00
Teemu R
530fb841b0
Add fixture for waterleak sensor T300 (#897)
Fixture by courtesy of @ngaertner
(https://github.com/python-kasa/python-kasa/issues/875#issuecomment-2091484438)
2024-05-03 15:24:34 +02: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
5b486074e2
Add LightEffectModule for dynamic light effects on SMART bulbs (#887)
Support the `light_effect` module which allows setting the effect to Off
or Party or Relax. Uses the new `Feature.Type.Choice`. Does not
currently allow editing of effects.
2024-05-02 16:31:12 +02:00
Teemu R
5ef81f4669
Improve feature setter robustness (#870)
This adds a test to check that all feature.set_value() calls will cause
a query, i.e., that there are no self.call()s that are not awaited, and
fixes existing code in this context.

This also fixes an issue where it was not possible to print out the
feature if the value threw an exception.
2024-05-02 15:32:06 +02:00
Teemu R
9dcd8ec91b
Improve temperature controls (#872)
This improves the temperature control features to allow implementing
climate platform support for homeassistant.

Also adds frostprotection module, which is also used to turn
the thermostat on and off.
2024-05-02 13:05:26 +00:00
Steven B
28d41092e5
Update interfaces so they all inherit from Device (#893)
Brings consistency to the api across Smart and Iot so the interfaces can be used for their specialist methods as well as the device methods (e.g. turn_on/off).
2024-05-02 13:55:08 +01:00
Steven B
b2194a1c62
Update ks240 fixture with child device query info (#890)
The fixture now includes the queries returned directly from the child devices which is stored under child_devices along with valid device ids.

Also fixes a bug in the test_cli.py::test_wifi_scan which fails with more than 9 networks.
2024-05-01 16:05:37 +01:00