From 5e2fcd2cca192d451109d5448a5b27324c0b431e Mon Sep 17 00:00:00 2001 From: sdb9696 <51370195+sdb9696@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:45:09 +0000 Subject: [PATCH] Re-add regional suffix to TAPO/SMART fixtures (#566) --- devtools/dump_devinfo.py | 41 +++++++++++-------- ...1.0_1.3.0.json => P110(UK)_1.0_1.3.0.json} | 0 2 files changed, 25 insertions(+), 16 deletions(-) rename kasa/tests/fixtures/smart/{P110_1.0_1.3.0.json => P110(UK)_1.0_1.3.0.json} (100%) diff --git a/devtools/dump_devinfo.py b/devtools/dump_devinfo.py index 777ee105..30f4ba1f 100644 --- a/devtools/dump_devinfo.py +++ b/devtools/dump_devinfo.py @@ -101,18 +101,25 @@ async def cli(host, debug, username, password): device = await Discover.discover_single(host, credentials=credentials) if isinstance(device, TapoDevice): - save_to, final = await get_smart_fixture(device) + save_filename, copy_folder, final = await get_smart_fixture(device) else: - save_to, final = await get_legacy_fixture(device) + save_filename, copy_folder, final = await get_legacy_fixture(device) pprint(scrub(final)) - save = click.prompt(f"Do you want to save the above content to {save_to} (y/n)") + save = click.prompt( + f"Do you want to save the above content to {save_filename} (y/n)" + ) if save == "y": - click.echo(f"Saving info to {save_to}") + click.echo(f"Saving info to {save_filename}") - with open(save_to, "w") as f: + with open(save_filename, "w") as f: json.dump(final, f, sort_keys=True, indent=4) f.write("\n") + + click.echo( + f"Saved. Copy/Move {save_filename} to " + + f"{copy_folder} to add it to the test suite" + ) else: click.echo("Not saving.") @@ -182,8 +189,9 @@ async def get_legacy_fixture(device): hw_version = sysinfo["hw_ver"] sw_version = sysinfo["sw_ver"] sw_version = sw_version.split(" ", maxsplit=1)[0] - save_to = f"{model}_{hw_version}_{sw_version}.json" - return save_to, final + save_filename = f"{model}_{hw_version}_{sw_version}.json" + copy_folder = "kasa/tests/fixtures/" + return save_filename, copy_folder, final async def get_smart_fixture(device: SmartDevice): @@ -234,23 +242,24 @@ async def get_smart_fixture(device: SmartDevice): for response in responses["responses"]: final[response["method"]] = response["result"] - if device._discovery_info: - # Need to recreate a DiscoverResult here because we don't want the aliases - # in the fixture, we want the actual field names as returned by the device. - dr = DiscoveryResult(**device._discovery_info) - final["discovery_result"] = dr.dict( - by_alias=False, exclude_unset=True, exclude_none=True, exclude_defaults=True - ) + # Need to recreate a DiscoverResult here because we don't want the aliases + # in the fixture, we want the actual field names as returned by the device. + dr = DiscoveryResult(**device._discovery_info) # type: ignore + final["discovery_result"] = dr.dict( + by_alias=False, exclude_unset=True, exclude_none=True, exclude_defaults=True + ) click.echo("Got %s successes" % len(successes)) click.echo(click.style("## device info file ##", bold=True)) hw_version = final["get_device_info"]["hw_ver"] sw_version = final["get_device_info"]["fw_ver"] - model = final["get_device_info"]["model"] + model = final["discovery_result"]["device_model"] sw_version = sw_version.split(" ", maxsplit=1)[0] - return f"{model}.smart_{hw_version}_{sw_version}.json", final + save_filename = f"{model}_{hw_version}_{sw_version}.json" + copy_folder = "kasa/tests/fixtures/smart/" + return save_filename, copy_folder, final if __name__ == "__main__": diff --git a/kasa/tests/fixtures/smart/P110_1.0_1.3.0.json b/kasa/tests/fixtures/smart/P110(UK)_1.0_1.3.0.json similarity index 100% rename from kasa/tests/fixtures/smart/P110_1.0_1.3.0.json rename to kasa/tests/fixtures/smart/P110(UK)_1.0_1.3.0.json