Commit Graph

67 Commits

Author SHA1 Message Date
J. Nick Koston
b3c8f9769c
Avoid temp array during encrypt and decrypt (#204)
* Avoid temp array during encrypt

* black

* Update kasa/protocol.py

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

* Update kasa/protocol.py

* update decrypt as well

Co-authored-by: Teemu R. <tpr@iki.fi>
2021-09-23 18:11:16 +02:00
Teemu R
36c412a9c2
Improve emeterstatus API, move into own module (#205)
Adds the following properties to EmeterStatus for saner API:
* voltage (in V)
* power (in W)
* current (in A)
* total (in kWh)
2021-09-23 17:58:19 +02:00
Teemu R
47a1405bd2
Add KP115 fixture (#202) 2021-09-21 19:20:59 +02:00
Teemu R
151976bb04
Add own device type for smartstrip children (#201) 2021-09-21 13:25:14 +02:00
Teemu R
2c83d8ee6d
bulb: allow set_hsv without v, add fallback ct range (#200)
* bulb: allow set_hsv without v, add fallback ct range

* add ColorTempRange and HSV named tuples
* add a fallback color temp range if unknown, log a warning
* set_hsv: the value is now optional

* Fix tests, change fallback range to 2700-5000
2021-09-21 13:23:56 +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
016d030245
Improve bulb support (alias, time settings) (#198)
* Fix set_alias and time related functions for bulbs

* Fix tests for smartlife.iot.common.timesetting and smartlife.iot.common.system
2021-09-19 23:53:17 +02:00
Teemu R
1803a83ae6
Improve testing harness to allow tests on real devices (#197)
* test_cli: provide return values to patched objects to avoid warning about non-awaited calls

* test_cli: restore alias after testing

* smartstrip: remove internal update() calls for turn_{on,off}, set_led

* Make sure power is always a float

* Fix discovery tests

* Make tests runnable on real devices

* Add a note about running tests on a real device

* test_strip: run update against the parent device
2021-09-19 23:45:48 +02:00
Teemu R
b088596205
Perform initial update only using the sysinfo query (#199)
Some devices are known to fail when trying to query non-supported modules like emeter information.
This commit makes the initial update() only request the sysinfo, followed up by a second query
if emeter is supported by the device.
2021-09-19 23:43:17 +02:00
JaydenRA
f8e7258b93
cli: add human-friendly printout when calling temperature on non-supported devices (#196)
* Bug Fix

Temperature is not supported on plugs

* Efficiency on support errors

* Update kasa/cli.py

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

Co-authored-by: Teemu R. <tpr@iki.fi>
2021-09-04 02:18:21 +02:00
Ivan Prodanov
7c9d21af7a
Add real kasa KL430(UN) device dump (#192)
* Add real kasa KL430(UN) device dump

* Adjust hue&sat max values

* light strips, as bulbs, have only power for emeter

Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
2021-08-16 20:16:29 +02:00
Teemu R
4e8a3185fb
Use less strict matcher for kl430 color temperature (#190) 2021-08-16 16:49:28 +02:00
Nathan Hyde
6184c0c72e
Add EP10(US) 1.0 1.0.2 fixture (#174)
* Add EP10(US) 1.0 1.0.2 fixture

* Add EP10 fixture to conftest PLUGS list.

* Add EP10 to the list of supported plugs in README

* Revert "Add EP10 to the list of supported plugs in README"

This reverts commit e8bf6551c3.
2021-06-24 19:43:54 +02:00
Teemu R
0aa20f6cf9
Prepare 0.4.0.dev3 (#172)
* Prepare 0.4.0.dev3

Most notable changes:

* Devices initialized by discovery are pre-initialized using the discovery response data, so no need for update() directly after discovery
* Only the basic information is requested during discovery, as some HS110 and HS220 devices do not respond to multi-module queries
* Fix mac address parsing for KL430
* Add support for KL125 color temperature ranges
* Documentation updates!

* add types-click for mypy hook

* use generator expression for sum
2021-06-16 18:16:45 +03:00
Appleguru
8a3ebbff6d
Add HS220 hw 2.0 fixture (#107)
* Add HS220 hw 2.0 fixture

* Update HS220 v2 profile from dump-discover

* fix linting

Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
2021-05-12 18:04:17 +02:00
Teemu R
c7a47ea1bf
Simplify mac address handling (#162) 2021-05-12 16:07:53 +03:00
Brian Davis
28a902c485
Added KL125 and HS200 fixture dumps and updated tests to run on new format (#160)
* Added new fixtures

* Refactored bulb categories and check for emeter on run

* linting changes
2021-05-11 17:47:52 +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
Teemu R
1ee4757fdb
Return None instead of raising an exception on missing, valid emeter keys (#146)
Fixes #142

Also, update the pre-commit hooks to their newest versions
2021-03-18 19:22:10 +01:00
mdarnol
2fe1b209d0
Add KL125 bulb definition (#143)
Co-authored-by: Mark Arnold <marnold@nvidia.com>
2021-02-27 15:09:33 +01: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
BuongiornoTexas
70061cbe67
Update cli.py to addresss crash on year/month calls and improve output formatting (#103)
* Update cli.py

Fix crash when kasa cli is called with --month or --year arguments.

* Update cli.py

* Fix crash on emeter monthly, yearly cli calls

* Formatting fix.
2020-10-03 20:32:38 +02: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
6844166c0d
add a small example script to show library usage (#90)
* add a small example script to show library usage

* asyncio.run++
2020-07-20 16:42:37 +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
96c15362c3
cli: Fix incorrect use of asyncio.run for temperature command (#85) 2020-07-06 21:46:40 +02:00
Teemu R
4d722e25c1
Add --transition to bulb-specific cli commands, fix turn_{on,off} signatures (#81) 2020-07-06 16:10:28 +02:00
Teemu R
44e2998705
Improve bulb API, force turn on for all light changes as offline changes are not supported (#76)
* Add ignore_default to lights to allow setting to specific light state, force bulb on when changing the settings, allow defining brightness for set_color_temp, add a couple of new API methods

* Fix and simplify transition_light_state to make tests pass
2020-07-06 16:09:30 +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
99e0c4a418
Bulbs: allow specifying transition for state changes (#70)
All state changing functions now allow defining transition time in milliseconds
2020-06-14 20:21:55 +02:00
Connor Proctor
dd073fa8c8
Add transition support for SmartDimmer (#69)
* Adds a transition param to set_brightness(), turn_on(), and turn_off() that specifies the duration in milliseconds that the dimmer switch will take to transition to the new state.
* Fixes bug where set_brightness(0) was allowed even though the dimmer does not support it. Now brightness values of 0 are coerced to 1 to be consistent with bulbs (which do support brightness values of 0).
2020-06-14 18:09:28 +02:00
Teemu R
9dc0cbaece
Add retries to protocol queries (#65)
* Add retries to query(), defaults to 3 + add tests

* Catch also json decoding errors for retries

* add missing exceptions file, fix old protocol tests
2020-05-27 20:02:09 +03: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
836f1701b9
Optimize I/O access (#59)
* Optimize I/O access

A single update() will now fetch information from all interesting modules,
including the current device state and the emeter information.

In practice, this will allow dropping the number of I/O reqs per homeassistant update cycle to 1,
which is paramount at least for bulbs which are very picky about sequential accesses.
This can be further extend to other modules/methods, if needed.

Currently fetched data:
* sysinfo
* realtime, today's and this months emeter stats

New properties:
* emeter_realtime: return the most recent emeter information, update()-version of get_emeter_realtime()
* emeter_today: returning today's energy consumption
* emeter_this_month: same for this month

Other changes:
* Accessing @requires_update properties will cause SmartDeviceException if the device has not ever been update()d
* Fix __repr__ for devices that haven't been updated
* Smartbulb uses now the state data from get_sysinfo instead of separately querying the bulb service
* SmartStrip's state_information no longer lists onsince for separate plugs
* The above mentioned properties are now printed out by cli
* Simplify is_on handling for bulbs

* remove implicit updates, return device responses for actions, update README.md instructions. fixes #61
2020-05-24 17:57:54 +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
e37244de0f
Remove unnecessary f-string definition to make tests pass (#58) 2020-05-13 14:50:45 +02:00
Teemu R
ed57563e8b
Convert to use poetry & pyproject.toml for dep & build management (#54)
* Convert to use poetry and pyproject.toml, update README

* add some resources for contributors

* minor adjustments

* ci: separate tests from linting, run using poetry

* add pytest-mock to dev requirements

* combine running tests and reporting to codecov

* generate both xml and html coverage reports

* add codecov to dev dependencies
2020-05-12 12:11:47 +02:00
Teemu R
c6d76836d7
Add fixture for KL60 (#52) 2020-04-26 17:44:16 +02:00
Teemu R
51af7809ec
Ignore D202 where necessary (#50)
This is required as https://github.com/PyCQA/pydocstyle/pull/426 does not
fix the issue for async def'd inner functions.
2020-04-25 21:21:39 +02:00
Teemu R
28c1811aef
Support wifi scan & join for bulbs using a different interface (#49) 2020-04-24 17:57:04 +03:00
Teemu R
0c71957aa8
Return on_since only when its available and the device is on (#48)
* moves on_since property to smartdevice class, as it is not plug only
* returns None if the value is not available (some bulbs), or if the device is off
2020-04-24 17:47:57 +03:00
Teemu R
fd560442a2
Allow 0 brightness for smartdimmer (#47)
according to https://github.com/home-assistant/core/pull/33909/files#diff-9a900d2f83693dd3e01d2894bf1c6bffR452
the dimmers will accept 0 brightness which differs from turning it off
2020-04-22 10:48:28 +03:00
Teemu R
3fe578cf26
async++, small powerstrip improvements (#46)
* async++, small powerstrip improvements

* use asyncclick instead of click, allows defining the commands with async def to avoid manual eventloop/asyncio.run handling
* improve powerstrip support:
  * new powerstrip api: turn_{on,off}_by_{name,index} methods
  * cli: fix on/off for powerstrip using the new apis
* add missing update()s for cli's hsv, led, temperature (fixes #43)
* prettyprint the received payloads when debug mode in use
* cli: debug mode can be activated now with '-d'

* update requirements_test.txt

* remove outdated click-datetime, replace click with asyncclick

* debug is a flag

* make smartstripplug to inherit the sysinfo from its parent, allows for simple access of general plug properties

* proper bound checking for index accesses, allow controlling the plug at index 0

* remove the mess of turn_{on,off}_by_{name,index}, get_plug_by_{name,index} are enough.

* adapt cli to use that
* allow changing the alias per index

* use f-strings consistently everywhere in the cli

* add tests for get_plug_by_{index,name}
2020-04-21 20:46:13 +02:00
Teemu R
852ae494af
Add (some) tests to the cli tool (#22)
* Add tests to the cli tool

* add pytest-mock

* do not ignore cli.py for coverage

* read requirements_test.txt instead of redefining reqs in tox.ini

* Add upload to codecov, first try!

* fix name of the result file

* no need to manually publish to azure devops..
2020-04-20 20:26:20 +03:00
Teemu R
7f625cd1c2
Add commands to control the wifi settings (#45)
* Add commands to control the wifi settings

Enables initial provisioning and changing the wifi network later on without the official app

* new api to smartdevice: wifi_scan() and wifi_join(ssid, password, keytype)
* cli: new subcommand 'wifi' with two commands: scan and join

* update readme to initial setup

* improvements based on code review, f-strings++
2020-04-20 18:57:33 +02:00
Teemu R
b73c0d222e
Move dimmer support to its own class (#34)
* Move dimmer support to its own class

SmartDimmer extends SmartPlug with brightness settings.
This will make the API of SmartPlug less confusing and will
make it simpler to downstream users to act with dimmers.

Fixes #33

* Lint & make tests pass

* Fix rebase after cache and emeter cleanups, hopefully everything went smoothly..

* oopsie, has_emeter was mistakenly included in smartplug
2020-04-18 23:35:39 +02:00
Andrew May
b6c3a7c54b
Move has_emeter to device level for multiple plug outlets (#41) 2020-04-12 16:00:15 +02:00
Teemu R
c90465c5dd
Remove unnecessary cache (#40)
The cache was useful trick when the property accesses caused I/O,
which is unnecessary now as dev.update() does explicitly cache results until its called again.
2020-04-12 15:57:49 +02:00