Fix dump-discover to use asyncio.run (#16)

This commit is contained in:
Teemu R 2020-01-13 08:52:52 +01:00 committed by Bas Nijholt
parent 0f0df481a0
commit 822ab3f8ac

View File

@ -1,5 +1,6 @@
"""python-kasa cli tool.""" """python-kasa cli tool."""
import asyncio import asyncio
import json
import logging import logging
from pprint import pformat as pf from pprint import pformat as pf
@ -88,14 +89,13 @@ def dump_discover(ctx, save):
Useful for dumping into a file with `--save` to be added to the test suite. Useful for dumping into a file with `--save` to be added to the test suite.
""" """
target = ctx.parent.params["target"] target = ctx.parent.params["target"]
for dev in Discover.discover(target=target, return_raw=True).values(): devs = asyncio.run(Discover.discover(target=target, return_raw=True))
for dev in devs.values():
model = dev["system"]["get_sysinfo"]["model"] model = dev["system"]["get_sysinfo"]["model"]
hw_version = dev["system"]["get_sysinfo"]["hw_ver"] hw_version = dev["system"]["get_sysinfo"]["hw_ver"]
save_to = f"{model}_{hw_version}.json" save_to = f"{model}_{hw_version}.json"
click.echo("Saving info to %s" % save_to) click.echo("Saving info to %s" % save_to)
with open(save_to, "w") as f: with open(save_to, "w") as f:
import json
json.dump(dev, f, sort_keys=True, indent=4) json.dump(dev, f, sort_keys=True, indent=4)