Refactor and drop py2 support (#49)

* move is_off property to SmartDevice, implement is_on for bulb and use it

* refactor by moving smartbulb and smartplug to their own classes

* drop python2 compatibility, make flake8 happy

* travis: remove 2.7, add 3.6
This commit is contained in:
Teemu R
2017-04-14 14:24:58 +02:00
committed by GitHub
parent c9662fcb7b
commit 86f14642c8
13 changed files with 497 additions and 497 deletions

View File

@@ -1,5 +1,5 @@
from pyHS100.protocol import TPLinkSmartHomeProtocol
from pyHS100 import SmartPlugException
from ..protocol import TPLinkSmartHomeProtocol
from .. import SmartPlugException
import logging

View File

@@ -1,22 +1,13 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from unittest import TestCase, skip, skipIf
from voluptuous import Schema, Invalid, All, Range
from functools import partial
from pyHS100 import SmartBulb, SmartPlugException
from pyHS100.tests.fakes import FakeTransportProtocol, sysinfo_lb130
from .. import SmartBulb, SmartPlugException
from .fakes import FakeTransportProtocol, sysinfo_lb130
BULB_IP = '192.168.250.186'
SKIP_STATE_TESTS = False
# python2 compatibility
try:
basestring
except NameError:
basestring = str
def check_int_bool(x):
if x != 0 and x != 1:
@@ -37,18 +28,18 @@ class TestSmartBulb(TestCase):
# as well as to check that faked devices are operating properly.
sysinfo_schema = Schema({
'active_mode': check_mode,
'alias': basestring,
'alias': str,
'ctrl_protocols': {
'name': basestring,
'version': basestring,
'name': str,
'version': str,
},
'description': basestring,
'dev_state': basestring,
'deviceId': basestring,
'disco_ver': basestring,
'description': str,
'dev_state': str,
'deviceId': str,
'disco_ver': str,
'heapsize': int,
'hwId': basestring,
'hw_ver': basestring,
'hwId': str,
'hw_ver': str,
'is_color': check_int_bool,
'is_dimmable': check_int_bool,
'is_factory': bool,
@@ -57,14 +48,14 @@ class TestSmartBulb(TestCase):
'brightness': All(int, Range(min=0, max=100)),
'color_temp': int,
'hue': All(int, Range(min=0, max=255)),
'mode': basestring,
'mode': str,
'on_off': check_int_bool,
'saturation': All(int, Range(min=0, max=255)),
},
'mic_mac': basestring,
'mic_type': basestring,
'model': basestring,
'oemId': basestring,
'mic_mac': str,
'mic_type': str,
'model': str,
'oemId': str,
'preferred_state': [{
'brightness': All(int, Range(min=0, max=100)),
'color_temp': int,
@@ -73,7 +64,7 @@ class TestSmartBulb(TestCase):
'saturation': All(int, Range(min=0, max=255)),
}],
'rssi': All(int, Range(max=0)),
'sw_ver': basestring,
'sw_ver': str,
})
current_consumption_schema = Schema({
@@ -81,10 +72,10 @@ class TestSmartBulb(TestCase):
})
tz_schema = Schema({
'zone_str': basestring,
'zone_str': str,
'dst_offset': int,
'index': All(int, Range(min=0)),
'tz_str': basestring,
'tz_str': str,
})
def setUp(self):
@@ -185,7 +176,7 @@ class TestSmartBulb(TestCase):
def test_alias(self):
test_alias = "TEST1234"
original = self.bulb.alias
self.assertTrue(isinstance(original, basestring))
self.assertTrue(isinstance(original, str))
self.bulb.alias = test_alias
self.assertEqual(self.bulb.alias, test_alias)
self.bulb.alias = original

View File

@@ -1,8 +1,5 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from unittest import TestCase
from pyHS100.protocol import TPLinkSmartHomeProtocol
from ..protocol import TPLinkSmartHomeProtocol
import json

View File

@@ -1,24 +1,15 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from unittest import TestCase, skip, skipIf
from voluptuous import Schema, Invalid, All, Range
from functools import partial
import datetime
import re
from pyHS100 import SmartPlug, SmartPlugException
from pyHS100.tests.fakes import FakeTransportProtocol, sysinfo_hs110
from .. import SmartPlug, SmartPlugException
from .fakes import FakeTransportProtocol, sysinfo_hs110
PLUG_IP = '192.168.250.186'
SKIP_STATE_TESTS = False
# python2 compatibility
try:
basestring
except NameError:
basestring = str
def check_int_bool(x):
if x != 0 and x != 1:
@@ -45,25 +36,25 @@ class TestSmartPlug(TestCase):
# as well as to check that faked devices are operating properly.
sysinfo_schema = Schema({
'active_mode': check_mode,
'alias': basestring,
'dev_name': basestring,
'deviceId': basestring,
'feature': basestring,
'fwId': basestring,
'hwId': basestring,
'hw_ver': basestring,
'icon_hash': basestring,
'alias': str,
'dev_name': str,
'deviceId': str,
'feature': str,
'fwId': str,
'hwId': str,
'hw_ver': str,
'icon_hash': str,
'latitude': All(float, Range(min=-90, max=90)),
'led_off': check_int_bool,
'longitude': All(float, Range(min=-180, max=180)),
'mac': check_mac,
'model': basestring,
'oemId': basestring,
'model': str,
'oemId': str,
'on_time': int,
'relay_state': int,
'rssi': All(int, Range(max=0)),
'sw_ver': basestring,
'type': basestring,
'sw_ver': str,
'type': str,
'updating': check_int_bool,
})
@@ -75,10 +66,10 @@ class TestSmartPlug(TestCase):
})
tz_schema = Schema({
'zone_str': basestring,
'zone_str': str,
'dst_offset': int,
'index': All(int, Range(min=0)),
'tz_str': basestring,
'tz_str': str,
})
def setUp(self):
@@ -195,7 +186,7 @@ class TestSmartPlug(TestCase):
def test_alias(self):
test_alias = "TEST1234"
original = self.plug.alias
self.assertTrue(isinstance(original, basestring))
self.assertTrue(isinstance(original, str))
self.plug.alias = test_alias
self.assertEqual(self.plug.alias, test_alias)
self.plug.alias = original