Commit Graph

66 Commits

Author SHA1 Message Date
Teemu Rytilahti
92c9cddfd4 return None instead of False for emeter related actions 2017-08-05 17:30:40 +02:00
Teemu R
0927930f41 wrap sysinfo to defaultdict to return None for keys which do not exist, makes unsupported keys not to fail hard (#72) 2017-08-05 17:28:45 +02:00
Teemu R
d15e7be4f3 add hs100 example to fakes.py, thanks to Semant1ka on #67 (#74) 2017-08-05 16:28:11 +02:00
Teemu R
07af48e41a Discover refactoring, enhancements to the cli tool (#71)
* Discover refactoring, enhancements to the cli tool

* Discover tries to detect the type of the device from sysinfo response
* Discover.discover() returns an IP address keyed dictionary,
  values are initialized instances of the automatically detected device type.

* When no IP is given, autodetect all supported devices and print out their states
* When only IP but no type is given, autodetect type and make a call based on that information.
  * One can define --bulb or --plug to skip the detection.

* renamed pyHS100.py -> smartdevice.py

* SmartPlugException -> SmartDeviceException in comments

* fix mic_type check

* make time() return None on failure as we don't know which devices support getting the time and it's used in the cli tool

* hw_info: check if key exists before accessing it, add mic_mac and mic_type

* Check for mic_mac on mac, based on work by kdschloesser on issue #59

* make hound happy, __init__ on SmartDevice cannot error out so removing 'raises' documentation
2017-08-05 15:49:56 +02:00
Sean Gollschewsky
d7aade4e61 Add LB110 sysinfo (#75)
* Add LB110 sysinfo

* Linting.
2017-08-05 15:47:41 +02:00
Teemu R
10544004cc add @pass_dev to hsv, adjust ranges (#70)
* add @pass_dev to hsv command, it was always broken

* Hue goes up to 360, saturation and value are up to 100(%)
2017-08-03 22:13:56 +02:00
Georgi Kirichkov
b7a7fdbfaf Merge pull request #61 from rytilahti/master
Slight refactoring
2017-05-27 09:21:16 +03:00
Teemu Rytilahti
7457ad48f8 extract shared types (exceptions, enums), add module level doc, rename exception to be generic 2017-05-26 16:12:52 +02:00
Matt LeBrun
93d24281c6 Add check to ensure devices with lat/lon with _i suffix are supported (#54) (#56)
* Add check to ensure devices with lat/lon with `_i` suffix are supported (#54)

* Add .gitignore for posterity
2017-04-26 18:43:50 +02:00
Teemu R
09e8948790 generalize smartdevice class and add bulb support for the cli tool (#50)
Fixes #48 and #51. The basic functionality should work on all types of supported devices, for bulb specific commands it is currently necessary to specify ```--bulb```.
2017-04-24 19:28:22 +02:00
Teemu R
86f14642c8 Refactor and drop py2 support (#49)
* move is_off property to SmartDevice, implement is_on for bulb and use it

* refactor by moving smartbulb and smartplug to their own classes

* drop python2 compatibility, make flake8 happy

* travis: remove 2.7, add 3.6
2017-04-14 14:24:58 +02:00
Teemu R
c9662fcb7b add future requirement (#47)
bump the version & add future requirement
2017-04-08 01:58:20 +02:00
Teemu Rytilahti
23e51a8686 cli: display an error if no ip is given
also bump the version to 0.2.4.1 with this fix.
2017-03-26 03:22:18 +02:00
Teemu R
b1cc0fd3f6 Release 0.2.4 preparations (#43) 2017-03-25 23:04:32 +01:00
Teemu R
d253b55d41 Add new client tool (#42)
* Add new client tool

After installing the package pyhs100 command-line tool can be used
to control the plug.

See --help for its usage, most of the features for plugs are implemented,
some of the shared functionality works for bulbs too.

* Add discover command

* Delete old examples, the cli works as an example well enough
2017-03-20 19:03:19 +01:00
hexa-
900b5394f4 Merge pull request #41 from rytilahti/ignore_oserror_on_shutdown
Ignore OSError on socket.shutdown()
2017-03-19 17:15:40 +01:00
Teemu Rytilahti
9d3fbfa975 Ignore OSError on socket.shutdown()
This fixes #22 and obsoletes PR #23.
2017-03-19 15:56:38 +01:00
pete1450
72cbaa2839 set color temp to 0 when trying to change color (#36)
* set color temp to 0 when trying to change color

* changed tabs to spaces
2017-03-17 14:40:48 +01:00
Teemu R
09f915183b Add changelog & add .gitchangelog.rc (#28)
This commits adds .gitchangelog.rc for changelog generation.
To generate, simply run gitchangelog.
2017-03-17 14:38:58 +01:00
Teemu R
1bada16636 discover: Catch socket.timeout and debug log it (#34)
Fixes #33
2017-03-17 14:32:50 +01:00
Teemu R
5dc94cd5c8 Add flake8 to tox, disable qa on pyHS100/__init__.py, fix py27 compatibility (#31) 2017-01-17 21:38:44 +08:00
Matthew Garrett
2d6376b597 Add support for TP-Link smartbulbs (#30)
* Add support for new-style protocol

Newer devices (including my LB130) seem to include the request length in
the previously empty message header, and ignore requests that lack it. They
also don't send an empty packet as the final part of a response, which can
lead to hangs. Add support for this, with luck not breaking existing devices
in the process.

* Fix tests

We now include the request length in the encrypted packet header, so strip
the header rather than assuming that it's just zeroes.

* Create a SmartDevice parent class

Add a generic SmartDevice class that SmartPlug can inherit from, in
preparation for adding support for other device types.

* Add support for TP-Link smartbulbs

These bulbs use the same protocol as the smart plugs, but have additional
commands for controlling bulb-specific features. In addition, the bulbs
have their emeter under a different target and return responses that
include the energy unit in the key names.

* Add tests for bulbs

Not entirely comprehensive, but has pretty much the same level of testing
as plugs
2017-01-17 21:38:23 +08:00
GadgetReactor
04185706f8 Version bump 2017-01-11 16:20:04 +08:00
Teemu R
609b323a45 Initial steps to remove caching (#26)
This commit removes caching of sysinfo to avoid
inconsistent states as described in issue #14.

Each an every access for properties will cause a request
to be made to the device. To avoid this, user of the library
may want to access sys_info() directly instead of using the helpers.

Currently sys_info() returns raw json object where-as helpers do
parse information for easier consumption; current state is just to
provide a PoC how it looks compared to having an active update()
for fetching the info.
2017-01-11 16:17:48 +08:00
Teemu R
76cc597c2a Make tests runnable without device (#24)
* Make tests runnable without device

Adds preliminary support for fake devices, thanks to
hoveeman's sysinfos from issue #14,
making running tests possible without a device.

At the moment we have only HS110 and HS200 infos available, and tests
are currently run only against HS110 data.

* Make tests py27 compatible
2017-01-08 06:45:47 +08:00
Teemu R
71ac1f043a Add device discovery (#25)
* add (untested) discover mode

* Keep discovery and normal communication separate, uppercase magic consts

This sepearates the earlier test code for discovering devices,
and adds 5 sec timeout for gathering responses from potential devices.

This commit also uppercases magic constants.

Discovery & communication tested with HS110.

* update readme with example how to discover devices, pep8ify
2017-01-08 06:44:57 +08:00
Austin
1e01530447 Add timeout to query (#19) 2017-01-08 06:42:31 +08:00
Teemu R
fd4e363f56 Refactor & add unittests for almost all functionality, add tox for running tests on py27 and py35 (#17)
* Refactor & add unittests for almost all functionality, add tox for running tests on py27 and py35

This commit adds unit tests for current api functionality.
- currently no mocking, all tests are run on the device.
- the library is now compatible with python 2.7 and python 3.5, use tox for tests
- schema checks are done with voluptuous

refactoring:
- protocol is separated into its own file, smartplug adapted to receive protocol worker as parameter.
- cleaned up the initialization routine, initialization is done on use, not on creation of smartplug
- added model and features properties, identity kept for backwards compatibility
- no more storing of local variables outside _sys_info, paves a way to handle state changes sanely (without complete reinitialization)

* Fix CI warnings, remove unused leftover code

* Rename _initialize to _fetch_sysinfo, as that's what it does.

* examples.cli: fix identify call, prettyprint sysinfo, update readme which had false format for led setting

* Add tox-travis for automated testing.
2016-12-17 06:51:56 +08:00
Georgi Kirichkov
45fc354888 Version bump (#16) 2016-12-13 14:50:40 +08:00
Teemu R
05a6bbb145 Read all data from the device, disable double-encoding, implement more APIs, refactor querying, update README (#11)
* Read from socket until no data available, disable double string encoding

HS110 sends sometimes datagrams in chunks especially for get_daystat,
this patch makes it to read until there is no more data to be read.

As json.dumps() does JSON encoding already, there's no need to str()
the year or month either.

* Add cli.py, a simple script to query devices for debugging purposes.

* allow easier importing with from pyHS100 import SmartPlug

* move cli.py to examples, add short usage into README.md

* Implement more available APIs, refactor querying code.

This commit adds access to new properties, both read & write,  while keeping the old one (mostly) intact.
Querying is refactored to be done inside _query_helper() method,
which unwraps results automatically and rises SmartPlugException() in case of errors.
Errors are to be handled by clients.

New features:
* Setting device alias (plug.alias = "name")
* led read & write
* icon read (doesn't seem to return anything without cloud support at least), write API is not known, throws an exception currently
* time read (returns datetime), time write implemented, but not working even when no error is returned from the device
* timezone read
* mac read & write, writing is untested for now.

Properties for easier access:
* hw_info: return hw-specific elements from sysinfo
* on_since: pretty-printed from sysinfo
* location: latitude and longitued from sysinfo
* rssi: rssi from sysinfo

* Update README.md with examples of available features.

* Handle comments from mweinelt

* Refactor state handling, use booleans instead of strings

* Fix issues raised during the review.

Following issues are addressed by this commit:
* All API is more or less commented (including return types, exceptions, ..)
* Converted state to use
* Added properties is_on, is_off for those who don't want to check against strings.
* Handled most issues reported by pylint.
* Adjusted _query_helper() to strip off err_code from the result object.
* Fixed broken format() syntax for string formattings.

* Fix ci woes plus one typo.

* Do initialization after changing device properties, fix nits.
2016-12-12 17:13:45 +08:00
GadgetReactor
1ffdc7bc67 Merge pull request #15 from mweinelt/master
Constants will be static members of SmartPlug
2016-12-05 08:54:27 +08:00
Martin Weinelt
109caaf9f6 Constants will be static members of SmartPlug 2016-12-04 23:01:06 +01:00
GadgetReactor
60dee92838 Merge pull request #13 from mweinelt/master
set up hound-ci
2016-12-04 11:51:03 +08:00
Martin Weinelt
1a9da33c21 set up hound-ci 2016-12-04 03:54:29 +01:00
GadgetReactor
fadb76c5a0 Merge pull request #8 from mweinelt/master
Externalize the TP-Link Smart Home Protocol
2016-11-22 21:29:19 +08:00
Martin Weinelt
cb5899e3cc
Normalize docstrings, address flake8 & pylint recommendations
Signed-off-by: Martin Weinelt <hexa@darmstadt.ccc.de>
2016-11-22 02:32:11 +01:00
Martin Weinelt
33b2800fe8
Properly detect advertised features, expose alias
Signed-off-by: Martin Weinelt <hexa@darmstadt.ccc.de>
2016-11-22 00:39:51 +01:00
Martin Weinelt
08fb487a06
Externalize the TP-Link Smart Home Protocol
Signed-off-by: Martin Weinelt <hexa@darmstadt.ccc.de>
2016-11-21 23:18:12 +01:00
GadgetReactor
53c06ca784 HS200 support
Update version to reflect latest changes
2016-11-14 09:56:11 +08:00
GadgetReactor
9c39249b99 Merge pull request #5 from smaggard/add-hs200
Adding in support for the HS200 Wall switch referencing issues (#4)
2016-10-28 11:08:42 +08:00
Stephen Maggard
1550b6cb2e Adding in support for the HS200 Wall switch referencing issues (#4), simplifying model determination 2016-10-26 10:33:08 -05:00
Stephen Maggard
fe00041130 Adding in support for the HS200 Wall switch referencing issues (#4), simplifying model determination 2016-10-26 10:32:46 -05:00
Stephen Maggard
225bf47ace Adding in support for the HS200 Wall switch referencing issues (#4) 2016-10-26 09:56:26 -05:00
GadgetReactor
1f771b7d80 Merge pull request #2 from kirichkov/energy-monitoring
Adds energy monitoring functionality available in the HS110 plugs
2016-10-19 16:10:00 +08:00
Georgi Kirichkov
61714ac110 Refactors state property to use get_info() and removes hs100_status() 2016-10-19 11:02:32 +03:00
Georgi Kirichkov
dc3de3fa10 Adds model check to current_consumption() and removes whitespace 2016-10-19 10:28:48 +03:00
Georgi Kirichkov
605abfdebb Fixes indentation and removes extra whitespaces 2016-10-18 10:59:30 +03:00
GadgetReactor
d4be10ff26 Update setup.py 2016-10-18 09:41:13 +08:00
GadgetReactor
b074a21c9a Update LICENSE
Updated to GPLv3 (instead of just copy and pasting)
2016-10-18 09:40:42 +08:00
Georgi Kirichkov
3744a075c3 Bumps the module version to 0.2.0 2016-10-17 15:36:07 +03:00