Commit Graph

6 Commits

Author SHA1 Message Date
Teemu Rytilahti
9d3fbfa975 Ignore OSError on socket.shutdown()
This fixes #22 and obsoletes PR #23.
2017-03-19 15:56:38 +01:00
Teemu R
1bada16636 discover: Catch socket.timeout and debug log it (#34)
Fixes #33
2017-03-17 14:32:50 +01: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
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