Commit Graph

604 Commits

Author SHA1 Message Date
Teemu R
53021f07fe
Add support for pydantic v2 using v1 shims (#504) 2023-08-28 17:48:49 +02:00
Norman Rasmussen
4b99351dd6
Add toggle command to cli (#498) 2023-08-26 14:21:38 +02:00
sdb9696
064e3fe560
Add discovery timeout parameter (#486)
* Add discovery timeout parameter

* Rename variable to be more pythonic
2023-08-03 14:24:46 +02:00
sdb9696
176ced9e6e
Add new HS100(UK) fixture (#489) 2023-08-03 13:20:09 +02:00
J. Nick Koston
677ef9c3ef
Add tests for KP200 (#483)
* Add tests for KP200

This one worked out of the box sans the OUI not being in the list

https://github.com/home-assistant/core/pull/97062

* it is a strip
2023-07-22 23:55:42 +02:00
J. Nick Koston
117a7ac64a
Replace asyncio.wait_for with async-timeout (#480)
asyncio.wait_for has some underlying problems that are only fixed in cpython 3.12.

Use async_timeout instead until the minimum supported version is 3.11+ and it can be replaced with asyncio.timeout

See https://github.com/python/cpython/pull/98518
2023-07-21 11:50:54 +02:00
Viktar Karpach
9b039d8374
Make device port configurable (#471) 2023-07-10 01:55:27 +02:00
xinud190
b83986bd51
Add fixture for KP405 Smart Dimmer Plug (#470)
* Add files via upload

* Add to KP405 to dimmers, update README

---------

Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
2023-06-30 02:53:23 +02:00
J. Nick Koston
afd54d11d3
Add optional kasa-crypt dependency for speedups (#464)
If installed, use the optimized protocol encryption procedures implemented as a C extension by kasa-crypt (https://pypi.org/project/kasa-crypt/
2023-06-30 02:43:01 +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
Brian Davis
9550cbd2f7
Exclude querying certain modules for KL125(US) which cause crashes (#451)
* commented out modules that break

* added exclusion logic to smartdevice.py

* cleaning up a name

* removing test fixture that isn't related to this PR

* incorporating PR feedback

* fixed an if statement

* reduced exclusion list to just 'cloud'

* Tidy up the issue comment

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

* this seems to be what the linter whats

---------

Co-authored-by: Teemu R. <tpr@iki.fi>
2023-05-18 17:04:24 +02:00
Teemu R
39310f3f02
Remove importlib-metadata dependency (#457)
This is no longer needed, as python 3.8 has native importlib.metadata
2023-05-17 20:33:02 +02:00
Teemu R
ce58cc1a6a
Add methods to configure dimmer settings (#429) 2023-05-17 20:10:39 +02:00
Teemu R
18ce40b6bb
Add inactivity setting for the motion module (#453)
* Add inactivity setting for the motion module

* Fix set_cold_time payload

Co-authored-by: Matt Whitlock <whitslack@users.noreply.github.com>

* Add mention about "smart control"

---------

Co-authored-by: Matt Whitlock <whitslack@users.noreply.github.com>
2023-05-17 20:08:05 +02:00
Teemu R
ce5821a35f
Drop python 3.7 support (#455)
* Drop python 3.7 support

* CI: drop 3.7 and add 3.11

* Remove skipifs that were required for <3.8

* Use pypy-3.8 for CI, re-enable pypy for windows to see if it works now

* Bump readthedocs to use py3.8

* Remove py3.7 failure comment
2023-05-17 20:03:08 +02:00
Teemu R
233f1c9534
Cleanup fixture filenames (#448)
* Mark mocked fixtures as such

* Use consistent filenames including the swver

* Remove executable bit

* Remove duplicate KL130(US)

* Remove unnecessary mocks where we have real ones available

* Fix filenames in tests
2023-04-01 17:10:46 +02:00
Teemu R
505b63dd55
Allow effect presets seen on light strips (#440)
* Make hue, saturation and color_temp optional for smartbulbpresets

* Adjust bulb preset attributes for effect mode

* Don't send None values on save_preset

* Add tests for save_preset payloads
2023-04-01 16:15:58 +02:00
Teemu R
4d514f983b
Return result objects for cli discover and implicit 'state' (#446)
This will make --json to output relevant contents even when no command is defined (i.e., when calling 'kasa --host <host> --json' or 'kasa --target <bcast> --json'.
2023-03-30 01:53:38 +02:00
Teemu R
02c857d472
Some release preparation janitoring (#432)
* Use myst-parser for readme.md doc injection

* Relax version pins

* Define bug tracker and doc links for pypi

* Update pre-commit hooks
2023-02-18 22:09:35 +01:00
Teemu R
016f4dfd19
Add support for json output (#430)
* Add json support

* Add tests

* Check if test_json_output works on ci using py3.8+

* Add a proper note why py3.7 test for json_output are disabled
2023-02-18 21:41:08 +01:00
Teemu R
1212715dde
Minor fixes to smartbulb docs (#431) 2023-02-18 21:17:19 +01:00
Julian Davis
43ed47eca8
Return usage.get_{monthstat,daystat} in expected format (#394)
* Basic fix for issue: https://github.com/python-kasa/python-kasa/issues/373
Change usage module get_daystat and get_monthat to return dictionaries of date index: time values as spec'd instead of raw usage data. Output matches emeter module get_daystat and get_monthstat

* Fixed some formatting and lint warnings to comply with black/flake8
Use the new _convert function in emeter for all conversions rather than the one in smartdevice.py
Removed unused function _emeter_convert_emeter_data from smartdevice.py

* Added a first pass test module for testing the new usage conversion function

* Changes based on PR feedback
Tidied up some doc string comments
Added a check for explicit values from conversion function

* Rebase on top of current master, fix docstrings

---------

Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
2023-02-18 20:53:02 +01:00
Teemu R
12c98eb58d
Add transition parameter to lightstrip's set_effect (#416) 2023-02-18 18:03:54 +01:00
Teemu R
92636fe82d
Pretty-print all exceptions from cli commands (#428)
Print out the repr of captured exception instead of full traceback
2023-02-18 17:32:03 +01:00
Teemu R
dd044130d4
Use rich for prettier output, if available (#403)
Use rich for prettier output, if available.

This does not add a new dependency, but rather uses rich if it's installed.
2023-02-18 17:31:06 +01:00
Teemu R
6e7a588d40
Add brightness to lightstrip's set_effect (#415)
* Add brightness parameter to lightstrip's set_effect

* Use None as default as effects have different default brightnesses
2023-01-21 00:25:59 +01:00
Teemu R
327efb6c65
Update pre-commit hooks (#401)
* Update pre-commit hooks

* Fix implicit optionals
2022-11-15 19:05:08 +01:00
Julian Davis
866c8d6db5
Fix pytest warnings about asyncio (#397)
Turn on ayncio auto mode for pytest and remove the global async marking flag
2022-11-13 23:34:47 +01:00
Teemu R
9cb2a56405
Add a note that transition is not supported by all devices (#398) 2022-11-11 21:06:54 +01:00
Aric Forrest
ec06331737
Adding cli command to delete a schedule rule (#391)
* adding cli option to delete rule

* resolving black linting issue

* simplifying command name

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

* updating rule filter

Co-authored-by: Teemu R. <tpr@iki.fi>
2022-11-03 02:11:24 +01:00
Teemu R
ef98c2aed9
Implement changing the bulb turn-on behavior (#381)
* Implement changing the bulb turn-on behavior

* Improve docstrings a bit

* Improve docs and expose TurnOnBehavior(s)

* fix typing
2022-10-27 17:40:54 +02:00
Julian Davis
1ac6c66277
Fix type hinting issue with call to click.Choice (#387)
* Fix type hinting issue with call to click.Choice which takes a Sequence not dictionary. Convert TYPE_TO_CLASS keys to a list to pass in.

* Update kasa/cli.py

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

Co-authored-by: Jules Davis <jules@focalpointvr.com>
Co-authored-by: Teemu R. <tpr@iki.fi>
2022-10-27 17:40:24 +02:00
Teemu R
f32f7f3925
Add support for bulb presets (#379)
* Add support for bulb presets

* Update docs
2022-10-23 00:15:47 +02:00
Teemu R
13052ac7a1
Fix year emeter for cli by using kwarg for year parameter (#372)
* Fix year emeter for cli by using kwarg for year parameter

* Improve tests

* Skip test_emeter on python3.7
2022-10-03 20:28:05 +02:00
Felix Yan
7aebef56ca
Correct typos in smartdevice.py (#358) 2022-07-17 19:19:09 +02:00
gritstub
57fac9a156
Add fixtures for KS200M (#356) 2022-06-28 18:53:23 +02:00
gritstub
d7295bdf6d
Add fixtures for ES20M (#353) (#354)
Co-authored-by: Teemu R <tpr@iki.fi>
2022-06-28 13:06:34 +02:00
gritstub
4c55289255
Add fixtures for KS230 (#355) 2022-06-28 12:56:36 +02:00
James Alseth
91ba1d5ac6
Add KP125 test fixture and support note. (#350)
* Add KP125 test fixture and support note.

Signed-off-by: James Alseth <james@jalseth.me>

* mark KP125 having an emeter

Co-authored-by: Teemu R <tpr@iki.fi>
2022-06-27 03:39:57 +02:00
J. Nick Koston
8e6cfd003e
Add fixtures for KP100 (#343)
* Add fixtures for KP100

* readme
2022-05-11 16:02:17 +02:00
J. Nick Koston
d908a5ab2a
Avoid retrying open_connection on unrecoverable errors (#340)
* Avoid retrying open_connection on unrecoverable errors

- We can retry so hard that we block the event loop

Fixes
```
2022-04-16 22:18:51 WARNING (MainThread) [asyncio] Executing <Task finished name=Task-3576 coro=<open_connection() done, defined at /opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/streams.py:25> exception=ConnectionRefusedError(61, "Connect call failed (192.168.107.200, 9999)") created at /opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py:460> took 1.001 seconds
```

* comment
2022-04-24 19:38:42 +02:00
J. Nick Koston
d2581bf077
Add fixtures for kl420 (#339)
* Add fixtures for kl420

* readme
2022-04-14 02:51:15 +02:00
Teemu R
631762b50c
Drop deprecated, type-specific options in favor of --type (#336)
* Drop deprecated, type-specific options in favor of --type

* Fix tests
2022-04-06 03:39:50 +02:00
Teemu R
6e988bd9a9
Avoid discovery on --help (#335) 2022-04-06 02:25:47 +02:00
Teemu R
a39cef9a8c
Export modules & make sphinx happy (#334) 2022-04-06 01:41:08 +02:00
Teemu Rytilahti
2a0919efd5 Fix linting 2022-04-05 19:27:46 +02:00
J. Nick Koston
1e4df7ec1b Fix modularize with strips (#326)
* Fix test_deprecated_type stalling

* Fix strips with modularize

* Fix test_deprecated_type stalling (#325)
2022-04-05 19:27:46 +02:00
Teemu Rytilahti
f0d66e4195 move get_time{zone} out from smartdevice + some minor cleanups 2022-04-05 19:27:46 +02:00
Teemu Rytilahti
c8ad99abcb Use device time for on_since for smartstripplugs 2022-04-05 19:27:46 +02:00
Teemu Rytilahti
bb013e75da Raise an exception when trying to access data prior updating 2022-04-05 19:27:46 +02:00
Teemu R
3a7836cd33 Do not request unsupported modules after the initial update (#298)
* Do not request unsupported modules after the initial update

* debugify logging
2022-04-05 19:27:46 +02:00
Teemu R
8c7b1b4a68 Implement motion & ambient light sensor modules for dimmers (#278) 2022-04-05 19:27:46 +02:00
Teemu R
e3588047fc Improve usage module, consolidate API with emeter (#249)
* Consolidate API for both emeter&usage modules
* Add new cli command 'usage' to query usage
2022-04-05 19:27:46 +02:00
Teemu R
3926f3224f Add module support & query their information during update cycle (#243)
* Add module support & modularize existing query

This creates a base to expose more features on the supported devices.
At the moment, the most visible change is that each update cycle gets information from all available modules:
* Basic system info
* Cloud (new)
* Countdown (new)
* Antitheft (new)
* Schedule (new)
* Time (existing, implements the time/timezone handling)
* Emeter (existing, partially separated from smartdevice)

* Fix imports

* Fix linting

* Use device host instead of alias in module repr

* Add property to list available modules, print them in cli state report

* usage: fix the get_realtime query

* separate usage from schedule to avoid multi-inheritance

* Fix module querying

* Add is_supported property to modules
2022-04-05 19:27:46 +02:00
J. Nick Koston
766819a2a4
Ensure bulb state is restored when turning back on (#330)
* Ensure state is restored when turning back on

Fixes https://github.com/home-assistant/core/issues/69039

* Update kasa/tests/test_bulb.py

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

Co-authored-by: Teemu R. <tpr@iki.fi>
2022-04-05 18:51:36 +02:00
J. Nick Koston
2b05751aa7
Fix test_deprecated_type stalling (#325) 2022-03-24 23:59:53 +01:00
J. Nick Koston
58f6517445
Add effect support for light strips (#293)
* Add effect support for KL430

* KL400 supports effects

* Add KL400 fixture

* Comments from review

* actually commit the remove
2022-03-21 22:10:12 +01:00
Teemu R
b22f6b4eef
Don't crash on devices not reporting features (#317)
Returns an empty set if no feature information is available
2022-03-02 16:29:20 +01:00
Teemu R
db170cf1f5
Allow using environment variables for discovery target, device type and debug (#313)
* KASA_TYPE defines the device type (bulb, plug, dimmer, strip, lightstrip)
* KASA_TARGET to define discovery target
* KASA_DEBUG to enable debugging
2022-02-15 16:59:36 +01:00
Teemu R
b61c0feea9
Add 'internal_state' to return the results from the last update query (#306)
This can be useful for debugging purposes, e.g., for homeassistant diagnostics
2022-02-07 09:13:47 +01:00
Teemu R
700f3859c2
Guard emeter accesses to avoid keyerrors (#304)
Raise an exception to inform the caller that update() is needed
2022-02-02 19:31:11 +01:00
Teemu R
9ea83388ac
cli: cleanup discover, fetch update prior device access (#303)
* Use on_discovered for smoother user experience
* Remove --discover-only as unnecessary
2022-02-02 19:30:48 +01:00
J. Nick Koston
c865d3f02c
Fix unsafe __del__ in TPLinkSmartHomeProtocol (#300)
* Fix unsafe __del__ in TPLinkSmartHomeProtocol

Fixes
```
Exception ignored in: <function TPLinkSmartHomeProtocol.__del__ at 0x1096d0670>
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/venv/lib/python3.9/site-packages/kasa/protocol.py", line 159, in __del__
    self.writer.close()
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/streams.py", line 353, in close
    return self._transport.close()
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 700, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 748, in call_soon
    self._check_thread()
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 785, in _check_thread
    raise RuntimeError(
RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one
```

* comment

* comment

* comment
2022-01-30 23:00:00 +01:00
mrbetta
5bf6fda7ee
Added a fixture file for KS220M (#273)
* Added motion and light sensor for KS220M

* Added fixture file for ks220m

* Remove dump_devinfo and add the extra queries to devtools/dump_devinfo

* Test KS220M as a dimmer

* Add empty modules to baseproto to make the tests pass

Co-authored-by: mrbetta <bettale@gmail.com>
Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
2022-01-29 18:28:14 +01:00
Teemu R
6a31de5381
Drop microsecond precision for on_since (#296) 2022-01-29 17:02:05 +01:00
Teemu R
bcb9fe18ab
Improve typing for protocol class (#289) 2022-01-14 23:08:25 +01:00
Teemu R
6ece506a3b
Relax asyncclick version requirement (#286)
* Add package_name to version_option(), breaks --version on click < 8
2022-01-14 16:32:32 +01:00
Teemu R
723fca9d08
Do not crash on discovery on WSL (#283) 2022-01-08 17:48:01 +01:00
Teemu R
a817d9cab1
Add python 3.10 to CI (#279)
* Add python 3.10 to CI

* Require pytest >=6.2.5

Required for running on python 3.10 (https://github.com/pytest-dev/pytest/pull/8540)

* Update lockfile

* Update pre-commit hooks
2021-12-17 17:48:03 +01:00
Teemu R
d2efaf5090
Add --type option to cli (#269)
* Add support for controlling dimmers
* Deprecate --bulb, --plug, --strip, --lightstrip
2021-12-13 20:17:54 +01:00
ErikSGross
6b18c5cd55
Add fixture file for KL135 (#263)
* Create new fixture file for KL135

* Add KL135 to COLOR_BULBS and VARIABLE_TEMP lists
2021-12-06 16:31:27 +01:00
Teemu R
a468d520c0
Add KL135 color temperature range (#256) 2021-11-19 18:08:20 +01:00
Teemu R
351e86bfa3
Add py.typed to flag that the package is typed (#251) 2021-11-15 18:21:24 +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
85a618f7c6
Add KP401 fixture (#234) 2021-10-11 17:13:00 +02:00
J. Nick Koston
cf151ead4a
Add KL60 US KP105 UK fixture (#233)
* Add KL60 US fixture

* Add KP105 UK fixture

* update test
2021-10-09 16:44:32 +02:00
Teemu R
e06b9a71e5
Make cli interface more consistent (#232) 2021-10-09 16:36:36 +02:00
J. Nick Koston
c65705bbbf
Add KL400, KL50 fixtures (#231)
* Add KL400 fixture

* Add KL400 fixture

* Add KL50 fixture

* tweaks
2021-10-08 00:15:32 +02:00
J. Nick Koston
98b4155c11
Add fixture for newer KP400 firmware (#227) 2021-10-04 20:40:31 +02:00
J. Nick Koston
0bcab39e60
Add fixtures for LB110, KL110, EP40, KL430, KP115 (#224)
* Add fixtures for LB110, KL110, EP40

* update schema

* kl430 fixture

* Add KP115 US fixture
2021-10-02 15:41:14 +02:00
J. Nick Koston
33bc38b57f
Fix lock being unexpectedly reset on close (#218)
* Implement a backoff for legacy devices

* do not clear self.query_lock at close()

* revert backoff
2021-09-26 19:38:33 +02:00
Teemu R
3cf549e32e
Add host information to protocol debug logs (#219) 2021-09-26 19:16:12 +02:00
J. Nick Koston
76c1264dc9
Avoid calling pformat unless debug logging is enabled (#217)
* Avoid calling pformat unless debug logging is enabled

* add logging test

* isort

* check for debug logging

* formatting
2021-09-26 16:50:58 +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
f1b28e79b9
Add KL130 fixture, initial lightstrip tests (#214) 2021-09-24 22:26:21 +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
J. Nick Koston
94e5a90ac4
Add emeter support for strip sockets (#203)
* Add support for plugs with emeters.

* Tweaks for emeter

* black

* tweaks

* tweaks

* more tweaks

* dry

* flake8

* flake8

* legacy typing

* Update kasa/smartstrip.py

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

* reduce

* remove useless delegation

* tweaks

* tweaks

* dry

* tweak

* tweak

* tweak

* tweak

* update tests

* wrap

* preen

* prune

* prune

* prune

* guard

* adjust

* robust

* prune

* prune

* reduce dict lookups by 1

* Update kasa/smartstrip.py

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

* delete utils

* isort

Co-authored-by: Brendan Burns <brendan.d.burns@gmail.com>
Co-authored-by: Teemu R. <tpr@iki.fi>
2021-09-24 00:24:44 +02:00
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
Andrew May
5ff299664e
Add in some new device types (#39)
* Add in some new device types

HS103 hardware 1.0 and 2.1
KP400

* Update conftest
2020-04-11 03:08:59 +02:00
J. Nick Koston
18d58388c1
Add test fixture for KL130 (#35)
* Add test fixture for KL130

* Update test
2020-04-10 16:16:50 +02:00
Teemu R
e9b0acaaa7
Enable Windows & OSX builds (#31)
* Enable Windows & OSX builds

* Add pypy for ubuntu

* Fix isort

* Disable PyPy

typed-ast building fails due to a missing header
ast27/Parser/tokenizer.c:17:10: fatal error: codecs.h: No such file or directory
2020-03-18 00:40:06 +01:00
Teemu R
00276e34b7
Move child socket handling to its own SmartStripPlug class (#26)
* All child device handling is moved out from the main smartdevice class, which simplifies the code.
* This will also cleanup the constructors as only the subdevices require the ID and the parent reference.
* SmartStripPlug offers SmartPlug like interface, but does not allow separate updates
  * Trying to update() on the children will cause a warning.
2020-03-16 14:52:40 +01:00
Teemu R
489a550582
Add KP303 to the list of powerstrips (#28)
Should fix #27
2020-03-16 14:52:24 +01:00
Alex Cragg
15b0c8c0e6 Adding KP303 to supported devices (#25)
* Adding KP303(UK)_1.0.json

Adding the result file for the KP303 from kasa dump-discover

* Update readme to include KP303 as a supported device
2020-01-28 14:58:20 +01:00
Angelo Gagliano
3337c574ce Remove unused save option and add scrubbing (#19)
* Removes unused save option and adds scrubbing

* Defaults to scrub and adds no-scrub option

* Adds latitude and longitude to the scrub list
2020-01-15 14:46:35 +01:00
Teemu R
80f097b5b3 use pytestmark to avoid repeating asyncio mark (#24) 2020-01-15 07:49:31 +01:00
Teemu R
72d6205ad2 Cleanup constructors by removing ioloop and protocol arguments (#23)
* Cleanup constructors by removing ioloop and protocol

* force kwarg for other arguments besides the host
2020-01-15 07:46:21 +01:00
Teemu R
7eea21f2dd
test the newly added device fixtures (#21)
* make fixture detection saner
* allow scrubbed locations
2020-01-14 19:16:30 +01:00
Angelo Gagliano
87c0dab8c8 Add real kasa device dumps (#18)
* Adds real kasa device dumps

* Adds newline to the end of the files
2020-01-14 13:34:57 +01:00
Teemu R
822ab3f8ac Fix dump-discover to use asyncio.run (#16) 2020-01-13 08:52:52 +01:00
Teemu R
0f0df481a0
Add device_id property, rename context to child_id (#15)
For regular devices, device_id is the mac address and for child devices it is a combination of the mac address and the child_id.
2020-01-13 00:17:45 +01: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
3c68d295da
Remove --ip which was just an alias to --host (#6) 2020-01-12 20:29:19 +01:00
Teemu R
4a25cbfff7
Set minimum requirement to python 3.7 (#5) 2020-01-12 20:27:53 +01:00
Teemu R
3ef5086ffb mass rename to (python-)kasa (#1) 2019-12-18 09:11:18 +01:00