FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Enable saving of fixture files without git clone by sdb9696 · Pull Request #1375 · python-kasa/python-kasa · GitHub

Repository navigation

49 changes: 41 additions & 8 deletions devtools/dump_devinfo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,20 @@
from kasa.smartcam import SmartCamDevice

Call = namedtuple("Call", "module method")
FixtureResult = namedtuple("FixtureResult", "filename, folder, data")
FixtureResult = namedtuple("FixtureResult", "filename, folder, data, protocol_suffix")

SMART_FOLDER = "tests/fixtures/smart/"
SMARTCAM_FOLDER = "tests/fixtures/smartcam/"
SMART_CHILD_FOLDER = "tests/fixtures/smart/child/"
IOT_FOLDER = "tests/fixtures/iot/"

SMART_PROTOCOL_SUFFIX = "SMART"
SMARTCAM_SUFFIX = "SMARTCAM"
SMART_CHILD_SUFFIX = "SMART.CHILD"
IOT_SUFFIX = "IOT"

NO_GIT_FIXTURE_FOLDER = "kasa-fixtures"

ENCRYPT_TYPES = [encrypt_type.value for encrypt_type in DeviceEncryptionType]

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -140,7 +147,17 @@ async def handle_device(
]

for fixture_result in fixture_results:
save_filename = Path(basedir) / fixture_result.folder / fixture_result.filename
save_folder = Path(basedir) / fixture_result.folder
if save_folder.exists():
save_filename = save_folder / f"{fixture_result.filename}.json"
else:
# If being run without git clone
save_folder = Path(basedir) / NO_GIT_FIXTURE_FOLDER
Comment thread
rytilahti marked this conversation as resolved.
save_folder.mkdir(exist_ok=True)
save_filename = (
save_folder
/ f"{fixture_result.filename}-{fixture_result.protocol_suffix}.json"
)

pprint(fixture_result.data)
if autosave:
Expand Down Expand Up @@ -459,9 +476,14 @@ async def get_legacy_fixture(
hw_version = sysinfo["hw_ver"]
sw_version = sysinfo["sw_ver"]
sw_version = sw_version.split(" ", maxsplit=1)[0]
save_filename = f"{model}_{hw_version}_{sw_version}.json"
save_filename = f"{model}_{hw_version}_{sw_version}"
copy_folder = IOT_FOLDER
return FixtureResult(filename=save_filename, folder=copy_folder, data=final)
return FixtureResult(
filename=save_filename,
folder=copy_folder,
data=final,
protocol_suffix=IOT_SUFFIX,
)


def _echo_error(msg: str):
Expand Down Expand Up @@ -830,9 +852,12 @@ def get_smart_child_fixture(response):
model = model_info.long_name
if model_info.region is not None:
model = f"{model}({model_info.region})"
save_filename = f"{model}_{hw_version}_{fw_version}.json"
save_filename = f"{model}_{hw_version}_{fw_version}"
return FixtureResult(
filename=save_filename, folder=SMART_CHILD_FOLDER, data=response
filename=save_filename,
folder=SMART_CHILD_FOLDER,
data=response,
protocol_suffix=SMART_CHILD_SUFFIX,
)


Expand Down Expand Up @@ -980,20 +1005,28 @@ async def get_smart_fixtures(
# smart protocol
model_info = SmartDevice._get_device_info(final, discovery_result)
copy_folder = SMART_FOLDER
protocol_suffix = SMART_PROTOCOL_SUFFIX
else:
# smart camera protocol
model_info = SmartCamDevice._get_device_info(final, discovery_result)
copy_folder = SMARTCAM_FOLDER
protocol_suffix = SMARTCAM_SUFFIX
hw_version = model_info.hardware_version
sw_version = model_info.firmware_version
model = model_info.long_name
if model_info.region is not None:
model = f"{model}({model_info.region})"

save_filename = f"{model}_{hw_version}_{sw_version}.json"
save_filename = f"{model}_{hw_version}_{sw_version}"

fixture_results.insert(
0, FixtureResult(filename=save_filename, folder=copy_folder, data=final)
0,
FixtureResult(
filename=save_filename,
folder=copy_folder,
data=final,
protocol_suffix=protocol_suffix,
),
)
return fixture_results

Expand Down

Back | FazBrowse Home | New Git URL