Commit Graph

978 Commits

Author SHA1 Message Date
Teemu R
4a25cbfff7
Set minimum requirement to python 3.7 (#5) 2020-01-12 20:27:53 +01:00
Bas Nijholt
161c3eb53b change ID of Azure Pipeline (#3) 2019-12-18 12:33:32 +01:00
Teemu R
3ef5086ffb mass rename to (python-)kasa (#1) 2019-12-18 09:11:18 +01:00
Bas Nijholt
624c44c27f multiply by 1000 instead of 10^3 2019-12-12 11:13:18 +01:00
Bas Nijholt
8d1e0acbba remove Travis CI 2019-12-12 11:09:53 +01:00
Bas Nijholt
ad209de268 fix mympy's error "Decorated property not supported" (mypy bug)
See https://github.com/python/mypy/issues/1362
2019-12-12 10:46:40 +01:00
Bas Nijholt
122cd4c19f run pre-commit run --all 2019-12-12 10:41:52 +01:00
Bas Nijholt
338e6ce743 add more pre-commit hooks 2019-12-12 10:41:36 +01:00
Bas Nijholt
a96af31116 replace Travis badge with Azure pipelines 2019-12-12 10:34:13 +01:00
Bas Nijholt
72d5443f1a implement methods that depend on sys_info as properties and add update
In the case of smartbulb.update, light_state is also updated.
2019-11-16 17:22:37 +01:00
Bas Nijholt
8c25590186 simplify loop in __init__ in smartstrip.py 2019-11-15 16:51:01 +01:00
Bas Nijholt
b2ca20edf0 use f-strings or format 2019-11-15 16:35:42 +01:00
Bas Nijholt
e39c6dbfa2 fix pre-commit issues 2019-11-15 16:28:02 +01:00
Bas Nijholt
1779e6e122 fix bug in cli.state 2019-11-15 16:11:55 +01:00
Bas Nijholt
2976c453ac improve doc-strings 2019-11-15 16:05:46 +01:00
Bas Nijholt
a7cb2cebed use tox.ini in hound 2019-11-15 14:31:01 +01:00
Bas Nijholt
09d620df01 Merge remote-tracking branch 'upstream/azure_pipelines' into asyncio 2019-11-15 14:17:00 +01:00
Bas Nijholt
190a800e77 only support >= 3.6 2019-11-11 23:15:57 +01:00
Bas Nijholt
cc900ae491 tmp: comment out 2 failing tests 2019-11-11 23:10:57 +01:00
Bas Nijholt
b2973cda6c fix the tests 2019-11-11 23:02:50 +01:00
Teemu Rytilahti
b5e585e1f8 export __version__ under the main module 2019-11-11 22:33:23 +01:00
Teemu Rytilahti
751c2445c2 add missing version.py 2019-11-11 22:30:37 +01:00
Teemu Rytilahti
8a131e1eeb Add precommit hooks & tox env to enforce code structure, add azure pipelines
Instead of leveraging hound & travis, add an option for azure pipelines,
which may replace the former in the future.

This also streamlines the contributing guidelines by:
* Adding pre-commit hooks to run isort, black, flake8, mypy
* Adding lint environment to allow checks to be run `tox -e lint`

This also contains a major cleanup to the SmartStrip handling which was due.
After seeing #184 I thought I should push this in as it is for comments before the codebase diverges too much.
2019-11-11 22:14:34 +01:00
Bas Nijholt
583c785611 prefer sync attribute over asyncio.run 2019-11-11 21:06:50 +01:00
Bas Nijholt
9907c6416b isort and black on the tests 2019-11-11 20:31:56 +01:00
Bas Nijholt
55d898b547 use absolute imports 2019-11-11 20:30:29 +01:00
Bas Nijholt
8a7d955eb7 use the "sync" attribute to call methods in the CLI 2019-11-11 20:29:18 +01:00
Bas Nijholt
e6faf9dd05 change cli.py message in according with setup.py 2019-11-11 20:29:18 +01:00
Bas Nijholt
0c1d8b6efe implement SyncSmartDevice and sort imports and use absolute imports 2019-11-11 20:29:18 +01:00
Bas Nijholt
30677b2af0 black setup.py 2019-11-11 20:29:18 +01:00
Bas Nijholt
b2d0a511a5 define __all__ ( also gets rid of flake8 issues) 2019-11-11 20:29:18 +01:00
Bas Nijholt
533c6b5ca2 pass an ioloop 2019-11-11 19:16:55 +01:00
Bas Nijholt
7d3d105e47 remove unused imports 2019-11-11 18:19:45 +01:00
Bas Nijholt
ba2600cb93 make SmartStrip use asyncio 2019-11-11 18:19:45 +01:00
Bas Nijholt
b6a0542f43 make SmartPlug use asyncio 2019-11-11 18:19:45 +01:00
Bas Nijholt
7c69d3c03a make SmartBulb use asyncio 2019-11-11 18:19:45 +01:00
Bas Nijholt
904bbe5c1a make SmartDevice use asyncio 2019-11-11 18:19:45 +01:00
Bas Nijholt
af0a1d61b1 use asyncio.run in tests instead of awaiting 2019-11-11 17:03:45 +01:00
Bas Nijholt
3b27f7d7e7 use asyncio.run on coroutines in cli.py 2019-11-11 17:01:42 +01:00
Bas Nijholt
0e0ab1dfc9 change functions that use query to await 2019-11-11 16:56:39 +01:00
Bas Nijholt
8f59d74e29 implement TPLinkSmartHomeProtocol.query with asyncio 2019-11-11 16:52:13 +01:00
Teemu R
59424d2738
Fix cli status reporting, blackify cli.py (#182)
Fixes #181
2019-10-26 14:21:08 +02:00
Ville Skyttä
752b24c4ec Python < 3.5 cleanups (#180)
* tox: remove Python < 3.5 config

* deps: drop typing, included in Python 3.5+
2019-08-13 16:55:18 -04:00
Christopher Fricke
c9280c70c0 Fix __repr__ function of SmartDevice (#178) 2019-07-26 15:21:25 -04:00
kochinc
2c79febae4 Allow specifying broadcast address for discovery (#176)
* Allow specifying broadcast address

In situations such as multiple network interfaces, it may be necessary to specify the broadcast address so that the discovery message is sent to the desired local network.

* Added the option to specify broadcast address

Sometimes it's necessary to specify what broadcast address it should send the discovery message. For instance, there are multiple network interfaces on the host.

* Get target from parent context when in subcommand

Since --target is a top-level option and we want to use it in subcommands, use ctx.parent.params['target'] to retrieve it.

* Removed the trailing space.

* Deleted commented out line
2019-07-25 00:21:24 -04:00
Daniel Berlin
fa0c2d82e8 Fix CLI for HS300 (#177) 2019-07-25 00:17:13 -04:00
Teemu R
2d60467bea
API and tests cleanup (#151)
* Add new cli commands: raw_command and dump_discover

- raw_command can be used to execute raw commands with given parameters
  * Useful for testing new calls before implementing them properly

- dump_discover can be used to dump the device discovery information (into a file)
  * The discovery is extended to request more modules and methods from devices
    * smartlife.iot.dimmer get_dimmer_parameters
    * smartlife.iot.common.emeter get_realtime
    * smartlife.iot.smartbulb.lightingservice get_light_state
  * This is used to dump more information for proper tests, and will also allow better discovery in the future

This commit contains also some documentation updates and dropping click_datetime in favor of click's built-in datetime

* Docstring fixes

* Major API cleanup

Properties shall no more change the state of the device, this work in still in progress, the main goal being making the API more user-friendly and to make implementing new features simpler.

The newly deprecated functionality will remain working and will simply warn the user about deprecation.
Previously deprecated 'features' property and 'identify' method are now finally removed.

Deprecate and replace the following property setters:
* state with turn_on() and turn_off()
* hsv with set_hsv()
* color_temp with set_color_temp()
* brightness with set_brightness()
* led with set_led()
* alias with set_alias()
* mac with set_mac()

And getters:
* state with is_on and is_off

The {BULB,PLUG}_STATE_{ON,OFF} is simplified to STATE_ON and STATE_OFF, UNKNOWN state is removed.
These are now deprecated and will be removed in the future.
* is_on and is_off can be used to check for the state
* turn_on() and turn_off() for changing the device state.

Trying to use functionality not supported by the device will cause SmartDeviceExceptions instead of failing silently and/or returning None.
This includes, e.g., trying to set a color temperature on non-supported bulb.

ValueErrors are raised instead of SmartDeviceExceptions where appropriate (e.g. when trying to set an invalid hsv or brightness).

New enum type DeviceType is added to allow detecting device types without resorting to isinstance() calling. SmartDevice class' device_type property can be used to query the type. is_plug and is_bulb helpers are added.

* Cleanup tests and improve test coverage

* Make writing tests easier by sharing code for common implementations
* Instead of storing test data inside python files, dump-discover based information is used
  * This will simplify adding new tests and remove code duplication
  * fixtures are based on https://github.com/plasticrake/tplink-smarthome-simulator

* run black on newfakes

* Add HS300 tests and update SmartStrip API according to earlier changes, still WIP

* run black and avoid wildcard imports

* Black on conftest

* bump minimum required version to 3.5

* Rename fixture_tests to test_fixtures for autocollect

* fix typoed type to _type, black

* run black on several files with -79 to fix hound issues

* Fix broken merge on hue

* Fix tests (hue update, pass context to smartdevice), add is_strip property, disable emeter tests for HS300 until a solution for API is found.

* Fix old tests

* Run black on changed files

* Add real HS220 discovery, thanks to @poiyo

* add is_dimmable and is_variable_color_temp to smartdevice class, simplifies interfacing with homeassistant

* add KL120(US) fixture

* Add a simple query cache

This commit adds a simple query cache to speed up the process for users
requesting lots of different properties from the device, as done by the
cli tool as well as homeassistant.

The logic for caching is very simple:
1. A timestamp for last fetch for each module+command is stored alongside the response.
2. If the issued command starts with `get_` and the TTL has not expired, the cache result is returned.
3. Otherwise the cache for the whole corresponding module gets invalidated, the device will be queried and the result will be stored in the cache.

* add deprecation to tox.ini

* make tests pass again

* remove old tests, add flake8 to tox reqs

* run black against pyhs100 module, add it to precommit hooks, fix flake8 configuration to conform to black standards (https://ljvmiranda921.github.io/notebook/2018/06/21/precommits-using-black-and-flake8/)

* fix syntax

* cleanup conftest
2019-06-16 17:05:00 -04:00
Teemu R
e82746da24
Fix temperature range for KL120, the device can only do up to 5000 k (#174)
* Fix temperature range for KL120, the device can only do up to 5000 kelvin

* use different temperature range for US and EU models of KL120
2019-06-09 18:28:51 -04:00
Teemu R
a475233464
Check for errors also in the command payload (#173)
For example, trying to set unsupported color temperature will cause such response.
This gets ignored at the moment completely, so there is no indication at all why the command caused no effect on the device.

> (93) {"smartlife.iot.smartbulb.lightingservice": {"transition_light_state": {"color_temp": 6000}}}
< (125) {"smartlife.iot.smartbulb.lightingservice":{"transition_light_state":{"err_code":-10000,"err_msg":"Invalid input argument"}}}
2019-06-03 09:58:03 -04:00
Teemu R
60add6fa66
Improve discovery by sending multiple UDP datagrams (#172)
As UDP datagrams may get lost in transit, e.g.,  due to poor network connectivity,
we can improve the detection rate by sending multiple datagrams and hoping some
will get through to the devices.

Confirmed to improve the detection by @scubanarc: https://github.com/home-assistant/home-assistant/issues/21966

This is a new configurable option, defaulting to three discover packets.
2019-05-20 21:56:01 -04:00