Commit Graph

709 Commits

Author SHA1 Message Date
sdb9696
2cbe30509e Use cli error function for device not supporting pairing output 2024-06-17 10:12:30 +01:00
sdb9696
fd68468f2e Merge remote-tracking branch 'upstream/master' into feat/hub_pairing 2024-06-17 10:05:36 +01:00
Teemu R
51a972542f
Disallow non-targeted device commands (#982)
Prevent the cli from allowing sub commands unless host or alias is specified.
It is unwise to allow commands to be run on an arbitrary set of discovered
devices so this PR shows an error if attempted.
Also consolidates other invalid cli operations to use a single error function
to display the error to the user.
2024-06-17 10:04:46 +01:00
Teemu R
867b7b8830
Add time sync command (#951)
Allows setting the device time (on SMART devices) to the current time.
Fixes also setting the time which was previously broken.
2024-06-17 09:37:08 +01:00
Teemu Rytilahti
e543297fe9 Allow creation of request_renegotiation mock for iot 2024-06-15 02:51:27 +02:00
Teemu Rytilahti
803e88d508 Add tests and refactor 2024-06-15 02:43:48 +02:00
Teemu Rytilahti
1a758a6a53 Re-initialize children after pairing/unpairing 2024-06-15 00:15:47 +02:00
Teemu Rytilahti
2f669f5ad7 Add 'Pair' action 2024-06-15 00:15:47 +02:00
Teemu Rytilahti
af9152a853 Add support for pairing devices 2024-06-15 00:15:46 +02:00
Steven B
6cdbbefb90
Add timezone to on_since attributes (#978)
This allows them to displayed in HA without errors.
2024-06-14 23:04:20 +02:00
Steven B
4cf395483f
Add type hints to feature set_value (#974)
To prevent untyped call mypy errors in consumers
2024-06-12 21:58:21 +02:00
Steven B
7f24408c32
Handle unknown light effect names and only calculate effect list once (#973)
Fixes issue with unpaired devices reporting light effect as `softAP`
reported in https://github.com/python-kasa/python-kasa/pull/972. I don't
think we need to handle that effect properly so just reports as off.
2024-06-11 20:23:06 +02:00
Teemu R
5d5c353422
Add fixture for L920-5(EU) 1.0.7 (#972)
When not paired, the effect is softAP: `Light effect (light_effect):
invalid value 'softAP' not in ['Off', 'Aurora', ...]`
2024-06-11 20:22:32 +02:00
Steven B
f0be672cf5
Add supported check to light transition module (#971)
Adds an implementation of `_check_supported` to the light transition module so it is
not added to a parent device that reports it but doesn't support it, i.e. ks240.
2024-06-11 15:46:36 +01:00
Steven B
57cbd3cb58
Prepare 0.7.0.dev4 (#969)
## [0.7.0.dev4](https://github.com/python-kasa/python-kasa/tree/0.7.0.dev4) (2024-06-10)

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

**Implemented enhancements:**

- Support smart child modules queries [\#967](https://github.com/python-kasa/python-kasa/pull/967) (@sdb9696)
- Do not expose child modules on parent devices [\#964](https://github.com/python-kasa/python-kasa/pull/964) (@sdb9696)
- Do not add parent only modules to strip sockets [\#963](https://github.com/python-kasa/python-kasa/pull/963) (@sdb9696)

**Project maintenance:**

- Better checking of child modules not supported by parent device [\#966](https://github.com/python-kasa/python-kasa/pull/966) (@sdb9696)
- Add fixture for p300 1.0.15 [\#915](https://github.com/python-kasa/python-kasa/pull/915) (@rytilahti)
2024-06-10 16:59:17 +01:00
Teemu R
447d829abe
Add fixture for p300 1.0.15 (#915)
This version adds auto-off for individual strip sockets.
2024-06-10 17:00:31 +02:00
Steven B
db6276d3fd
Support smart child modules queries (#967)
Required for the P300 firmware update with `auto_off` module on child
devices. Will query child modules for parent devices that are not hubs.

Coverage will be fixed when the P300 fixture is added
https://github.com/python-kasa/python-kasa/pull/915
2024-06-10 16:47:00 +02:00
Steven B
927fe648ac
Better checking of child modules not supported by parent device (#966)
Replaces the logic to skip adding child modules to parent devices based
on whether a device is a wall switch and instead relies on the
`_check_supported` method. Is more future proof and will fix issue with
the P300 with child `auto_off` modules
https://github.com/python-kasa/python-kasa/pull/915 not supported on the
parent.
2024-06-10 15:13:46 +02:00
Steven B
9e74e1bd40
Do not add parent only modules to strip sockets (#963)
Excludes modules that child devices report as supported but do not make sense
on a child device like firmware, cloud, time etc.
2024-06-10 06:21:21 +01:00
Steven B
fe0bbf1b98
Do not expose child modules on parent devices (#964)
Removes the logic to expose child modules on parent devices,
which could cause complications with downstream consumers unknowingly duplicating things.
2024-06-10 05:59:37 +01:00
Steven B
b094e334ca
Prepare 0.7.0.dev3 (#962)
## [0.7.0.dev3](https://github.com/python-kasa/python-kasa/tree/0.7.0.dev3) (2024-06-07)

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

**Fixed bugs:**

- Fix switching off light effects for iot lights strips [\#961](https://github.com/python-kasa/python-kasa/pull/961) (@sdb9696)
- Add state features to iot strip sockets [\#960](https://github.com/python-kasa/python-kasa/pull/960) (@sdb9696)
- Ensure http delay logic works during default login attempt [\#959](https://github.com/python-kasa/python-kasa/pull/959) (@sdb9696)
- Fix fan speed level when off and derive smart fan module from common fan interface [\#957](https://github.com/python-kasa/python-kasa/pull/957) (@sdb9696)
- Require update in cli for wifi commands [\#956](https://github.com/python-kasa/python-kasa/pull/956) (@rytilahti)

**Project maintenance:**

- Use freezegun for testing aes http client delays [\#954](https://github.com/python-kasa/python-kasa/pull/954) (@sdb9696)
- Update release playbook [\#932](https://github.com/python-kasa/python-kasa/pull/932) (@rytilahti)
2024-06-07 13:25:17 +01:00
Teemu R
9b66ac8765
Require update in cli for wifi commands (#956)
Executing wifi join requires passing the current time information for smart devices which we read from the device.
This PR removes wifi from the block list to make it work.
2024-06-07 12:47:51 +01:00
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