Remove unused save option and add scrubbing (#19)

* Removes unused save option and adds scrubbing

* Defaults to scrub and adds no-scrub option

* Adds latitude and longitude to the scrub list
This commit is contained in:
Angelo Gagliano 2020-01-15 08:46:35 -05:00 committed by Teemu R
parent 80f097b5b3
commit 3337c574ce

View File

@ -2,6 +2,7 @@
import asyncio import asyncio
import json import json
import logging import logging
import re
from pprint import pformat as pf from pprint import pformat as pf
import click import click
@ -81,22 +82,46 @@ def cli(ctx, host, alias, target, debug, bulb, plug, strip):
@cli.command() @cli.command()
@click.option("--save") @click.option("--scrub/--no-scrub", default=True)
@click.pass_context @click.pass_context
def dump_discover(ctx, save): def dump_discover(ctx, scrub):
"""Dump discovery information. """Dump discovery information.
Useful for dumping into a file with `--save` to be added to the test suite. Useful for dumping into a file to be added to the test suite.
""" """
target = ctx.parent.params["target"] target = ctx.parent.params["target"]
keys_to_scrub = [
"deviceId",
"fwId",
"hwId",
"oemId",
"mac",
"latitude_i",
"longitude_i",
"latitude",
"longitude",
]
devs = asyncio.run(Discover.discover(target=target, return_raw=True)) devs = asyncio.run(Discover.discover(target=target, return_raw=True))
if scrub:
click.echo("Scrubbing personal data before writing")
for dev in devs.values(): for dev in devs.values():
if scrub:
for key in keys_to_scrub:
if key in dev["system"]["get_sysinfo"]:
val = dev["system"]["get_sysinfo"][key]
if key in ["latitude_i", "longitude_i"]:
val = 0
else:
val = re.sub("\w", "0", val)
dev["system"]["get_sysinfo"][key] = val
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:
json.dump(dev, f, sort_keys=True, indent=4) json.dump(dev, f, sort_keys=True, indent=4)
f.write("\n")
@cli.command() @cli.command()