Commit Graph

826 Commits

Author SHA1 Message Date
Steven B
fe6b1892cc
Fix pypy39 CI cache on macos (#868) 2024-04-25 15:57:08 +01:00
Teemu R
1ff3162112
Expose IOT emeter info as features (#844)
Exposes IOT emeter information using features, bases on #843 to allow
defining the units.


---------

Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
2024-04-25 14:59:17 +02:00
Steven B
724dad02f7
Do not try coverage upload for pypy (#867)
Do not try to upload coverage for pypy which is run without coverage.
2024-04-25 14:02:17 +02:00
Steven B
6e55c8d989
Add runner.arch to cache-key in CI (#866) 2024-04-25 13:02:00 +01:00
Steven B
9efcc0d19f
Fix broken CI due to missing python version on macos-latest (#864) 2024-04-25 08:05:51 +01:00
Teemu R
10629f2db9
Be more lax on unknown SMART devices (#863) 2024-04-25 07:36:30 +01:00
Steven B
53b84b7683
Handle paging of partial responses of lists like child_device_info (#862)
When devices have lists greater than 10 for child devices only the first
10 are returned. This retrieves the rest of the items (currently with
single requests rather than multiple requests)
2024-04-24 20:32:30 +02:00
Steven B
eff8db450d
Support for new ks240 fan/light wall switch (#839)
In order to support the ks240 which has children for the fan and light
components, this PR adds those modules at the parent level and hides the
children so it looks like a single device to consumers. It also decides
which modules not to take from the child because the child does not
support them even though it say it does. It does this for now via a
fixed list, e.g. `Time`, `Firmware` etc.

Also adds fixtures from two versions and corresponding tests.
2024-04-24 20:17:49 +02:00
Teemu R
65874c0365
Embed FeatureType inside Feature (#860)
Moves `FeatureType` into `Feature` to make it easier to use the API.
This also enforces that no invalid types are accepted (i.e.,
`Category.Config` cannot be a `Sensor`)
If `--verbose` is used with the cli tool, some extra information is
displayed for features when in the state command.
2024-04-24 18:38:52 +02:00
Steven B
e410e4f3f3
Fix incorrect state updates in FakeTestProtocols (#861) 2024-04-24 12:25:16 +01:00
Teemu R
6e5cae1f47
Implement action feature (#849)
Adds `FeatureType.Action` making it possible to expose features like
"reboot", "test alarm", "pair" etc.

The `attribute_getter` is no longer mandatory, but it will raise an
exception if not defined for other types than actions.
Trying to read returns a static string `<Action>`.
This overloads the `set_value` to call the given callable on any value.

This also fixes the `play` and `stop` coroutines of the alarm module to
await the call.
2024-04-23 19:49:04 +02:00
Teemu R
b860c32d5f
Implement feature categories (#846)
Initial implementation for feature categories to help downstreams and
our cli tool to categorize the data for more user-friendly manner. As
more and more information is being exposed through the generic features
interface, it is necessary to give some hints to downstreams about how
might want to present the information to users.

This is not a 1:1 mapping to the homeassistant's mental model, and it
will be necessary to fine-tune homeassistant-specific parameters by
other means to polish the presentation.
2024-04-23 19:20:12 +02:00
Steven B
aa969ef020
Better firmware module support for devices not connected to the internet (#854)
Devices not connected to the internet will either error when querying
firmware queries (e.g. P300) or return misleading information (e.g.
P100). This PR adds the cloud connect query to the initial queries and
bypasses the firmware module if not connected.
2024-04-23 13:56:32 +02:00
Steven B
03a0ef3cc3
Include component_nego with child fixtures (#858) 2024-04-22 19:17:11 +02:00
Adrian Dörr
0ab7436eef
Add support for KH100 hub (#847)
Add SMART.KASAHUB to the map of supported devices.
This also adds fixture files for KH100, KE100, and T310, and adapts affected modules and their tests accordingly.

---------

Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
2024-04-22 16:24:15 +02:00
Teemu R
e7d6758b8d
Add rust tapo link to README (#857)
* Added https://github.com/mihai-dinculescu/tapo/ to the list of related
projects.
* Changed the `kasa.tapo` to `kasa.smart`

---------

Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
2024-04-22 14:53:49 +02:00
Teemu R
72db5c6447
Add temperature control module for smart (#848) 2024-04-22 12:39:07 +01:00
Teemu R
890900daf3
Add support for feature units (#843)
Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
2024-04-22 10:25:30 +01:00
Teemu R
651ad96144
Use brightness module for smartbulb (#853)
Moves one more feature out from the smartbulb class
2024-04-20 20:29:07 +02:00
Teemu R
29b28966e0
Remove mock fixtures (#845) 2024-04-20 16:37:24 +01:00
Steven B
214b26a1ea
Re-query missing responses after multi request errors (#850)
When smart devices encounter an error during a multipleRequest they
return the previous successes and the current error and stop processing
subsequent requests. This checks the responses returned and
re-queries individually for any missing responses so that individual
errors do not break other components.
2024-04-20 17:24:49 +02:00
Steven B
aeb2c923c6
Add ColorModule for smart devices (#840)
Adds support L530 hw_version 1.0
2024-04-20 17:18:35 +02:00
Teemu R
4573260ac8
Ignore system environment variables for tests (#851) 2024-04-20 16:14:53 +01:00
Steven B
203bd79253
Enable and convert to future annotations (#838) 2024-04-17 15:39:24 +02:00
Teemu R
82d92aeea5
smartbulb: Limit brightness range to 1-100 (#829)
The allowed brightness for tested light devices (L530, L900) is [1-100]
instead of [0-100] like it was for some kasa devices.
2024-04-17 13:33:10 +02:00
Teemu R
700643d3cf
Add fan module (#764)
Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
2024-04-17 11:07:16 +01: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
87fa39dd80
Cache pipx in CI and add custom setup action (#835) 2024-04-13 18:56:55 +01:00
Steven B
5d08a4c074
Fix CI issue with python version used by pipx to install poetry (#831) 2024-03-28 11:57:26 +00:00
Steven B
0f3b29183d
Fix non python 3.8 compliant test (#832) 2024-03-28 11:38:58 +00:00
Teemu R
c08b58cd8b
Add colortemp feature for iot devices (#827)
Make color temperature feature available for iot bulbs.
2024-03-26 18:33:10 +00:00
Teemu R
35dbda7049
Change state_information to return feature values (#804)
This changes `state_information` to return the names and values of
all defined features.
It was originally a "temporary" hack to show some extra, device-specific
information in the cli tool, but now that we have device-defined
features we can leverage them.
2024-03-26 19:28:39 +01:00
Teemu R
d63f43a230
Add colortemp module (#814)
Allow controlling the color temperature via features interface:
```
$ kasa --host 192.168.xx.xx feature color_temperature                                                                                                                             
Color temperature (color_temperature): 0

$ kasa --host 192.168.xx.xx feature color_temperature 2000
Setting color_temperature to 2000
Raised error: Temperature should be between 2500 and 6500, was 2000
Run with --debug enabled to see stacktrace

$ kasa --host 192.168.xx.xx feature color_temperature 3000
Setting color_temperature to 3000

$ kasa --host 192.168.xx.xx feature color_temperature                                                                                                                             
Color temperature (color_temperature): 3000
```
2024-03-15 17:36:07 +01:00
Teemu R
270614aa02
Revise device initialization and subsequent updates (#807)
This improves the initial update cycle to fetch the information as early
as possible and avoid requesting unnecessary information (like the child
component listing) in every subsequent call of `update()`.

The initial update performs the following steps:
1. `component_nego` (for components) and `get_device_info` (for common
device info) are requested as first, and their results are stored in the
internal state to allow individual modules (like colortemp) to access
the data during the initialization later on.
2. If `child_device` component is available, the child device list and
their components is requested separately to initialize the children.
3. The modules are initialized based on component lists, making the
queries available for the regular `update()`.
4. Finally, a query requesting all module-defined queries is executed,
including also those that we already did above, like the device info.

All subsequent updates will only involve queries that are defined by the
supported modules. This also means that we do not currently support
adding & removing child devices on the fly.

The internal state contains now only the responses for the most recent
update (i.e., no component information is directly available anymore,
but needs to be accessed separately if needed). If component information
is wanted from homeassistant users via diagnostics reports, the
diagnostic platform needs to be adapted to acquire this separately.
2024-03-15 17:18:13 +01:00
Teemu R
48ac39e6d8
Refactor split smartdevice tests to test_{iot,smart}device (#822) 2024-03-15 15:55:48 +00:00
Steven B
41e58252f7
Add pre-commit caching and fix poetry extras cache (#817)
Caching pre-commit halves the linting time and the `action/setup-python`
cache does not handle `--extras` [properly
](https://github.com/actions/setup-python/issues/505) so switching to
action/cache for the poetry cache
2024-03-15 16:42:40 +01:00
Steven B
063518b7db
Add support for firmware module v1 (#821)
The v1 of firmware does not support changing the auto update setting,
this makes it so that it isn't requested in that case.
2024-03-12 18:18:08 +01:00
Steven B
33be568897
Add P100 fw 1.4.0 fixture (#820) 2024-03-12 17:28:50 +01:00
Steven B
7507837734
Fix slow aestransport and cli tests (#816) 2024-03-11 10:17:12 +00:00
Teemu R
3495bd83df
Add T315 fixture, tests for humidity&temperature modules (#802) 2024-03-06 18:04:09 +00:00
Steven B
adce92a761
Add iot brightness feature (#808) 2024-03-06 16:45:08 +00:00
Steven B
42080bd954
Update test framework for dynamic parametrization (#810) 2024-03-06 16:18:52 +00:00
Steven B
652696a9a6
Do not run coverage on pypy and cache poetry envs (#812)
Currently the CI is very slow for pypy vs cpython, one job is 24m vs 3m
on cpython. This PR enables poetry environment caching and bypasses
coverage checking for pypy.

N.B. The poetry cache is keyed on a hash of the `poetry.lock` file.
2024-03-06 16:23:31 +01: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
Teemu R
0d5a3c8439
Add brightness module (#806)
Add module for controlling the brightness.
2024-03-05 15:41:40 +01:00
Teemu R
eb4c048b57
Simplify device __repr__ (#805)
Previously:
```
>>> dev
<DeviceType.Hub model H100 at 192.168.xx.xx (Smart Hub), is_on: False - dev specific: {'overheated': False, 'signal_level': 2, 'SSID': 'xx'}>
>>> dev.children[0]
<ChildDevice Temperature Humidity Sensor of <DeviceType.Hub model H100 at 192.168.xx.xx (Smart Hub), is_on: False - dev specific: {'overheated': False, 'signal_level': 2, 'SSID': 'xx'}>>
```

Now:
```
>>> dev
Device: <DeviceType.Hub at 192.168.xx.xx - Smart Hub (H100)>
>>> dev.children[0]
<DeviceType.Sensor Temperature Humidity Sensor (T315) of <DeviceType.Hub at 192.168.xx.xx - Smart Hub (H100)>>
```
2024-03-05 13:35:19 +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
0306e05fb9
Fix energy module calling get_current_power (#798) 2024-02-28 17:57:02 +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
75c60eb97c
Add fixture for P110 sw 1.0.7 (#801)
By courtesy of @pplucky (#797)
2024-02-27 20:06:13 +01:00