Commit Graph

76 Commits

Author SHA1 Message Date
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
sdb9696
26502982a0
Update discover single to handle hostnames (#539) 2023-11-07 02:15:41 +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
J. Nick Koston
85c8410c3d
Add a connect_single method to Discover to avoid the need for UDP (#528)
This should equate to a significant reliability improvement for networks with poor wifi (edge of range)/udp.
2023-10-08 02:29:22 +02:00
J. Nick Koston
0ec0826cc7
Make timeout adjustable (#494) 2023-10-07 20:58:00 +02:00
sdb9696
7bb4a456a2
Add plumbing for passing credentials to devices (#507)
* Add plumbing for passing credentials as far as discovery

* Pass credentials to Smart devices

* Rename authentication exception

* Fix tests failure due to test_json_output leaving echo as nop

* Fix test_credentials test

* Do not print credentials, fix echo function bug and improve get type parameter

* Add device class constructor test

* Add comment for echo handling and move assignment
2023-09-13 15:46:38 +02:00
sdb9696
6055c29d74
Add support for alternative discovery protocol (20002/udp) (#488)
This will broadcast the new discovery message on the new port and log any responses received as unsupported devices.
2023-08-29 15:04:28 +02:00
Viktar Karpach
9b039d8374
Make device port configurable (#471) 2023-07-10 01:55:27 +02:00
J. Nick Koston
2d42ca301f
Use orjson when already installed or with speedups extra (#466)
* Use orjson when already installed

* Use orjson when already installed

* fix patch target

* fix patch target

* add speedups extra

* Update README.md

* Update README.md
2023-06-18 01:03:04 +02:00
Teemu R
327efb6c65
Update pre-commit hooks (#401)
* Update pre-commit hooks

* Fix implicit optionals
2022-11-15 19:05:08 +01:00
Teemu R
723fca9d08
Do not crash on discovery on WSL (#283) 2022-01-08 17:48:01 +01:00
Teemu R
9cda529329
Catch exceptions raised on unknown devices during discovery (#240) 2021-10-29 02:44:51 +02:00
J. Nick Koston
e31cc6662c
Keep connection open and lock to prevent duplicate requests (#213)
* Keep connection open and lock to prevent duplicate requests

* option to not update children

* tweaks

* typing

* tweaks

* run tests in the same event loop

* memorize model

* Update kasa/protocol.py

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

* Update kasa/protocol.py

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

* Update kasa/protocol.py

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

* Update kasa/protocol.py

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

* dry

* tweaks

* warn when the event loop gets switched out from under us

* raise on unable to connect multiple times

* fix patch target

* tweaks

* isrot

* reconnect test

* prune

* fix mocking

* fix mocking

* fix test under python 3.7

* fix test under python 3.7

* less patching

* isort

* use mocker to patch

* disable on old python since mocking doesnt work

* avoid disconnect/reconnect cycles

* isort

* Fix hue validation

* Fix latitude_i/longitude_i units

Co-authored-by: Teemu R. <tpr@iki.fi>
2021-09-24 23:25:43 +02:00
Teemu R
acb221b1e0
Cleanup discovery & add tests (#212)
* Cleanup discovery & add tests

* discovered_devices_raw is not anymore available, as that can be accessed directly from the device objects
* test most of the discovery code paths
* some minor cleanups to test handling
* update discovery docs

* Move category check to be after the definitions

* skip a couple of tests requiring asyncmock not available on py37

* Remove return_raw usage from cli.discover
2021-09-24 17:18:11 +02:00
Leandro Reox
7565d03c8e
Add a note about using the discovery target parameter (#168)
* Update discover.py

Updated discovery documentation for multiple interfaces explanation

* revise

Co-authored-by: Teemu R <tpr@iki.fi>
2021-09-20 00:01:06 +02:00
Teemu R
0471e1a5a8
Simplify discovery query, refactor dump-devinfo (#147)
* Use only system:get_sysinfo for discovery

* move dump-devinfo into a separate tool under devtools

* Fix linting
2021-05-10 02:19:00 +02:00
dlee1j1
d4a361dd3e
Leverage data from UDP discovery to initialize device structure (#132)
* avoid talking to devices after UDP discovery

* formatting fix

* more formatting

* more formatting changes

* undo gitignore changes

* fixing git ignore for black

Co-authored-by: dlee1j1 <dlee1j@yahoo.comm>
2021-02-06 16:14:36 +01:00
Teemu R
56eb2cdcb5
Simplify device class detection, fix hardcoded timeout for discovery (#112) 2020-11-08 14:32:27 +01:00
Teemu R
c59b748a06
Pin dependencies on major versions, add poetry.lock (#94)
* Pin dependencies on major versions, add poetry.lock

* Fix linting
2020-07-29 19:28:00 +02:00
Dmitrii Eliuseev
1cd1e84f78
'Interface' parameter added to discovery process (#79)
* 'Interface' parameter added to discovery process

Some systems (for example dd-wrt) requires specifying the network interface name, otherwise the broadcast does not work

* 'Interface' variable type and check fixed

* Formatting fixed

* Update kasa/discover.py

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

Co-authored-by: Teemu R. <tpr@iki.fi>
2020-07-28 23:20:58 +02:00
Teemu R
d30d00a3ff
Add support for lightstrips (KL430) (#74)
* Preliminary support for light strips

* Add color temperature range and cleanup, thanks to @darkoppressor

* Use lightstrip instead of {led,light}strip consistently everywhere
* The cli flag is now --lightstrip

* add apidocs

* Add fixture file for KL430

Signed-off-by: Kevin Wells <darkoppressor@gmail.com>

* Add discovery support, expose effect and length of the strip

* use set_light_state instead of transition_light_state

* Add tests for lightstrip

* add doctests

* Add KL430 to supported devices in README

Co-authored-by: Kevin Wells <darkoppressor@gmail.com>
2020-07-19 22:32:17 +02:00
Teemu R
f9a987ca18
Simplify API documentation by using doctests (#73)
* Add doctests to SmartBulb

* Add SmartDevice doctests, cleanup README.md

* add doctests for smartplug and smartstrip

* add discover doctests

* Fix bulb mock

* add smartdimmer doctests

* add sphinx-generated docs, cleanup readme a bit

* remove sphinx-click as it does not work with asyncclick

* in preparation for rtd hooking, move doc deps to be separate from dev deps

* pytestmark needs to be applied separately for each and every file, this fixes the tests

* use pathlib for resolving relative paths

* Skip discovery doctest on python3.7

The code is just fine, but some reason the mocking behaves differently between 3.7 and 3.8.
The latter seems to accept a discrete object for asyncio.run where the former expects a coroutine..
2020-06-30 02:29:52 +02:00
Teemu R
644a10a0d1
General cleanups all around (janitoring) (#63)
* Move tests to device-type specific test files to make improvements more approachable

* protocol: remove the port parameter from query, as there are no other known ports, fix docstrings

* Revise docstrings, remove superfluous information and remove unused methods ({set,get_icon} and set_time)

* cli: indent device output to make it more easily readable when having multiple devices

* remove adjust flake8 ignores (we have no setup.py anymore)

* pyproject: include cli tool to coverage, add config for interrogate (docstring coverage)

* bulb: raise exception on color_temp error cases instead of returning zero values

* improve bulb tests, simplify conftest

* strip: rename plugs property to children and move it to smartdevice
2020-05-27 16:55:18 +02:00
Teemu R
012436c494
Improve dimmer support (#62)
* discover dimmers properly

* fix circular import, hopefully

* add is_color to SmartDevice API

* allow changing the dimming without implicitly turning the device on

* Add tests for device type handling for discovery data, make sure new fixtures are added to categories inside conftest
2020-05-20 21:17:33 +02:00
Teemu R
524d28abbc
Remove sync interface, add asyncio discovery (#14)
* do not update inside __repr__

* Convert discovery to asyncio

* Use asyncio.DatagramProtocol
* Cleanup parameters, no more positional arguments

Closes #7

* Remove sync interface

* This requires #13 to be merged. Closes #12.
* Converts cli to use asyncio.run() where needed.
* The children from smartstrips is being initialized during the first update call.

* Convert on and off commands to use asyncio.run

* conftest: do the initial update automatically for the device, cleans up tests a bit

* return subdevices alias for strip plugs, remove sync from docstrings

* Make tests pass using pytest-asyncio

* Simplify tests and use pytest-asyncio.
* Removed the emeter tests for child devices, as this information do not seem to exist (based on the dummy sysinfo data). Can be added again if needed.
* Remove sync from docstrings.

* Fix incorrect type hint

* Add type hints and some docstrings to discovery
2020-01-12 22:44:19 +01:00
Teemu R
3ef5086ffb mass rename to (python-)kasa (#1) 2019-12-18 09:11:18 +01:00