|
57 | 57 | from kasa.smartcam import SmartCamDevice
|
58 | 58 |
|
59 | 59 | Call = namedtuple("Call", "module method")
|
60 |
| -FixtureResult = namedtuple("FixtureResult", "filename, folder, data") |
| 60 | +FixtureResult = namedtuple("FixtureResult", "filename, folder, data, protocol_suffix") |
61 | 61 |
|
62 | 62 | SMART_FOLDER = "tests/fixtures/smart/"
|
63 | 63 | SMARTCAM_FOLDER = "tests/fixtures/smartcam/"
|
64 | 64 | SMART_CHILD_FOLDER = "tests/fixtures/smart/child/"
|
65 | 65 | IOT_FOLDER = "tests/fixtures/iot/"
|
66 | 66 |
|
| 67 | +SMART_PROTOCOL_SUFFIX = "SMART" |
| 68 | +SMARTCAM_SUFFIX = "SMARTCAM" |
| 69 | +SMART_CHILD_SUFFIX = "SMART.CHILD" |
| 70 | +IOT_SUFFIX = "IOT" |
| 71 | + |
| 72 | +NO_GIT_FIXTURE_FOLDER = "kasa-fixtures" |
| 73 | + |
67 | 74 | ENCRYPT_TYPES = [encrypt_type.value for encrypt_type in DeviceEncryptionType]
|
68 | 75 |
|
69 | 76 | _LOGGER = logging.getLogger(__name__)
|
@@ -140,7 +147,17 @@ async def handle_device(
|
140 | 147 | ]
|
141 | 148 |
|
142 | 149 | for fixture_result in fixture_results:
|
143 |
| - save_filename = Path(basedir) / fixture_result.folder / fixture_result.filename |
| 150 | + save_folder = Path(basedir) / fixture_result.folder |
| 151 | + if save_folder.exists(): |
| 152 | + save_filename = save_folder / f"{fixture_result.filename}.json" |
| 153 | + else: |
| 154 | + # If being run without git clone |
| 155 | + save_folder = Path(basedir) / NO_GIT_FIXTURE_FOLDER |
| 156 | + save_folder.mkdir(exist_ok=True) |
| 157 | + save_filename = ( |
| 158 | + save_folder |
| 159 | + / f"{fixture_result.filename}-{fixture_result.protocol_suffix}.json" |
| 160 | + ) |
144 | 161 |
|
145 | 162 | pprint(fixture_result.data)
|
146 | 163 | if autosave:
|
@@ -459,9 +476,14 @@ async def get_legacy_fixture(
|
459 | 476 | hw_version = sysinfo["hw_ver"]
|
460 | 477 | sw_version = sysinfo["sw_ver"]
|
461 | 478 | sw_version = sw_version.split(" ", maxsplit=1)[0]
|
462 |
| - save_filename = f"{model}_{hw_version}_{sw_version}.json" |
| 479 | + save_filename = f"{model}_{hw_version}_{sw_version}" |
463 | 480 | copy_folder = IOT_FOLDER
|
464 |
| - return FixtureResult(filename=save_filename, folder=copy_folder, data=final) |
| 481 | + return FixtureResult( |
| 482 | + filename=save_filename, |
| 483 | + folder=copy_folder, |
| 484 | + data=final, |
| 485 | + protocol_suffix=IOT_SUFFIX, |
| 486 | + ) |
465 | 487 |
|
466 | 488 |
|
467 | 489 | def _echo_error(msg: str):
|
@@ -830,9 +852,12 @@ def get_smart_child_fixture(response):
|
830 | 852 | model = model_info.long_name
|
831 | 853 | if model_info.region is not None:
|
832 | 854 | model = f"{model}({model_info.region})"
|
833 |
| - save_filename = f"{model}_{hw_version}_{fw_version}.json" |
| 855 | + save_filename = f"{model}_{hw_version}_{fw_version}" |
834 | 856 | return FixtureResult(
|
835 |
| - filename=save_filename, folder=SMART_CHILD_FOLDER, data=response |
| 857 | + filename=save_filename, |
| 858 | + folder=SMART_CHILD_FOLDER, |
| 859 | + data=response, |
| 860 | + protocol_suffix=SMART_CHILD_SUFFIX, |
836 | 861 | )
|
837 | 862 |
|
838 | 863 |
|
@@ -980,20 +1005,28 @@ async def get_smart_fixtures(
|
980 | 1005 | # smart protocol
|
981 | 1006 | model_info = SmartDevice._get_device_info(final, discovery_result)
|
982 | 1007 | copy_folder = SMART_FOLDER
|
| 1008 | + protocol_suffix = SMART_PROTOCOL_SUFFIX |
983 | 1009 | else:
|
984 | 1010 | # smart camera protocol
|
985 | 1011 | model_info = SmartCamDevice._get_device_info(final, discovery_result)
|
986 | 1012 | copy_folder = SMARTCAM_FOLDER
|
| 1013 | + protocol_suffix = SMARTCAM_SUFFIX |
987 | 1014 | hw_version = model_info.hardware_version
|
988 | 1015 | sw_version = model_info.firmware_version
|
989 | 1016 | model = model_info.long_name
|
990 | 1017 | if model_info.region is not None:
|
991 | 1018 | model = f"{model}({model_info.region})"
|
992 | 1019 |
|
993 |
| - save_filename = f"{model}_{hw_version}_{sw_version}.json" |
| 1020 | + save_filename = f"{model}_{hw_version}_{sw_version}" |
994 | 1021 |
|
995 | 1022 | fixture_results.insert(
|
996 |
| - 0, FixtureResult(filename=save_filename, folder=copy_folder, data=final) |
| 1023 | + 0, |
| 1024 | + FixtureResult( |
| 1025 | + filename=save_filename, |
| 1026 | + folder=copy_folder, |
| 1027 | + data=final, |
| 1028 | + protocol_suffix=protocol_suffix, |
| 1029 | + ), |
997 | 1030 | )
|
998 | 1031 | return fixture_results
|
999 | 1032 |
|
|
0 commit comments