mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-19 19:20:22 +00:00
add typing hints to make it easier for 3rd party developers to use the library (#90)
* add typing hints to make it easier for 3rd party developers to use the library * remove unused devicetype enum to support python3.3 * add python 3.3 to travis and tox, install typing module in setup.py
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import datetime
|
||||
import logging
|
||||
from typing import Any, Dict
|
||||
|
||||
from pyHS100 import SmartDevice
|
||||
|
||||
@@ -30,13 +31,15 @@ class SmartPlug(SmartDevice):
|
||||
SWITCH_STATE_OFF = 'OFF'
|
||||
SWITCH_STATE_UNKNOWN = 'UNKNOWN'
|
||||
|
||||
def __init__(self, ip_address, protocol=None):
|
||||
def __init__(self,
|
||||
ip_address: str,
|
||||
protocol: 'TPLinkSmartHomeProtocol' = None) -> None:
|
||||
SmartDevice.__init__(self, ip_address, protocol)
|
||||
self.emeter_type = "emeter"
|
||||
self.emeter_units = False
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def state(self) -> str:
|
||||
"""
|
||||
Retrieve the switch state
|
||||
|
||||
@@ -57,7 +60,7 @@ class SmartPlug(SmartDevice):
|
||||
return SmartPlug.SWITCH_STATE_UNKNOWN
|
||||
|
||||
@state.setter
|
||||
def state(self, value):
|
||||
def state(self, value: str):
|
||||
"""
|
||||
Set the new switch state
|
||||
|
||||
@@ -78,7 +81,7 @@ class SmartPlug(SmartDevice):
|
||||
raise ValueError("State %s is not valid.", value)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""
|
||||
Returns whether device is on.
|
||||
|
||||
@@ -103,7 +106,7 @@ class SmartPlug(SmartDevice):
|
||||
self._query_helper("system", "set_relay_state", {"state": 0})
|
||||
|
||||
@property
|
||||
def led(self):
|
||||
def led(self) -> bool:
|
||||
"""
|
||||
Returns the state of the led.
|
||||
|
||||
@@ -112,15 +115,8 @@ class SmartPlug(SmartDevice):
|
||||
"""
|
||||
return bool(1 - self.sys_info["led_off"])
|
||||
|
||||
@property
|
||||
def state_information(self):
|
||||
return {
|
||||
'LED state': self.led,
|
||||
'On since': self.on_since
|
||||
}
|
||||
|
||||
@led.setter
|
||||
def led(self, state):
|
||||
def led(self, state: bool):
|
||||
"""
|
||||
Sets the state of the led (night mode)
|
||||
|
||||
@@ -130,7 +126,7 @@ class SmartPlug(SmartDevice):
|
||||
self._query_helper("system", "set_led_off", {"off": int(not state)})
|
||||
|
||||
@property
|
||||
def on_since(self):
|
||||
def on_since(self) -> datetime.datetime:
|
||||
"""
|
||||
Returns pretty-printed on-time
|
||||
|
||||
@@ -139,3 +135,10 @@ class SmartPlug(SmartDevice):
|
||||
"""
|
||||
return datetime.datetime.now() - \
|
||||
datetime.timedelta(seconds=self.sys_info["on_time"])
|
||||
|
||||
@property
|
||||
def state_information(self) -> Dict[str, Any]:
|
||||
return {
|
||||
'LED state': self.led,
|
||||
'On since': self.on_since
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user