Commit Graph

787 Commits

Author SHA1 Message Date
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
Steven B
57835276e3
Fix devtools for P100 and add fixture (#753) 2024-02-14 19:43:10 +00:00
Steven B
13d8d94bd5
Fix for P100 on fw 1.1.3 login_version none (#751)
* Fix for P100 on fw 1.1.3 login_version none

* Fix coverage

* Add delay before trying default login

* Move devtools and fixture out

* Change logging string

Co-authored-by: Teemu R. <tpr@iki.fi>

* Fix test

---------

Co-authored-by: Teemu R. <tpr@iki.fi>
2024-02-14 19:13:28 +00:00
Steven B
45f251e57e
Ensure connections are closed when cli is finished (#752)
* Ensure connections are closed when cli is finished

* Test for close calls on error and success
2024-02-14 17:03:50 +00:00
Steven B
5d81e9f94c
Pass timeout parameters to discover_single (#744)
* Pass timeout parameters to discover_single

* Fix tests
2024-02-08 20:03:06 +01:00
Teemu R
458949157a
Add 'shell' command to cli (#738)
* Add 'shell' command to cli

* Add test

* Add ptpython as optional dep
2024-02-06 14:48:19 +01:00
Steven B
6ab17d823c
Reduce AuthenticationExceptions raising from transports (#740)
* Reduce AuthenticationExceptions raising from transports

* Make auth failed test ids easier to read

* Test invalid klap response length
2024-02-05 21:49:26 +01:00
Steven B
215b8d4e4f
Fix discovery cli to print devices not printed during discovery timeout (#670)
* Fix discovery cli to print devices not printed during discovery

* Fix tests

* Fix print exceptions not being propagated

* Fix tests

* Reduce test discover_send time

* Simplify wait logic

* Add tests

* Remove sleep loop and make auth failed a list
2024-02-05 17:53:09 +00:00
Steven B
0d119e63d0
Refactor devices into subpackages and deprecate old names (#716)
* Refactor devices into subpackages and deprecate old names

* Tweak and add tests

* Fix linting

* Remove duplicate implementations affecting project coverage

* Update post review

* Add device base class attributes and rename subclasses

* Rename Module to BaseModule

* Remove has_emeter_history

* Fix missing _time in init

* Update post review

* Fix test_readmeexamples

* Fix erroneously duped files

* Clean up iot and smart imports

* Update post latest review

* Tweak Device docstring
2024-02-04 16:20:08 +01:00
Teemu R
6afd05be59
Do not crash cli on missing discovery info (#735) 2024-02-03 15:28:51 +01:00
Teemu R
fae071f0df
Fix port-override for aes&klap transports (#734)
* Fix port-override for aes&klap transports

* Add tests for port override
2024-02-03 15:28:20 +01:00
Teemu R
414489ff18
Prepare 0.6.2.1 (#736)
[Full Changelog](https://github.com/python-kasa/python-kasa/compare/0.6.2...0.6.2.1)

**Fixed bugs:**

- Avoid crashing on childdevice property accesses [\#732](https://github.com/python-kasa/python-kasa/pull/732) (@rytilahti)

**Merged pull requests:**

- Retain last two chars for children device\_id [\#733](https://github.com/python-kasa/python-kasa/pull/733) (@rytilahti)
- Add TP15 fixture [\#730](https://github.com/python-kasa/python-kasa/pull/730) (@bdraco)
- Add TP25 fixtures [\#729](https://github.com/python-kasa/python-kasa/pull/729) (@bdraco)
- Various test code cleanups [\#725](https://github.com/python-kasa/python-kasa/pull/725) (@rytilahti)
- Unignore F401 for tests [\#724](https://github.com/python-kasa/python-kasa/pull/724) (@rytilahti)
2024-02-02 20:18:46 +01:00
Teemu R
1f15bcda7c
Avoid crashing on childdevice property accesses (#732)
* Avoid crashing on childdevice property accesses

* Push updates from parent to child
2024-02-02 17:29:14 +01:00