From 3337c574ce231a101640498c8d841ed7997b76bb Mon Sep 17 00:00:00 2001 From: Angelo Gagliano <25516409+TheGardenMonkey@users.noreply.github.com> Date: Wed, 15 Jan 2020 08:46:35 -0500 Subject: [PATCH] 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 --- kasa/cli.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/kasa/cli.py b/kasa/cli.py index 210e2fff..0aeedb26 100755 --- a/kasa/cli.py +++ b/kasa/cli.py @@ -2,6 +2,7 @@ import asyncio import json import logging +import re from pprint import pformat as pf import click @@ -81,22 +82,46 @@ def cli(ctx, host, alias, target, debug, bulb, plug, strip): @cli.command() -@click.option("--save") +@click.option("--scrub/--no-scrub", default=True) @click.pass_context -def dump_discover(ctx, save): +def dump_discover(ctx, scrub): """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"] + keys_to_scrub = [ + "deviceId", + "fwId", + "hwId", + "oemId", + "mac", + "latitude_i", + "longitude_i", + "latitude", + "longitude", + ] devs = asyncio.run(Discover.discover(target=target, return_raw=True)) + if scrub: + click.echo("Scrubbing personal data before writing") 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"] hw_version = dev["system"]["get_sysinfo"]["hw_ver"] save_to = f"{model}_{hw_version}.json" click.echo("Saving info to %s" % save_to) with open(save_to, "w") as f: json.dump(dev, f, sort_keys=True, indent=4) + f.write("\n") @cli.command()