mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-24 05:37:59 +00:00
test the newly added device fixtures (#21)
* make fixture detection saner * allow scrubbed locations
This commit is contained in:
parent
4a4b9c655a
commit
7eea21f2dd
@ -16,8 +16,8 @@ SUPPORTED_DEVICES = glob.glob(
|
|||||||
|
|
||||||
BULBS = {"LB100", "LB120", "LB130", "KL120"}
|
BULBS = {"LB100", "LB120", "LB130", "KL120"}
|
||||||
VARIABLE_TEMP = {"LB120", "LB130", "KL120"}
|
VARIABLE_TEMP = {"LB120", "LB130", "KL120"}
|
||||||
PLUGS = {"HS100", "HS105", "HS110", "HS200", "HS220", "HS300"}
|
PLUGS = {"HS100", "HS105", "HS110", "HS200", "HS210", "HS220", "HS300"}
|
||||||
STRIPS = {"HS300"}
|
STRIPS = {"HS107", "HS300"}
|
||||||
COLOR_BULBS = {"LB130"}
|
COLOR_BULBS = {"LB130"}
|
||||||
DIMMABLE = {*BULBS, "HS220"}
|
DIMMABLE = {*BULBS, "HS220"}
|
||||||
EMETER = {"HS110", "HS300", *BULBS}
|
EMETER = {"HS110", "HS300", *BULBS}
|
||||||
@ -25,14 +25,15 @@ EMETER = {"HS110", "HS300", *BULBS}
|
|||||||
ALL_DEVICES = BULBS.union(PLUGS)
|
ALL_DEVICES = BULBS.union(PLUGS)
|
||||||
|
|
||||||
|
|
||||||
def filter_model(filter):
|
def filter_model(desc, filter):
|
||||||
print(filter)
|
|
||||||
filtered = list()
|
filtered = list()
|
||||||
for dev in SUPPORTED_DEVICES:
|
for dev in SUPPORTED_DEVICES:
|
||||||
for filt in filter:
|
for filt in filter:
|
||||||
if filt in basename(dev):
|
if filt in basename(dev):
|
||||||
filtered.append(dev)
|
filtered.append(dev)
|
||||||
|
|
||||||
|
filtered_basenames = [basename(f) for f in filtered]
|
||||||
|
print(f"{desc}: {filtered_basenames}")
|
||||||
return filtered
|
return filtered
|
||||||
|
|
||||||
|
|
||||||
@ -42,30 +43,36 @@ def get_ioloop():
|
|||||||
return ioloop
|
return ioloop
|
||||||
|
|
||||||
|
|
||||||
has_emeter = pytest.mark.parametrize("dev", filter_model(EMETER), indirect=True)
|
has_emeter = pytest.mark.parametrize(
|
||||||
|
"dev", filter_model("has emeter", EMETER), indirect=True
|
||||||
|
)
|
||||||
no_emeter = pytest.mark.parametrize(
|
no_emeter = pytest.mark.parametrize(
|
||||||
"dev", filter_model(ALL_DEVICES - EMETER), indirect=True
|
"dev", filter_model("no emeter", ALL_DEVICES - EMETER), indirect=True
|
||||||
)
|
)
|
||||||
|
|
||||||
bulb = pytest.mark.parametrize("dev", filter_model(BULBS), indirect=True)
|
bulb = pytest.mark.parametrize("dev", filter_model("bulbs", BULBS), indirect=True)
|
||||||
plug = pytest.mark.parametrize("dev", filter_model(PLUGS), indirect=True)
|
plug = pytest.mark.parametrize("dev", filter_model("plugs", PLUGS), indirect=True)
|
||||||
strip = pytest.mark.parametrize("dev", filter_model(STRIPS), indirect=True)
|
strip = pytest.mark.parametrize("dev", filter_model("strips", STRIPS), indirect=True)
|
||||||
|
|
||||||
dimmable = pytest.mark.parametrize("dev", filter_model(DIMMABLE), indirect=True)
|
dimmable = pytest.mark.parametrize(
|
||||||
|
"dev", filter_model("dimmable", DIMMABLE), indirect=True
|
||||||
|
)
|
||||||
non_dimmable = pytest.mark.parametrize(
|
non_dimmable = pytest.mark.parametrize(
|
||||||
"dev", filter_model(ALL_DEVICES - DIMMABLE), indirect=True
|
"dev", filter_model("non-dimmable", ALL_DEVICES - DIMMABLE), indirect=True
|
||||||
)
|
)
|
||||||
|
|
||||||
variable_temp = pytest.mark.parametrize(
|
variable_temp = pytest.mark.parametrize(
|
||||||
"dev", filter_model(VARIABLE_TEMP), indirect=True
|
"dev", filter_model("variable color temp", VARIABLE_TEMP), indirect=True
|
||||||
)
|
)
|
||||||
non_variable_temp = pytest.mark.parametrize(
|
non_variable_temp = pytest.mark.parametrize(
|
||||||
"dev", filter_model(BULBS - VARIABLE_TEMP), indirect=True
|
"dev", filter_model("non-variable color temp", BULBS - VARIABLE_TEMP), indirect=True
|
||||||
)
|
)
|
||||||
|
|
||||||
color_bulb = pytest.mark.parametrize("dev", filter_model(COLOR_BULBS), indirect=True)
|
color_bulb = pytest.mark.parametrize(
|
||||||
|
"dev", filter_model("color bulbs", COLOR_BULBS), indirect=True
|
||||||
|
)
|
||||||
non_color_bulb = pytest.mark.parametrize(
|
non_color_bulb = pytest.mark.parametrize(
|
||||||
"dev", filter_model(BULBS - COLOR_BULBS), indirect=True
|
"dev", filter_model("non-color bulbs", BULBS - COLOR_BULBS), indirect=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -99,6 +106,19 @@ def dev(request):
|
|||||||
return d
|
return d
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def device_for_file(model):
|
||||||
|
for d in STRIPS:
|
||||||
|
if d in model:
|
||||||
|
return SmartStrip
|
||||||
|
for d in PLUGS:
|
||||||
|
if d in model:
|
||||||
|
return SmartPlug
|
||||||
|
for d in BULBS:
|
||||||
|
if d in model:
|
||||||
|
return SmartBulb
|
||||||
|
|
||||||
|
raise Exception("Unable to find type for %s", model)
|
||||||
|
|
||||||
with open(file) as f:
|
with open(file) as f:
|
||||||
sysinfo = json.load(f)
|
sysinfo = json.load(f)
|
||||||
model = basename(file)
|
model = basename(file)
|
||||||
@ -107,14 +127,7 @@ def dev(request):
|
|||||||
"protocol": FakeTransportProtocol(sysinfo),
|
"protocol": FakeTransportProtocol(sysinfo),
|
||||||
"cache_ttl": 0,
|
"cache_ttl": 0,
|
||||||
}
|
}
|
||||||
if "LB" in model or "KL" in model:
|
p = device_for_file(model)(**params, ioloop=ioloop)
|
||||||
p = SmartBulb(**params, ioloop=ioloop)
|
|
||||||
elif "HS300" in model:
|
|
||||||
p = SmartStrip(**params, ioloop=ioloop)
|
|
||||||
elif "HS" in model:
|
|
||||||
p = SmartPlug(**params, ioloop=ioloop)
|
|
||||||
else:
|
|
||||||
raise Exception("No tests for %s" % model)
|
|
||||||
ioloop.run_until_complete(p.update())
|
ioloop.run_until_complete(p.update())
|
||||||
yield p
|
yield p
|
||||||
|
|
||||||
|
@ -73,10 +73,10 @@ PLUG_SCHEMA = Schema(
|
|||||||
"hw_ver": str,
|
"hw_ver": str,
|
||||||
"icon_hash": str,
|
"icon_hash": str,
|
||||||
"led_off": check_int_bool,
|
"led_off": check_int_bool,
|
||||||
"latitude": Any(All(float, Range(min=-90, max=90)), None),
|
"latitude": Any(All(float, Range(min=-90, max=90)), 0, None),
|
||||||
"latitude_i": Any(All(float, Range(min=-90, max=90)), None),
|
"latitude_i": Any(All(float, Range(min=-90, max=90)), 0, None),
|
||||||
"longitude": Any(All(float, Range(min=-180, max=180)), None),
|
"longitude": Any(All(float, Range(min=-180, max=180)), 0, None),
|
||||||
"longitude_i": Any(All(float, Range(min=-180, max=180)), None),
|
"longitude_i": Any(All(float, Range(min=-180, max=180)), 0, None),
|
||||||
"mac": check_mac,
|
"mac": check_mac,
|
||||||
"model": str,
|
"model": str,
|
||||||
"oemId": str,
|
"oemId": str,
|
||||||
|
@ -116,7 +116,7 @@ async def test_no_emeter(dev):
|
|||||||
@has_emeter
|
@has_emeter
|
||||||
async def test_get_emeter_realtime(dev):
|
async def test_get_emeter_realtime(dev):
|
||||||
if dev.is_strip:
|
if dev.is_strip:
|
||||||
pytest.skip("Disabled for HS300 temporarily")
|
pytest.skip("Disabled for strips temporarily")
|
||||||
|
|
||||||
assert dev.has_emeter
|
assert dev.has_emeter
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ async def test_get_emeter_realtime(dev):
|
|||||||
@has_emeter
|
@has_emeter
|
||||||
async def test_get_emeter_daily(dev):
|
async def test_get_emeter_daily(dev):
|
||||||
if dev.is_strip:
|
if dev.is_strip:
|
||||||
pytest.skip("Disabled for HS300 temporarily")
|
pytest.skip("Disabled for strips temporarily")
|
||||||
|
|
||||||
assert dev.has_emeter
|
assert dev.has_emeter
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ async def test_get_emeter_daily(dev):
|
|||||||
@has_emeter
|
@has_emeter
|
||||||
async def test_get_emeter_monthly(dev):
|
async def test_get_emeter_monthly(dev):
|
||||||
if dev.is_strip:
|
if dev.is_strip:
|
||||||
pytest.skip("Disabled for HS300 temporarily")
|
pytest.skip("Disabled for strips temporarily")
|
||||||
|
|
||||||
assert dev.has_emeter
|
assert dev.has_emeter
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ async def test_get_emeter_monthly(dev):
|
|||||||
@has_emeter
|
@has_emeter
|
||||||
async def test_emeter_status(dev):
|
async def test_emeter_status(dev):
|
||||||
if dev.is_strip:
|
if dev.is_strip:
|
||||||
pytest.skip("Disabled for HS300 temporarily")
|
pytest.skip("Disabled for strips temporarily")
|
||||||
|
|
||||||
assert dev.has_emeter
|
assert dev.has_emeter
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ async def test_erase_emeter_stats(dev):
|
|||||||
@has_emeter
|
@has_emeter
|
||||||
async def test_current_consumption(dev):
|
async def test_current_consumption(dev):
|
||||||
if dev.is_strip:
|
if dev.is_strip:
|
||||||
pytest.skip("Disabled for HS300 temporarily")
|
pytest.skip("Disabled for strips temporarily")
|
||||||
|
|
||||||
if dev.has_emeter:
|
if dev.has_emeter:
|
||||||
x = await dev.current_consumption()
|
x = await dev.current_consumption()
|
||||||
|
Loading…
Reference in New Issue
Block a user