Commit Graph

109 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
Teemu R
46338ee21d
Use pydantic.v1 namespace on all pydantic versions (#883)
With https://github.com/pydantic/pydantic/pull/9042 being shipped with
[1.10.15](https://docs.pydantic.dev/latest/changelog/#v11015-2024-04-03),
we can clean up the imports a bit until we make decisions how to move
onward with or without pydantic.

---------

Co-authored-by: Steven B. <51370195+sdb9696@users.noreply.github.com>
2024-05-01 15:59:35 +02:00
Steven B
16f17a7729
Add Fan interface for SMART devices (#873)
Enables the Fan interface for devices supporting that component.
Currently the only device with a fan is the ks240 which implements it as
a child device. This PR adds a method `get_module` to search the child
device for modules if it is a WallSwitch device type.
2024-04-30 17:42:53 +01:00
Teemu R
5599756d28
Add support for waterleak sensor (T300) (#876) 2024-04-30 17:31:47 +02:00
Teemu R
300d823895
Implement choice feature type (#880)
Implement the choice feature type allowing to provide a list of choices that can be set.

Co-authored-by: sdb9696
2024-04-30 07:56:09 +01:00
Teemu R
d7a36fe071
Add precision_hint to feature (#871)
This can be used to hint how the sensor value should be rounded when
displaying it to users.

The values are adapted from the values used by homeassistant.
2024-04-29 13:31:42 +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
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
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
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
Steven B
aeb2c923c6
Add ColorModule for smart devices (#840)
Adds support L530 hw_version 1.0
2024-04-20 17:18:35 +02:00
Steven B
203bd79253
Enable and convert to future annotations (#838) 2024-04-17 15:39:24 +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
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
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
Teemu R
3495bd83df
Add T315 fixture, tests for humidity&temperature modules (#802) 2024-03-06 18:04:09 +00:00
Teemu R
0d5a3c8439
Add brightness module (#806)
Add module for controlling the brightness.
2024-03-05 15:41:40 +01:00
Steven B
0306e05fb9
Fix energy module calling get_current_power (#798) 2024-02-28 17:57:02 +00: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
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
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