Add precommit hooks & tox env to enforce code structure, add azure pipelines

Instead of leveraging hound & travis, add an option for azure pipelines,
which may replace the former in the future.

This also streamlines the contributing guidelines by:
* Adding pre-commit hooks to run isort, black, flake8, mypy
* Adding lint environment to allow checks to be run `tox -e lint`

This also contains a major cleanup to the SmartStrip handling which was due.
After seeing #184 I thought I should push this in as it is for comments before the codebase diverges too much.
This commit is contained in:
Teemu Rytilahti
2019-11-11 22:14:34 +01:00
parent 59424d2738
commit 8a131e1eeb
17 changed files with 354 additions and 549 deletions

View File

@@ -1,10 +1,11 @@
from pyHS100 import DeviceType, SmartDevice, SmartDeviceException
from .protocol import TPLinkSmartHomeProtocol
from deprecation import deprecated
"""Module for bulbs."""
import re
from datetime import datetime
from typing import Any, Dict, Tuple
from deprecation import deprecated
from .protocol import TPLinkSmartHomeProtocol
from .smartdevice import DeviceType, SmartDevice, SmartDeviceException
TPLINK_KELVIN = {
"LB130": (2500, 9000),
@@ -12,8 +13,8 @@ TPLINK_KELVIN = {
"LB230": (2500, 9000),
"KB130": (2500, 9000),
"KL130": (2500, 9000),
"KL120\(EU\)": (2700, 6500),
"KL120\(US\)": (2700, 5000),
r"KL120\(EU\)": (2700, 6500),
r"KL120\(US\)": (2700, 5000),
}
@@ -131,7 +132,6 @@ class SmartBulb(SmartDevice):
:return: hue, saturation and value (degrees, %, %)
:rtype: tuple
"""
if not self.is_color:
raise SmartDeviceException("Bulb does not support color.")
@@ -161,7 +161,9 @@ class SmartBulb(SmartDevice):
def set_hsv(self, hue: int, saturation: int, value: int):
"""Set new HSV.
:param tuple state: hue, saturation and value (degrees, %, %)
:param int hue: hue in degrees
:param int saturation: saturation in percentage [0,100]
:param int value: value in percentage [0, 100]
"""
if not self.is_color:
raise SmartDeviceException("Bulb does not support color.")
@@ -230,7 +232,7 @@ class SmartBulb(SmartDevice):
@property
def brightness(self) -> int:
"""Current brightness of the device.
"""Return the current brightness.
:return: brightness in percent
:rtype: int
@@ -250,7 +252,7 @@ class SmartBulb(SmartDevice):
self.set_brightness(brightness)
def set_brightness(self, brightness: int) -> None:
"""Set the current brightness of the device.
"""Set the brightness.
:param int brightness: brightness in percent
"""
@@ -303,10 +305,10 @@ class SmartBulb(SmartDevice):
:return: Bulb information dict, keys in user-presentable form.
:rtype: dict
"""
info = {
info: Dict[str, Any] = {
"Brightness": self.brightness,
"Is dimmable": self.is_dimmable,
} # type: Dict[str, Any]
}
if self.is_variable_color_temp:
info["Color temperature"] = self.color_temp
info["Valid temperature range"] = self.valid_temperature_range
@@ -331,4 +333,5 @@ class SmartBulb(SmartDevice):
@property
def has_emeter(self) -> bool:
"""Return that the bulb has an emeter."""
return True