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
This commit is contained in:
Teemu R
2017-08-05 15:49:56 +02:00
committed by GitHub
parent d7aade4e61
commit 07af48e41a
8 changed files with 154 additions and 92 deletions

View File

@@ -1,7 +1,7 @@
import datetime
import logging
from .pyHS100 import SmartDevice
from pyHS100 import SmartDevice
_LOGGER = logging.getLogger(__name__)
@@ -19,7 +19,7 @@ class SmartPlug(SmartDevice):
# query and print current state of plug
print(p.state)
Errors reported by the device are raised as SmartPlugExceptions,
Errors reported by the device are raised as SmartDeviceExceptions,
and should be handled by the user of the library.
Note:
@@ -65,7 +65,7 @@ class SmartPlug(SmartDevice):
SWITCH_STATE_ON
SWITCH_STATE_OFF
:raises ValueError: on invalid state
:raises SmartPlugException: on error
:raises SmartDeviceException: on error
"""
if not isinstance(value, str):
@@ -90,7 +90,7 @@ class SmartPlug(SmartDevice):
"""
Turn the switch on.
:raises SmartPlugException: on error
:raises SmartDeviceException: on error
"""
self._query_helper("system", "set_relay_state", {"state": 1})
@@ -98,7 +98,7 @@ class SmartPlug(SmartDevice):
"""
Turn the switch off.
:raises SmartPlugException: on error
:raises SmartDeviceException: on error
"""
self._query_helper("system", "set_relay_state", {"state": 0})
@@ -125,7 +125,7 @@ class SmartPlug(SmartDevice):
Sets the state of the led (night mode)
:param bool state: True to set led on, False to set led off
:raises SmartPlugException: on error
:raises SmartDeviceException: on error
"""
self._query_helper("system", "set_led_off", {"off": int(not state)})