Skip to content

Commit 9c6c5da

Browse files
committed
Merge remote-tracking branch 'origin/main' into add-gpio-list
2 parents 296b502 + 572afed commit 9c6c5da

File tree

3 files changed

+13
-46
lines changed

3 files changed

+13
-46
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.0.7 - 2025-08-20
4+
5+
- feat: add `read_framebuffer_png_bytes()` and `save_framebuffer_png()` methods (#4)
6+
37
## 0.0.6 - 2025-08-17
48

59
- feat: add `set_control()`, `read_pin()`, `listen_pin()`, `serial_write()` methods (#1)

src/wokwi_client/client.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
from wokwi_client.exceptions import ProtocolError
99
from wokwi_client.framebuffer import (
10-
compare_framebuffer_png,
11-
framebuffer_png_bytes,
12-
framebuffer_read,
10+
read_framebuffer_png_bytes,
1311
save_framebuffer_png,
1412
)
1513

@@ -276,22 +274,10 @@ async def set_control(
276274
"""
277275
return await set_control(self._transport, part=part, control=control, value=value)
278276

279-
async def framebuffer_read(self, id: str) -> ResponseMessage:
280-
"""Read the current framebuffer for the given device id."""
281-
return await framebuffer_read(self._transport, id=id)
282-
283-
async def framebuffer_png_bytes(self, id: str) -> bytes:
277+
async def read_framebuffer_png_bytes(self, id: str) -> bytes:
284278
"""Return the current framebuffer as PNG bytes."""
285-
return await framebuffer_png_bytes(self._transport, id=id)
279+
return await read_framebuffer_png_bytes(self._transport, id=id)
286280

287281
async def save_framebuffer_png(self, id: str, path: Path, overwrite: bool = True) -> Path:
288282
"""Save the current framebuffer as a PNG file."""
289283
return await save_framebuffer_png(self._transport, id=id, path=path, overwrite=overwrite)
290-
291-
async def compare_framebuffer_png(
292-
self, id: str, reference: Path, save_mismatch: Optional[Path] = None
293-
) -> bool:
294-
"""Compare the current framebuffer with a reference PNG file."""
295-
return await compare_framebuffer_png(
296-
self._transport, id=id, reference=reference, save_mismatch=save_mismatch
297-
)

src/wokwi_client/framebuffer.py

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424
from .transport import Transport
2525

2626
__all__ = [
27-
"framebuffer_read",
28-
"framebuffer_png_bytes",
27+
"read_framebuffer",
28+
"read_framebuffer_png_bytes",
2929
"save_framebuffer_png",
30-
"compare_framebuffer_png",
3130
]
3231

3332

34-
async def framebuffer_read(transport: Transport, *, id: str) -> ResponseMessage:
33+
async def read_framebuffer(transport: Transport, *, id: str) -> ResponseMessage:
3534
"""Issue `framebuffer:read` for the given device id and return raw response."""
3635
return await transport.request("framebuffer:read", {"id": id})
3736

@@ -44,9 +43,9 @@ def _extract_png_b64(resp: ResponseMessage) -> str:
4443
return png_b64
4544

4645

47-
async def framebuffer_png_bytes(transport: Transport, *, id: str) -> bytes:
46+
async def read_framebuffer_png_bytes(transport: Transport, *, id: str) -> bytes:
4847
"""Return decoded PNG bytes for the framebuffer of device `id`."""
49-
resp = await framebuffer_read(transport, id=id)
48+
resp = await read_framebuffer(transport, id=id)
5049
return base64.b64decode(_extract_png_b64(resp))
5150

5251

@@ -64,30 +63,8 @@ async def save_framebuffer_png(
6463
"""
6564
if path.exists() and not overwrite:
6665
raise WokwiError(f"File already exists and overwrite=False: {path}")
67-
data = await framebuffer_png_bytes(transport, id=id)
66+
data = await read_framebuffer_png_bytes(transport, id=id)
6867
path.parent.mkdir(parents=True, exist_ok=True)
6968
with open(path, "wb") as f:
7069
f.write(data)
7170
return path
72-
73-
74-
async def compare_framebuffer_png(
75-
transport: Transport, *, id: str, reference: Path, save_mismatch: Path | None = None
76-
) -> bool:
77-
"""Compare the current framebuffer PNG with a reference file.
78-
79-
Performs a byte-for-byte comparison. If different and `save_mismatch` is
80-
provided, writes the current framebuffer PNG there.
81-
82-
Returns True if identical, False otherwise.
83-
"""
84-
if not reference.exists():
85-
raise WokwiError(f"Reference image does not exist: {reference}")
86-
current = await framebuffer_png_bytes(transport, id=id)
87-
ref_bytes = reference.read_bytes()
88-
if current == ref_bytes:
89-
return True
90-
if save_mismatch:
91-
save_mismatch.parent.mkdir(parents=True, exist_ok=True)
92-
save_mismatch.write_bytes(current)
93-
return False

0 commit comments

Comments
 (0)