Commit Graph

97 Commits

Author SHA1 Message Date
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
67b5d7de83
Update cli to use common modules and remove iot specific cli testing (#913) 2024-05-14 08:38:21 +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
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
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
Teemu R
7db989e2ec
Fix --help on subcommands (#886)
Pass a dummy object as context object as it will not be used by --help
anyway.

Also, allow defining --help anywhere in the argv, not just in the last
place.
2024-04-30 18:30:03 +02:00
Steven B
d3544b4989
Move SmartBulb into SmartDevice (#874) 2024-04-29 18:19:44 +01:00
Steven B
cb11b36511
Put modules back on children for wall switches (#881)
Puts modules back on the children for `WallSwitches` (i.e. ks240) and
makes them accessible from the `modules` property on the parent.
2024-04-29 18:34:20 +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
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
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
Steven B
203bd79253
Enable and convert to future annotations (#838) 2024-04-17 15:39:24 +02: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
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
Steven B
fcad0d2344
Add WallSwitch device type and autogenerate supported devices docs (#758) 2024-03-01 18:32:45 +00: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
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
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
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
5ba3676422
Raise CLI errors in debug mode (#771) 2024-02-20 11:21:04 +00: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
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
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
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
J. Nick Koston
fa6bc59b29
Replace rich formatting stripper (#706)
* Revert "Fix overly greedy _strip_rich_formatting (#703)"

This reverts commit ae6a31463e.

* Improve rich formatter stripper

reverts and replaces #703
2024-01-25 08:49:26 +01:00
J. Nick Koston
ae6a31463e
Fix overly greedy _strip_rich_formatting (#703) 2024-01-24 11:53:28 -10:00
Teemu R
8b566757c3
Add new cli command 'command' to execute arbitrary commands (#692)
* Add new cli command 'command' to execute arbitrary commands

This deprecates 'raw-command', which requires positional argument for module,
in favor of new 'command' that accepts '--module' option for IOT devices.

* Pull block list to the module level
2024-01-24 09:10:55 +01:00
Teemu R
e576fcdb46
Allow raw-command and wifi without update (#688)
* Allow raw-command and wifi without update

* Call update always but on wifi&raw-command

* Add tests

* Skip update also if device_family was defined, as device factory performs an update
2024-01-23 22:58:57 +01:00
Teemu R
cfbdf7c64a
Show discovery data for state with verbose (#678)
* Show discovery data for state with verbose

* Remove duplicate discovery printout on discovery, add a newline for readability
2024-01-23 13:24:17 +01:00
Steven B
d5a6fd8e73
Improve test coverage (#625) 2024-01-10 20:37:43 +01:00
Nathan Wreggit
cfe694e5de
Get child emeters with CLI (#623)
* Get child emeters with CLI

* Avoid extra IO when not que querying the child emeter
2024-01-05 02:25:24 +01:00
Teemu R
2d8a8d9511
Add update-credentials command (#620)
* Add change credentials command

* Rename command and add prompts for credential update
2024-01-05 02:25:15 +01:00
sdb9696
b156defc3c
Fix cli discover bug with None username/password (#615) 2024-01-04 19:17:48 +01:00
sdb9696
e9bf9f58ee
Allow serializing and passing of credentials_hashes in DeviceConfig (#607)
* Allow passing of credentials_hashes in DeviceConfig

* Update following review
2024-01-03 22:46:08 +01:00
Teemu R
3692e4812f
Implement wifi interface for tapodevice (#606)
* Implement wifi interface for tapodevice

* Implement wifi_join

Tested to work on P110

* Fix linting
2024-01-03 22:45:16 +01:00
sdb9696
f6fd898faf
Add DeviceConfig to allow specifying configuration parameters (#569)
* Add DeviceConfig handling

* Update post review

* Further update post latest review

* Update following latest review

* Update docstrings and docs
2023-12-29 20:17:15 +01:00
Teemu R
1d5a9c35f4
Elevate --verbose to top-level option (#590)
* Elevate --verbose to be usable for all commands

* Fix tests
2023-12-29 16:04:41 +01:00
sdb9696
209391c422
Improve CLI Discovery output (#583)
- Show discovery results for unsupported devices and devices that fail to authenticate.
- Rename `--show-unsupported` to `--verbose`.
- Remove separate `--timeout` parameter from cli discovery so it's not confused with `--timeout` now added to cli command.
- Add tests.
2023-12-19 13:50:33 +01:00
Teemu R
8cdd4f59f8
Use consistent naming for cli envvars (#570)
* Use consistent naming for cli envvars

* Fix linting
2023-12-05 23:20:29 +01:00
Teemu R
347cbfe3bd
Make timeout configurable for cli (#564) 2023-12-04 16:44:27 +01:00
J. Nick Koston
e98252ff17
Move connect_single to SmartDevice.connect (#538)
This refactors `Discover.connect_single` by moving device instance construction into a separate device factory module.
New `SmartDevice.connect(host, *, port, timeout, credentials, device_type)` class method replaces the functionality of `connect_single`,
and also now allows constructing device instances without relying on UDP discovery for type discovery if `device_type` parameter is set.

---------

Co-authored-by: Teemu R. <tpr@iki.fi>
2023-11-21 23:48:53 +01:00
sdb9696
30f217b8ab
Add klap protocol (#509)
* Add support for the new encryption protocol

This adds support for the new TP-Link discovery and encryption
protocols. It is currently incomplete - only devices without
username and password are current supported, and single device
discovery is not implemented.

Discovery should find both old and new devices. When accessing
a device by IP the --klap option can be specified on the command
line to active the new connection protocol.

sdb9696 - This commit also contains 16 later commits from Simon Wilkinson
squashed into the original

* Update klap changes 2023 to fix encryption, deal with kasa credential switching and work with new discovery changes

* Move from aiohttp to httpx

* Changes following review comments

---------

Co-authored-by: Simon Wilkinson <simon@sxw.org.uk>
2023-11-20 14:17:10 +01:00
Teemu R
c431dbb832
Use ruff and ruff format (#534)
Replaces the previously used linting and code formatting tools with ruff.
2023-10-29 23:15:42 +01:00
Teemu R
84a501bcdc
Show an error if both --alias and --host are defined (#513)
Display an error if both --alias and --host are defined to avoid ambiguous target device:
```
❯ kasa --host 123 --alias 123 state
Usage: kasa [OPTIONS] COMMAND [ARGS]...
Try 'kasa --help' for help.

Error: Use either --alias or --host, not both.
```

Also, use `click.BadOptionUsage` consistently for other errors, like when only `--username` or `--password` is given.
2023-10-04 23:35:26 +02:00