Commit Graph

599 Commits

Author SHA1 Message Date
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
Steven B
97680bdcee
Refactor test framework (#794)
This is in preparation for tests based on supporting features amongst
other tweaks:

- Consolidates the filtering logic that was split across `filter_model`
and `filter_fixture`
- Allows filtering `dev` fixture by `component`
- Consolidates fixtures missing method warnings into one warning
- Does not raise exceptions from `FakeSmartTransport` for missing
methods (required for KS240)
2024-02-27 18:39:04 +01:00
Steven B
996322cea8
Do not fail fast on pypy CI jobs (#799)
The pypy jobs are quite error prone, particularly the windows ones.
2024-02-27 15:58:06 +01:00
Steven B
d82747d73f
Support multiple child requests (#795) 2024-02-26 17:13:46 +01:00
Teemu R
cbf82c9498
Support for on_off_gradually v2+ (#793)
Previously, only v1 of on_off_gradually is supported, and the newer versions are not backwards compatible.
This PR adds support for the newer versions of the component, and implements `number` type for `Feature` to expose the transition time selection.
This also adds a new `supported_version` property to the main module API.
2024-02-24 02:16:43 +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
Teemu R
c3aa34425d
Add temperature_unit feature to t315 (#788) 2024-02-24 00:05:06 +01:00
Teemu R
c61f2e931c
Add --child option to feature command (#789)
This allows listing and changing child device features that were previously not accessible using the cli tool.
2024-02-23 23:32:17 +01:00
Teemu R
7884436679
Add updated L530 fixture 1.1.6 (#792) 2024-02-23 17:13:11 +01:00
Teemu R
bc65f96f85
Add initial support for H100 and T315 (#776)
Adds initial support for H100 and its alarmmodule.

Also implements the following modules for T315:
* reportmodule (reporting interval)
* battery
* humidity
* temperature
2024-02-22 23:09:38 +01:00
Teemu R
951d41a628
Fix auto update switch (#786)
Set the attribute_setter. Also, (at least some) devices expect the full payload data so send it with.
2024-02-22 20:57:42 +01:00
Teemu R
2b0721aea9
Generalize smartdevice child support (#775)
* Initialize children's modules (and features) using the child component negotiation results
* Set device_type based on the device response
* Print out child features in cli 'state'
* Add --child option to cli 'command' to allow targeting child devices
* Guard "generic" features like rssi, ssid, etc. only to devices which have this information

Note, we do not currently perform queries on child modules so some data may not be available. At the moment, a stop-gap solution to use parent's data is used but this is not always correct; even if the device shares the same clock and cloud connectivity, it may have its own firmware updates.
2024-02-22 20:46:19 +01:00
Benjamin Ness
f965b14021
Add feature for ambient light sensor (#787) 2024-02-22 19:11:30 +01:00
Steven B
a87fc3b766
Retry query on 403 after succesful handshake (#785)
If a handshake session becomes invalid the device returns 403 on send and an `AuthenticationError` is raised which prevents a retry, however a retry would be successful.  In HA this causes devices to go into reauth flow which is not necessary.
2024-02-22 18:02:03 +01:00
Teemu R
d9d2f1a430
Remove SmartPlug in favor of SmartDevice (#781)
With the move towards autodetecting available features, there is no reason to keep SmartPlug around.

kasa.smart.SmartPlug is removed in favor of kasa.smart.SmartDevice which offers the same functionality.
Information about auto_off can be accessed using Features of the AutoOffModule on supported devices.

Co-authored-by: Steven B. <51370195+sdb9696@users.noreply.github.com>
2024-02-22 14:34:55 +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
Steven B
4beff228c9
Enable shell extra for installing ptpython and rich (#782)
Co-authored-by: Teemu R. <tpr@iki.fi>
2024-02-20 18:40:28 +00:00
Steven B
5ba3676422
Raise CLI errors in debug mode (#771) 2024-02-20 11:21:04 +00:00
Teemu R
29e6b92b1e
Add missing firmware module import (#774)
#766 was merged too hastily to fail the tests as the module was never imported.
2024-02-20 01:00:26 +01:00
Teemu R
3de04f320a
Add firmware module for smartdevice (#766)
Initial firmware module implementation.

New switch: `Auto update enabled (auto_update_enabled): False`
New binary sensor: `Update available (update_available): False`
2024-02-19 21:29:09 +01:00
Teemu R
efb4a0f31f
Auto auto-off module for smartdevice (#760)
Adds auto-off implementation. The feature stays enabled after the timer runs out, and it will start the countdown if the device is turned on again without explicitly disabling it.

New features:
* Switch to select if enabled: `Auto off enabled (auto_off_enabled): False`
* Setting to change the delay: `Auto off minutes (auto_off_minutes): 222`
* If timer is active, datetime object when the device gets turned off: `Auto off at (auto_off_at): None`
2024-02-19 21:11:11 +01:00
Teemu R
44b59efbb2
Add smartdevice module for led controls (#761)
Allows controlling LED on devices that support it.
2024-02-19 20:59:09 +01:00
Teemu R
f5175c5632
Add cloud module for smartdevice (#767)
Add initial support for the cloud module.

Adds a new binary sensor: `Cloud connection (cloud_connection): False`
2024-02-19 20:48:46 +01:00
Teemu R
520b6bbae3
Add smartdevice module for smooth transitions (#759)
* Add smart module for smooth transitions

* Fix tests

* Fix linting
2024-02-19 20:39:20 +01:00
Teemu R
11719991c0
Initial implementation for modularized smartdevice (#757)
The initial steps to modularize the smartdevice. Modules are initialized based on the component negotiation, and each module can indicate which features it supports and which queries should be run during the update cycle.
2024-02-19 18:01:31 +01:00
Teemu R
e86dcb6bf5
Fix dump_devinfo scrubbing for ks240 (#765) 2024-02-19 00:08:39 +01:00
Steven B
9ab9420ad6
Let caller handle SMART errors on multi-requests (#754)
* Fix for missing get_device_usage

* Fix coverage and add methods to exceptions

* Remove unused caplog fixture
2024-02-15 18:10:34 +00:00
Teemu R
64da736717
Add generic interface for accessing device features (#741)
This adds a generic interface for all device classes to introspect available device features,
that is necessary to make it easier to support a wide variety of supported devices with different set of features.
This will allow constructing generic interfaces (e.g., in homeassistant) that fetch and change these features without hard-coding the API calls.

`Device.features()` now returns a mapping of `<identifier, Feature>` where the `Feature` contains all necessary information (like the name, the icon, a way to get and change the setting) to present and change the defined feature through its interface.
2024-02-15 16:25:08 +01:00