python-kasa/examples/cli.py
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

25 lines
632 B
Python

import sys
import logging
from pprint import pformat as pf
from pyHS100 import SmartPlug
logging.basicConfig(level=logging.DEBUG)
if len(sys.argv) < 2:
print("%s <ip>" % sys.argv[0])
sys.exit(1)
hs = SmartPlug(sys.argv[1])
logging.info("Identify: %s", hs.identify())
logging.info("Sysinfo: %s", pf(hs.get_sysinfo()))
has_emeter = hs.has_emeter
if has_emeter:
logging.info("== Emeter ==")
logging.info("- Current: %s", hs.get_emeter_realtime())
logging.info("== Monthly ==")
logging.info(hs.get_emeter_monthly())
logging.info("== Daily ==")
logging.info(hs.get_emeter_daily(month=11, year=2016))