Commit Graph

80 Commits

Author SHA1 Message Date
Steven B.
cae9decb02
Exclude __getattr__ for deprecated attributes from type checkers (#1294) 2024-11-21 18:40:13 +00:00
Steven B.
f7778aaa53
Migrate RuleModule to mashumaro (#1283)
Also fixes a bug whereby multiple queries for the same module would overwrite each other.
2024-11-20 14:59:32 +00:00
Steven B.
955e7ab4d0
Migrate TurnOnBehaviours to mashumaro (#1285) 2024-11-20 15:35:51 +01:00
Steven B.
5eca487bcb
Migrate iot cloud module to mashumaro (#1282)
Breaking change as the CloudInfo interface is changing to snake case for
consistency with the rest of the library.
2024-11-20 14:34:26 +01:00
Steven B.
03c073c293
Migrate IotLightPreset to mashumaru (#1275) 2024-11-20 08:37:04 +00:00
Steven B.
a01247d48f
Remove support for python <3.11 (#1273)
Python 3.11 ships with latest Debian Bookworm. 
pypy is not that widely used with this library based on statistics. It could be added back when pypy supports python 3.11.
2024-11-18 18:46:36 +00:00
Steven B.
e209d40a6d
Use _get_device_info methods for smart and iot devs in devtools (#1265) 2024-11-18 14:53:11 +00:00
Steven B.
9d46996e9b
Fix repr for device created with no sysinfo or discovery info" (#1266)
Co-authored-by: Teemu R. <tpr@iki.fi>
2024-11-18 13:14:39 +00:00
Steven B.
e55731c110
Move protocol modules into protocols package (#1254) 2024-11-13 17:50:21 +00:00
Steven B.
71ae06fa83
Fix test framework running against real devices (#1235) 2024-11-11 17:41:31 +00:00
Teemu R.
66eb17057e
Enable ruff check for ANN (#1139) 2024-11-10 18:55:13 +00:00
Teemu R.
b2f3971a4c
Add PIR&LAS for wall switches mentioning PIR support (#1227)
Some devices (like KS200M) support ambient and motion, but as they are
detected as wall switches, they don't get the modules added.
This PR enables the respective modules for wall switches when the
`dev_name` contains `PIR`.
2024-11-03 16:45:48 +01:00
Teemu R.
5da41fcc11
Use stacklevel=2 for warnings to report on callsites (#1219)
Use stacklevel=2 for warnings, as this will correctly show the callsite
instead of the line where the warning is reported.

Currently:
```
kasa/__init__.py:110
  /home/tpr/code/python-kasa/kasa/__init__.py:110: DeprecationWarning: SmartDevice is deprecated, use IotDevice from package kasa.iot instead or use Discover.discover_single() and Device.connect() to support new protocols
    warn(
```

After:
```
kasa/tests/smart/modules/test_contact.py:3
  /home/tpr/code/python-kasa/kasa/tests/smart/modules/test_contact.py:3: DeprecationWarning: SmartDevice is deprecated, use IotDevice from package kasa.iot instead or use Discover.discover_single() and Device.connect() to support new protocols
    from kasa import Module, SmartDevice

``` 

Currently:
```
kasa/tests/test_lightstrip.py: 56 warnings
  /home/tpr/code/python-kasa/kasa/device.py:559: DeprecationWarning: effect is deprecated, use: Module.LightEffect in device.modules instead
    warn(msg, DeprecationWarning, stacklevel=1)
```

After:
```
kasa/tests/test_lightstrip.py::test_effects_lightstrip_set_effect_transition[500-KL430(US)_2.0_1.0.9.json]
  /home/tpr/code/python-kasa/kasa/tests/test_lightstrip.py:62: DeprecationWarning: set_effect is deprecated, use: Module.LightEffect in device.modules instead
    await dev.set_effect("Candy Cane")
```
2024-10-31 14:12:17 +01:00
Teemu R.
6c141c3b65
Expose ambient light setting for iot dimmers (#1210)
This PR adds a setting to control the ambient light enabled/disabled.

Also fixes the getters.
2024-10-31 12:17:18 +01:00
Teemu R.
9975bbf26a
Expose PIR enabled setting for iot dimmers (#1174)
This adds PIR enabled feature to iot dimmers, making it possible to
enable and disable the motion detection.
2024-10-31 10:41:11 +00:00
Steven B.
673a32258f
Make HSV NamedTuple creation more efficient (#1211) 2024-10-29 17:14:52 +00:00
Steven B.
7fd8c14c1f
Create common Time module and add time set cli command (#1157) 2024-10-15 08:59:25 +01:00
Steven B.
bd5a24b0ed
Use tzinfo in time constructor instead of astime for iot devices (#1158)
Fixes using `astime` on a non tzinfo aware object which causes issues with daylight saving.
2024-10-08 12:33:19 +01:00
Steven B.
7c1686d3ae
Cache zoneinfo for smart devices (#1156) 2024-10-08 12:21:01 +01:00
Steven B.
9641edcbc0
Make iot time timezone aware (#1147)
Also makes on_since for iot devices use device time.
Changes the return value for device.timezone to be tzinfo instead of a dict.
2024-10-08 08:16:51 +01:00
Steven B.
1fcf3e44c2
Stabilise on_since value for smart devices (#1144)
Caches the `on_since` value to prevent jitter caused by the device calculations.
2024-10-02 15:04:16 +01:00
Steven B.
81e2685605
Send empty dictionary instead of null for iot queries (#1145) 2024-10-01 12:47:36 +01:00
Teemu R.
d897503b58
Move feature initialization from __init__ to _initialize_features (#1140) 2024-09-28 20:14:31 +02:00
Teemu R.
1ce5af2494
Add factory_reset() to iotdevice (#1125)
Also extend the base device class API to make factory_reset() part of the common API.
2024-09-27 17:42:22 +01:00
Teemu R.
73b6d16074
Extend KL135 ct range up to 9000K (#1123) 2024-09-21 16:29:25 +01:00
Teemu R.
6a86ffbbba
Add flake8-pytest-style (PT) for ruff (#1105)
This will catch common issues with pytest code.

* Use `match` when using `pytest.raises()` for base exception types like
`TypeError` or `ValueError`
* Use tuples for `parametrize()`
* Enforces `pytest.raises()` to contain simple statements, using `noqa`
to skip this on some cases for now.
* Fixes incorrect exception type (valueerror instead of typeerror) for
iotdimmer.
* Adds check valid types for `iotbulb.set_hsv` and `color` smart module.
* Consolidate exception messages for common interface modules.
2024-08-30 17:30:07 +02:00
Teemu R.
3e43781bb2
Add flake8-logging (LOG) and flake8-logging-format (G) for ruff (#1104)
Enables rules LOG (flake8-logging) and G (flake8-logging-format) for
ruff. This will catch eager log message formatting, among other similar
issues.
2024-08-30 16:13:14 +02:00
J. Nick Koston
b6339be9ec
Fix logging in iotdevice when a module is module not supported (#1100)
Debug logger was generating the `repr()` of each module and throwing it away because it had a `%` instead of a `,`
2024-08-23 10:56:33 +01:00
J. Nick Koston
4669e08605
Improve performance of dict merge code (#1097)
Co-authored-by: Teemu R. <tpr@iki.fi>
2024-08-14 16:33:54 -05:00
Steven B.
31ec27c1c8
Fix iot light effect brightness (#1092)
Fixes issue where the brightness of the `iot` light effect is set properly
on the light effect but read back incorrectly from the light.
2024-07-31 15:58:48 +01:00
Steven B.
cb0077f634
Do not send light_on value to iot bulb set_state (#1090)
Passing this extra value caused the `ignore_default` check in the `IotBulb._set_light_state`
method to fail which causes the device to come back on to the default state.
2024-07-31 15:56:07 +01:00
Steven B.
cb7e904d30
Enable setting brightness with color temp for smart devices (#1091) 2024-07-31 15:52:27 +01:00
Steven B.
7bba9926ed
Allow erroring modules to recover (#1080)
Re-query failed modules after some delay instead of immediately disabling them.
Changes to features so they can still be created when modules are erroring.
2024-07-30 19:23:07 +01:00
Teemu R.
dc0aedad20
Expose reboot action (#1073)
Expose reboot through the feature interface.
This can be useful in situations where one wants to reboot the device,
e.g., in recent cases where frequent update calls will render the device
unresponsive after a specific amount of time.
2024-07-24 15:47:38 +02:00
Steven B
9cffbe9e48
Support child devices in all applicable cli commands (#1020)
Adds a new decorator that adds child options to a command and gets the
child device if the options are set.

- Single definition of options and error handling
- Adds options automatically to command
- Backwards compatible with `--index` and `--name`
- `--child` allows for id and alias for ease of use
- Omitting a value for `--child` gives an interactive prompt

Implements private `_update` to allow the CLI to patch a child `update`
method to call the parent device `update`.

Example help output:
```
$ kasa brightness --help
Usage: kasa brightness [OPTIONS] [BRIGHTNESS]

  Get or set brightness.

Options:
  --transition INTEGER
  --child, --name TEXT            Child ID or alias for controlling sub-
                                  devices. If no value provided will show an
                                  interactive prompt allowing you to select a
                                  child.
  --child-index, --index INTEGER  Child index controlling sub-devices
  --help                          Show this message and exit.
```

Fixes #769
2024-07-02 15:11:19 +02:00
Steven B
2687c71c4b
Make parent attribute on device consistent across iot and smart (#1023)
Both device types now have an internal `_parent` and a public property getter
2024-07-01 11:51:06 +01:00
Steven B
07fa0d7a7b
Fix post update hook for iot child devices (#1011)
`_post_update_hook` not being called on child `iot` devices, causing
missing emeter features for children
2024-06-25 17:58:07 +00:00
Teemu R
0f5bafaa43
Require explicit feature type (#1006)
Explicit > implicit. Having this previously would have avoided using a
wrong type for water_alert in the first place.
2024-06-25 18:30:36 +02:00
Steven B
5846bbdbbb
Fix iot strip so the children do not have led and cloud modules (#1010)
Also adds led and cloud connection on the strip parent
2024-06-25 17:24:05 +01:00
Steven B
e083449049
Update mode, time, rssi and report_interval feature names/units (#995) 2024-06-21 18:42:43 +02:00
Teemu R
472008e818
Drop python3.8 support (#992)
Drop support for soon-to-be eol'd python 3.8.
This will allow some minor cleanups & makes it easier to add support for
timezones.

Related to
https://github.com/python-kasa/python-kasa/issues/980#issuecomment-2170889543
2024-06-19 20:24:12 +02:00
Steven B
b4a6df2b5c
Add common energy module and deprecate device emeter attributes (#976)
Consolidates logic for energy monitoring across smart and iot devices.
Deprecates emeter attributes in favour of common names.
2024-06-17 11:22:05 +01: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
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
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
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
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
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