mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
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:
parent
80f097b5b3
commit
3337c574ce
31
kasa/cli.py
31
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()
|
||||
|
Loading…
Reference in New Issue
Block a user