Skip to content

Commit dd47956

Browse files
committed
feat: add fetching metadata to pyodide bridge
1 parent bdb0f98 commit dd47956

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/vpe_pyodide_bridge.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@
2727
)
2828

2929

30+
def get_firmware_metadata(fw_path: str) -> dict:
31+
"""Firmware-level metadata for display in the UI (not per-segment) -
32+
version string, segment count, checksum validity, total image size, and
33+
the AudioLibraryHeader's raw fw_version field."""
34+
fw = ISD9160Firmware.from_filepath(fw_path)
35+
return {
36+
"version": fw.version,
37+
"segmentCount": fw.segment_count,
38+
"checksumValid": fw.is_checksum_valid(),
39+
"sizeBytes": len(fw.data),
40+
"fwVersionRaw": fw.audiolib_header.fw_version,
41+
}
42+
43+
3044
def extract_segments(fw_path: str, output_dir: str) -> list[dict]:
3145
"""Extract every segment in the firmware at fw_path to WAV+raw files
3246
under output_dir (via ISD9160Firmware.extract_all). Returns per-segment
@@ -80,10 +94,10 @@ def patch_firmware(fw_path: str, segment_paths: dict[int, str], version_str: str
8094
NOTE: writes output_path itself rather than returning ISD9160Firmware.data
8195
directly, and deliberately does not return the ISD9160Firmware object
8296
patch_with_new_segments() produces - its `.version`/`.seg_entries` stay
83-
stale after patching (see external/DuRFUnitI2C/tests/test_vpe.py's
84-
documented gotcha), only `.data` is trustworthy. Read output_path back
85-
via a fresh ISD9160Firmware.from_filepath() call if you need to inspect
86-
the result afterwards.
97+
stale after patching (see this project's tests/test_vpe.py's documented
98+
gotcha), only `.data` is trustworthy. Read output_path back via a fresh
99+
ISD9160Firmware.from_filepath() call if you need to inspect the result
100+
afterwards (get_firmware_metadata() above does exactly that).
87101
"""
88102
fw = ISD9160Firmware.from_filepath(fw_path)
89103
new_segments = fw.get_all_segments()

tests/test_vpe_pyodide_bridge.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ def fw_path(tmp_path):
2424
return str(path)
2525

2626

27+
def test_get_firmware_metadata_reports_version_segments_and_checksum(fw_path):
28+
result = bridge.get_firmware_metadata(fw_path)
29+
30+
assert result["version"] == VERSION_STR
31+
assert result["segmentCount"] == 1
32+
assert result["checksumValid"] is True
33+
assert result["sizeBytes"] == 0x24400
34+
assert result["fwVersionRaw"] == 1
35+
36+
2737
def test_extract_segments_returns_per_segment_metadata(fw_path, tmp_path):
2838
output_dir = str(tmp_path / "out")
2939

0 commit comments

Comments
 (0)