fix: complete HM42 monochrome image planes

This commit is contained in:
yi-bot committed 2026-08-03 02:40:00 +00:00
1 parent 3db8295654
commit 092b104e3d
4 files changed
+52 -1

No files matched your search

+29 -1
View File
@@ -7,10 +7,11 @@ from ppclock.client import PPClient
class FakeTransport:
def __init__(self):
def __init__(self, firmware_revision=None):
self.epd_writes = []
self.rxtx_writes = []
self.address = "AA:BB:CC:DD:EE:FF"
self.firmware_revision = firmware_revision
async def __aenter__(self):
return self
@@ -78,6 +79,33 @@ class TestCommands:
assert client._t.rxtx_writes[0] == bytes([0xEA, 0x00])
assert len(client._t.epd_writes) == 63 + 63 + 1
@pytest.mark.asyncio
async def test_upload_mono_non_hm42_sends_one_plane(self):
from PIL import Image
client = PPClient(FakeTransport("PP_da14585_4.2"))
result = await client.upload_image(
Image.new("RGB", (400, 300), "white"), slot=1,
algo="none", mono=True,
)
assert result["bytes_bw"] == 15000
assert result["bytes_red"] == 0
assert len(client._t.epd_writes) == 63 + 1
@pytest.mark.asyncio
async def test_upload_mono_hm42_appends_empty_red_plane(self):
from PIL import Image
client = PPClient(FakeTransport("HM42_AIO_V1.0.9"))
result = await client.upload_image(
Image.new("RGB", (400, 300), "white"), slot=1,
algo="none", mono=True,
)
assert result["bytes_bw"] == 15000
assert result["bytes_red"] == 15000
assert len(client._t.epd_writes) == 63 + 63 + 1
first_red = client._t.epd_writes[63]
assert first_red[:4] == bytes.fromhex("03000000")
assert set(first_red[4:]) == {0}
@pytest.mark.asyncio
async def test_render_template(self, client):
result = await client.render_template("custom", {"text": "你好"})