pyvisionect 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/.github/workflows/test.yml +5 -1
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/PKG-INFO +1 -1
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/pyproject.toml +1 -1
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/devices/__init__.py +2 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/devices/panels.py +140 -24
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/tcp.py +83 -9
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/packets/status.py +15 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/session/device.py +15 -2
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_api_additions.py +21 -1
- pyvisionect-0.2.0/tests/test_panel_fallback.py +169 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_tcp_server.py +50 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/.github/workflows/publish.yml +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/.gitignore +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/LICENSE +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/OPEN-QUESTIONS.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/README.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/docs/README.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/docs/firmware.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/docs/framing.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/docs/imaging.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/docs/overview.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/docs/packets.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/docs/parameters.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/docs/status.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/docs/unknowns.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/docs/usb-cli.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/examples/push_test_card.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/__init__.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/devices/enums.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/devices/tclv.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/README.md +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/__init__.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/checksum.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/constants.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/data/blue_noise_64.npy +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/decode.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/dither.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/encoder.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/geometry.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/grey.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/interlace.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/pack.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/panel.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/partial.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/imaging/rects.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/__init__.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/__init__.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/cli.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/commands.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/console.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/device.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/discovery.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/encryption.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/errors.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/fake.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/parsers.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/io/usb/provisioning.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/packets/__init__.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/packets/control.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/packets/file.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/packets/image.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/packets/misc.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/packets/param.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/packets/stored.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/py.typed +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/session/__init__.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/session/connection.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/session/events.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/session/filetransfer.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/session/pending.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/wire/__init__.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/wire/blocks.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/wire/checksum.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/wire/errors.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/src/pyvisionect/wire/framing.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/conftest.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/data/image0_pv2_head.bin +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/data/test-tls-cert.pem +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/data/test-tls-key.pem +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/fixtures/golden.json.gz +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/conftest.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/data/golden_canvas_1440x2560_grey8.raw.xz +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/data/golden_capture.json +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/test_decode.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/test_dither.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/test_encode_frame.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/test_golden_capture.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/test_grey.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/test_interlace.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/test_pack.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/test_panel.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/test_partial.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/test_rects.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_blocks.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_checksum.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_file_readback.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_filetransfer.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_framing.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_golden_replay.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_packets.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_pcap_full_replay.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_pending.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_persistence.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_sansio_purity.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_session.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_status_codecs.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_stored_frames.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_sync_status.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/test_tclv.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/usb/__init__.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/usb/test_cli.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/usb/test_commands.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/usb/test_console.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/usb/test_discovery.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/usb/test_parsers.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/usb/test_provisioning.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tools/extract_pcap_fixture.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/tools/gen_blue_noise.py +0 -0
- {pyvisionect-0.1.0 → pyvisionect-0.2.0}/uv.lock +0 -0
|
@@ -7,10 +7,14 @@ on:
|
|
|
7
7
|
jobs:
|
|
8
8
|
pytest:
|
|
9
9
|
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
fail-fast: false
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
10
14
|
steps:
|
|
11
15
|
- uses: actions/checkout@v4
|
|
12
16
|
- uses: actions/setup-python@v5
|
|
13
17
|
with:
|
|
14
|
-
python-version:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
15
19
|
- run: pip install -e '.[imaging,usb,test]'
|
|
16
20
|
- run: pytest -q
|
|
@@ -38,6 +38,7 @@ from .panels import (
|
|
|
38
38
|
Panel,
|
|
39
39
|
display_type_name,
|
|
40
40
|
driver_for,
|
|
41
|
+
driver_for_size,
|
|
41
42
|
panel_for,
|
|
42
43
|
)
|
|
43
44
|
from .tclv import (
|
|
@@ -86,6 +87,7 @@ __all__ = [
|
|
|
86
87
|
"describe",
|
|
87
88
|
"display_type_name",
|
|
88
89
|
"driver_for",
|
|
90
|
+
"driver_for_size",
|
|
89
91
|
"lookup",
|
|
90
92
|
"name_of",
|
|
91
93
|
"panel_for",
|
|
@@ -8,8 +8,9 @@ mirror that.
|
|
|
8
8
|
``DisplayType`` must stay an **opaque uint32**. The live 32" sign reports
|
|
9
9
|
``0xC2050128``, which is *not* in the vendor's enum (it falls through to
|
|
10
10
|
``DISPLAY_UNKNOWN``) and yet is a perfectly valid firmware-service key. So:
|
|
11
|
-
look the raw value up, fall back to
|
|
12
|
-
|
|
11
|
+
look the raw value up, fall back to the size the device reports (as the vendor
|
|
12
|
+
does) and only then to a default row, and take *capabilities* from the device's
|
|
13
|
+
own ``PV2Features`` advertisement -- never from the model.
|
|
13
14
|
"""
|
|
14
15
|
|
|
15
16
|
from __future__ import annotations
|
|
@@ -26,6 +27,7 @@ __all__ = [
|
|
|
26
27
|
"DISPLAY_TYPE_DRIVER",
|
|
27
28
|
"panel_for",
|
|
28
29
|
"driver_for",
|
|
30
|
+
"driver_for_size",
|
|
29
31
|
]
|
|
30
32
|
|
|
31
33
|
|
|
@@ -83,12 +85,22 @@ class Panel:
|
|
|
83
85
|
"""The raw ``DisplayType`` this row was looked up with, when known."""
|
|
84
86
|
|
|
85
87
|
is_default: bool = False
|
|
86
|
-
"""True when this is the fallback row rather than a
|
|
88
|
+
"""True when this is the hard-coded fallback row rather than a real answer.
|
|
87
89
|
|
|
88
90
|
Worth surfacing in diagnostics: our sign's ``0xC2050128`` is not in the
|
|
89
91
|
vendor's enum at all, so "unrecognised panel, assuming 2880x640" is an
|
|
90
92
|
honest thing to tell a user, and silently using a guess is not. Capabilities
|
|
91
93
|
still come from the device's own ``PV2Features``, not from this.
|
|
94
|
+
|
|
95
|
+
False when the geometry came from the device's own reported size (see
|
|
96
|
+
:attr:`from_reported_size`); that is the vendor's answer too, not a guess.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
from_reported_size: bool = False
|
|
100
|
+
"""True when the geometry came from the device's reported size, not a table row.
|
|
101
|
+
|
|
102
|
+
That is what the vendor server does for a ``DisplayType`` it has no case
|
|
103
|
+
for, so it is not a guess -- but it is worth showing in diagnostics.
|
|
92
104
|
"""
|
|
93
105
|
|
|
94
106
|
@property
|
|
@@ -100,7 +112,12 @@ class Panel:
|
|
|
100
112
|
|
|
101
113
|
def describe(self) -> str:
|
|
102
114
|
"""A one-line human description, for diagnostics."""
|
|
103
|
-
|
|
115
|
+
if self.is_default:
|
|
116
|
+
prefix = "unrecognised panel, assuming"
|
|
117
|
+
elif self.from_reported_size:
|
|
118
|
+
prefix = f"{self.name}, sized from device report:"
|
|
119
|
+
else:
|
|
120
|
+
prefix = self.name
|
|
104
121
|
return (
|
|
105
122
|
f"{prefix} {self.canvas_width}x{self.canvas_height} "
|
|
106
123
|
f"({self.displays} x {self.width}x{self.height}, driver {self.driver})"
|
|
@@ -181,23 +198,38 @@ DISPLAY_TYPE_DRIVER: dict[int, str] = {
|
|
|
181
198
|
DEFAULT_PANEL = Panel(
|
|
182
199
|
width=1440, height=640, displays=4, driver="eink-flip", is_default=True
|
|
183
200
|
)
|
|
184
|
-
"""
|
|
185
|
-
|
|
186
|
-
The vendor's switch sends ``{5, 13, 14, 15, 16, 17
|
|
187
|
-
``
|
|
188
|
-
|
|
189
|
-
device-reported ``2880x640`` into ``4 x 1440x640
|
|
190
|
-
``0xC2050128``
|
|
201
|
+
"""What we assume when we know neither the ``DisplayType`` nor the size.
|
|
202
|
+
|
|
203
|
+
The vendor's switch sends ``{5, 13, 14, 15, 16, 17}`` to ``1440x640 forced to
|
|
204
|
+
4 displays``, logging ``"We expect 4 virtual displays for one 32\\" eink
|
|
205
|
+
display!"``. Its ``default:`` arm (server 9.2.0, ``config.go:267``) uses the
|
|
206
|
+
device-reported size instead, rewriting ``2 x 2880x640`` into ``4 x 1440x640``;
|
|
207
|
+
that is how our sign's unknown ``0xC2050128`` ends up on this geometry, and
|
|
208
|
+
:func:`panel_for` does the same when it is given the reported size. Without a
|
|
209
|
+
reported size the vendor fails; we use this row so older callers keep working.
|
|
191
210
|
"""
|
|
192
211
|
|
|
193
212
|
PANELS: dict[int, Panel] = {
|
|
194
213
|
0x7FFFFFFD: Panel(80, 32, 1, "eink-generic"),
|
|
195
214
|
1: Panel(600, 800, 1, "eink-generic"),
|
|
196
215
|
6: Panel(1024, 758, 1, "eink-generic"),
|
|
216
|
+
# 8 (EINK_6_0_C219) and 9 (EINK_6_0_C246) are 6" panels and share type 6's
|
|
217
|
+
# 1024x758 arm in device-config.SetupDisplaysType (config.go:234-237) in
|
|
218
|
+
# visionect/visionect-server-v3:9.2.0, /opt/visionect/vss/bin/vss.
|
|
219
|
+
8: Panel(1024, 758, 1, "eink-generic"),
|
|
220
|
+
9: Panel(1024, 758, 1, "eink-generic"),
|
|
221
|
+
# Joan 6, reported in issue #3 and confirmed on real hardware. The vendor has
|
|
222
|
+
# no row for it (visionect/visionect-server-v3:9.2.0, sha256:7f666db9...,
|
|
223
|
+
# /opt/visionect/vss/bin/vss: no case in status.(*DisplayType).String /
|
|
224
|
+
# FwServerString, or in device-config.SetupDisplaysType), so it is
|
|
225
|
+
# DISPLAY_UNKNOWN there too. The vendor's default arm (config.go:267) uses
|
|
226
|
+
# the device-reported DisplayWidth/DisplayHeight and NumberOfSupportedDisplays,
|
|
227
|
+
# and for DISPLAY_UNKNOWN it picks the driver with
|
|
228
|
+
# common/v2.DriverForDisplay(w, h) (display-translations.go:72), which maps
|
|
229
|
+
# 1024x758 to type 6 -> "eink-generic". This row reproduces that result.
|
|
230
|
+
0x501100EB: Panel(1024, 758, 1, "eink-generic"),
|
|
197
231
|
2: Panel(1200, 825, 1, "eink-generic"),
|
|
198
232
|
7: Panel(1200, 825, 1, "eink-generic"),
|
|
199
|
-
8: Panel(1200, 825, 1, "eink-generic"),
|
|
200
|
-
9: Panel(1200, 825, 1, "eink-generic"),
|
|
201
233
|
10: Panel(1200, 825, 1, "eink-generic"),
|
|
202
234
|
11: Panel(1200, 825, 1, "eink-generic"),
|
|
203
235
|
0xA30500F3: Panel(1200, 825, 1, "eink-generic"),
|
|
@@ -216,24 +248,108 @@ PANELS: dict[int, Panel] = {
|
|
|
216
248
|
default row. Geometry from ``SetupDisplaysType``."""
|
|
217
249
|
|
|
218
250
|
|
|
219
|
-
|
|
220
|
-
|
|
251
|
+
_SIZE_DISPLAY_TYPES: dict[tuple[int, int], int] = {
|
|
252
|
+
(80, 32): 0x7FFFFFFD,
|
|
253
|
+
(600, 800): 1,
|
|
254
|
+
(1024, 758): 6,
|
|
255
|
+
(1200, 825): 2,
|
|
256
|
+
(1600, 1200): 3,
|
|
257
|
+
(1440, 640): 5,
|
|
258
|
+
(1280, 960): 4,
|
|
259
|
+
}
|
|
260
|
+
"""``common/v2.DriverForDisplay`` (``display-translations.go:65-85``): the size
|
|
261
|
+
of one display mapped to a ``DisplayType``, whose driver name is then used."""
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def driver_for_size(width: int, height: int) -> str:
|
|
265
|
+
"""Driver name for one display of ``width`` x ``height``, as the vendor picks it.
|
|
221
266
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
"
|
|
267
|
+
Mirrors ``common/v2.DriverForDisplay``. An unrecognised size gives
|
|
268
|
+
``"no display"``, as in the vendor; like ``"unknown"`` it is not mirrored.
|
|
269
|
+
"""
|
|
270
|
+
display_type = _SIZE_DISPLAY_TYPES.get((width, height), 0)
|
|
271
|
+
return DISPLAY_TYPE_DRIVER[display_type]
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _panel_from_reported_size(
|
|
275
|
+
display_type: int, width: int, height: int, num_displays: int
|
|
276
|
+
) -> Panel:
|
|
277
|
+
"""The default arm of ``SetupDisplaysType`` (``config.go:267-273``).
|
|
278
|
+
|
|
279
|
+
Geometry is whatever the device reports. The one rewrite is the 32"
|
|
280
|
+
sign's: two 2880x640 channels become four 1440x640 virtual displays. The
|
|
281
|
+
driver comes from the type when the vendor knows its name, and from the
|
|
282
|
+
size otherwise (``config.go:323-325``).
|
|
283
|
+
"""
|
|
284
|
+
if num_displays == 2 and width == 2880 and height == 640:
|
|
285
|
+
width, num_displays = 1440, 4
|
|
286
|
+
if display_type in DISPLAY_TYPE_NAMES:
|
|
287
|
+
driver = DISPLAY_TYPE_DRIVER[display_type]
|
|
288
|
+
else:
|
|
289
|
+
driver = driver_for_size(width, height)
|
|
290
|
+
return Panel(
|
|
291
|
+
width,
|
|
292
|
+
height,
|
|
293
|
+
num_displays,
|
|
294
|
+
driver,
|
|
295
|
+
display_type=display_type,
|
|
296
|
+
from_reported_size=True,
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def panel_for(
|
|
301
|
+
display_type: int,
|
|
302
|
+
*,
|
|
303
|
+
width: int | None = None,
|
|
304
|
+
height: int | None = None,
|
|
305
|
+
num_displays: int | None = None,
|
|
306
|
+
) -> Panel:
|
|
307
|
+
"""Panel geometry for a raw ``DisplayType``.
|
|
308
|
+
|
|
309
|
+
A type listed in :data:`PANELS` gets its row; the device-reported size is
|
|
310
|
+
ignored, as the vendor ignores it. The one exception is type 1, which the
|
|
311
|
+
vendor treats as 600x800 only when the device reports width 800
|
|
312
|
+
(``config.go:224-225``); with any other reported width the size decides.
|
|
313
|
+
|
|
314
|
+
Any other type is sized the way the vendor server does it: from the
|
|
315
|
+
device's own ``DisplayWidth``/``DisplayHeight`` (status tags 38/39) and
|
|
316
|
+
``NumberOfSupportedDisplays`` (tag 7). Pass all three to get that.
|
|
317
|
+
|
|
318
|
+
If any of the three is missing or zero, this returns :data:`DEFAULT_PANEL`
|
|
319
|
+
with :attr:`Panel.is_default` set. The vendor raises an error there
|
|
320
|
+
instead; we keep the old 32" default so a status without a size still works
|
|
321
|
+
and the caller can still say "unrecognised panel, assuming 2880x640".
|
|
322
|
+
|
|
323
|
+
The returned :class:`Panel` always carries the ``display_type`` it was
|
|
324
|
+
looked up with.
|
|
225
325
|
"""
|
|
226
326
|
found = PANELS.get(display_type)
|
|
227
|
-
if found is None:
|
|
228
|
-
return replace(
|
|
229
|
-
|
|
327
|
+
if found is not None and not (display_type == 1 and width and width != 800):
|
|
328
|
+
return replace(found, display_type=display_type)
|
|
329
|
+
if width and height and num_displays:
|
|
330
|
+
return _panel_from_reported_size(
|
|
331
|
+
display_type, int(width), int(height), int(num_displays)
|
|
332
|
+
)
|
|
333
|
+
return replace(DEFAULT_PANEL, display_type=display_type)
|
|
230
334
|
|
|
231
335
|
|
|
232
|
-
def driver_for(
|
|
233
|
-
|
|
336
|
+
def driver_for(
|
|
337
|
+
display_type: int,
|
|
338
|
+
*,
|
|
339
|
+
width: int | None = None,
|
|
340
|
+
height: int | None = None,
|
|
341
|
+
num_displays: int | None = None,
|
|
342
|
+
) -> Driver:
|
|
343
|
+
"""Driver spec for a raw ``DisplayType``.
|
|
344
|
+
|
|
345
|
+
Takes the same optional reported size as :func:`panel_for`, so that an
|
|
346
|
+
unknown type gets the same driver from both.
|
|
347
|
+
"""
|
|
234
348
|
name = DISPLAY_TYPE_DRIVER.get(display_type)
|
|
235
349
|
if name is None:
|
|
236
|
-
name = panel_for(
|
|
350
|
+
name = panel_for(
|
|
351
|
+
display_type, width=width, height=height, num_displays=num_displays
|
|
352
|
+
).driver
|
|
237
353
|
return DRIVERS.get(name, DRIVERS["unknown"])
|
|
238
354
|
|
|
239
355
|
|
|
@@ -176,6 +176,17 @@ class ServerStats:
|
|
|
176
176
|
rejected: int = 0
|
|
177
177
|
"""Connections closed on a protocol violation."""
|
|
178
178
|
|
|
179
|
+
unidentified_timeouts: int = 0
|
|
180
|
+
"""Connections closed because they never identified.
|
|
181
|
+
|
|
182
|
+
A device that completes the TCP handshake and then sends nothing holds the
|
|
183
|
+
socket open forever, because the read loop has nothing to wake it. Observed
|
|
184
|
+
twice after a Home Assistant restart: ``segs_in: 2`` -- the handshake and
|
|
185
|
+
nothing else -- for minutes, while the sign believed it was connected and
|
|
186
|
+
the integration reported it absent. Closing our end makes the device
|
|
187
|
+
re-dial, which clears it.
|
|
188
|
+
"""
|
|
189
|
+
|
|
179
190
|
tls_accepted: int = 0
|
|
180
191
|
"""Connections whose TLS handshake completed."""
|
|
181
192
|
|
|
@@ -357,6 +368,12 @@ class VisionectServer:
|
|
|
357
368
|
certfile / keyfile: a shorthand for
|
|
358
369
|
``ssl_context=server_ssl_context(certfile, keyfile)``. Mutually
|
|
359
370
|
exclusive with *ssl_context*.
|
|
371
|
+
identify_timeout: close a connection that has sent nothing at all
|
|
372
|
+
after this many seconds, so the device re-dials. ``None``
|
|
373
|
+
disables it. Only applies *before* a device identifies: once it
|
|
374
|
+
has, it may hold the socket quiet between heartbeats. The default
|
|
375
|
+
is generous -- a real sign sends its first status within a second
|
|
376
|
+
of connecting.
|
|
360
377
|
clock: seconds-valued monotonic clock. Injectable for tests; this is the
|
|
361
378
|
**only** place the library reads a clock.
|
|
362
379
|
|
|
@@ -381,6 +398,7 @@ class VisionectServer:
|
|
|
381
398
|
certfile: str | None = None,
|
|
382
399
|
keyfile: str | None = None,
|
|
383
400
|
clock: Callable[[], float] = time.monotonic,
|
|
401
|
+
identify_timeout: float | None = 120.0,
|
|
384
402
|
) -> None:
|
|
385
403
|
self.on_events = on_events
|
|
386
404
|
self.store = store if store is not None else DeviceStateStore()
|
|
@@ -392,12 +410,16 @@ class VisionectServer:
|
|
|
392
410
|
if ssl_context is None and certfile is not None:
|
|
393
411
|
ssl_context = server_ssl_context(certfile, keyfile)
|
|
394
412
|
self.ssl_context = ssl_context
|
|
413
|
+
self.identify_timeout = identify_timeout
|
|
395
414
|
self.clock = clock
|
|
396
415
|
self.stats = ServerStats()
|
|
397
416
|
self._server: asyncio.AbstractServer | None = None
|
|
398
417
|
self._connections: dict[bytes, DeviceConnection] = {}
|
|
399
418
|
self._writers: dict[bytes, asyncio.StreamWriter] = {}
|
|
400
419
|
self._listeners: list[EventHandler] = []
|
|
420
|
+
# Every accepted socket's transport, so close() can shut them on a
|
|
421
|
+
# runtime whose asyncio.Server has no close_clients() (3.12).
|
|
422
|
+
self._transports: set[asyncio.BaseTransport] = set()
|
|
401
423
|
|
|
402
424
|
@property
|
|
403
425
|
def connections(self) -> dict[bytes, DeviceConnection]:
|
|
@@ -427,7 +449,7 @@ class VisionectServer:
|
|
|
427
449
|
"""
|
|
428
450
|
try:
|
|
429
451
|
self._server = await asyncio.start_server(
|
|
430
|
-
self.
|
|
452
|
+
self._accept, self.host, self.port
|
|
431
453
|
)
|
|
432
454
|
except OSError as exc:
|
|
433
455
|
raise ListenError(self.host, self.port, exc) from exc
|
|
@@ -469,16 +491,19 @@ class VisionectServer:
|
|
|
469
491
|
return
|
|
470
492
|
server, self._server = self._server, None
|
|
471
493
|
server.close()
|
|
472
|
-
# Python 3.13+ has both
|
|
473
|
-
# warning rather than an AttributeError during shutdown.
|
|
494
|
+
# Python 3.13+ has both close_clients() and abort_clients().
|
|
474
495
|
closer = getattr(server, "abort_clients" if abort else "close_clients", None)
|
|
475
496
|
if closer is not None:
|
|
476
497
|
closer()
|
|
477
|
-
else:
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
)
|
|
498
|
+
else:
|
|
499
|
+
# Python 3.12's wait_closed() already waits for every connection,
|
|
500
|
+
# but close_clients() only arrived in 3.13, so close the
|
|
501
|
+
# transports we tracked ourselves. (3.11 does not wait at all.)
|
|
502
|
+
for transport in list(self._transports):
|
|
503
|
+
if abort and isinstance(transport, asyncio.WriteTransport):
|
|
504
|
+
transport.abort()
|
|
505
|
+
else:
|
|
506
|
+
transport.close()
|
|
482
507
|
with contextlib.suppress(Exception):
|
|
483
508
|
await server.wait_closed()
|
|
484
509
|
|
|
@@ -500,6 +525,16 @@ class VisionectServer:
|
|
|
500
525
|
head += chunk
|
|
501
526
|
return head
|
|
502
527
|
|
|
528
|
+
async def _accept(
|
|
529
|
+
self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter
|
|
530
|
+
) -> None:
|
|
531
|
+
transport = writer.transport
|
|
532
|
+
self._transports.add(transport)
|
|
533
|
+
try:
|
|
534
|
+
await self._handle_client(reader, writer)
|
|
535
|
+
finally:
|
|
536
|
+
self._transports.discard(transport)
|
|
537
|
+
|
|
503
538
|
async def _handle_client(
|
|
504
539
|
self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter
|
|
505
540
|
) -> None:
|
|
@@ -513,7 +548,28 @@ class VisionectServer:
|
|
|
513
548
|
|
|
514
549
|
# The sniff, before anything else and before the timers start: this is
|
|
515
550
|
# the only point at which the connection's protocol is still undecided.
|
|
516
|
-
|
|
551
|
+
#
|
|
552
|
+
# Bounded, because this is where a zombie connection actually hangs: a
|
|
553
|
+
# device that completes the handshake and sends nothing never reaches
|
|
554
|
+
# the read loop at all, so a guard further down would never run.
|
|
555
|
+
try:
|
|
556
|
+
head = (
|
|
557
|
+
await asyncio.wait_for(self._peek(reader), self.identify_timeout)
|
|
558
|
+
if self.identify_timeout
|
|
559
|
+
else await self._peek(reader)
|
|
560
|
+
)
|
|
561
|
+
except asyncio.TimeoutError:
|
|
562
|
+
self.stats.unidentified_timeouts += 1
|
|
563
|
+
log.warning(
|
|
564
|
+
"closing %s: connected but sent nothing in %.0fs, so it cannot "
|
|
565
|
+
"be identified. Closing makes the device re-dial.",
|
|
566
|
+
peer,
|
|
567
|
+
self.identify_timeout,
|
|
568
|
+
)
|
|
569
|
+
writer.close()
|
|
570
|
+
with contextlib.suppress(Exception):
|
|
571
|
+
await writer.wait_closed()
|
|
572
|
+
return
|
|
517
573
|
if looks_like_client_hello(head):
|
|
518
574
|
if self.ssl_context is None:
|
|
519
575
|
self.stats.tls_unsupported += 1
|
|
@@ -556,6 +612,24 @@ class VisionectServer:
|
|
|
556
612
|
while not conn.closed:
|
|
557
613
|
if head:
|
|
558
614
|
data, head = head, b""
|
|
615
|
+
elif registered is None and self.identify_timeout:
|
|
616
|
+
# Only while unidentified: a device that has introduced
|
|
617
|
+
# itself may legitimately hold the socket quiet between
|
|
618
|
+
# heartbeats, but one that has said nothing at all is a
|
|
619
|
+
# zombie and will never speak.
|
|
620
|
+
try:
|
|
621
|
+
data = await asyncio.wait_for(
|
|
622
|
+
reader.read(READ_CHUNK), self.identify_timeout
|
|
623
|
+
)
|
|
624
|
+
except asyncio.TimeoutError:
|
|
625
|
+
self.stats.unidentified_timeouts += 1
|
|
626
|
+
log.warning(
|
|
627
|
+
"closing %s: connected but sent nothing in %.0fs, so it "
|
|
628
|
+
"cannot be identified. Closing makes the device re-dial.",
|
|
629
|
+
peer,
|
|
630
|
+
self.identify_timeout,
|
|
631
|
+
)
|
|
632
|
+
break
|
|
559
633
|
else:
|
|
560
634
|
data = await reader.read(READ_CHUNK)
|
|
561
635
|
if not data:
|
|
@@ -481,6 +481,21 @@ class StatusPacket:
|
|
|
481
481
|
"""Raw uint32 ``DisplayType`` (tag 8). Deliberately not an enum."""
|
|
482
482
|
return self.raw.get(8)
|
|
483
483
|
|
|
484
|
+
@property
|
|
485
|
+
def number_of_supported_displays(self) -> int | None:
|
|
486
|
+
"""Tag 7: how many physical display channels the device drives."""
|
|
487
|
+
return self.raw.get(7)
|
|
488
|
+
|
|
489
|
+
@property
|
|
490
|
+
def display_width(self) -> int | None:
|
|
491
|
+
"""Tag 38: width of one physical display channel, in pixels."""
|
|
492
|
+
return self.raw.get(38)
|
|
493
|
+
|
|
494
|
+
@property
|
|
495
|
+
def display_height(self) -> int | None:
|
|
496
|
+
"""Tag 39: height of one physical display channel, in pixels."""
|
|
497
|
+
return self.raw.get(39)
|
|
498
|
+
|
|
484
499
|
@property
|
|
485
500
|
def display_state_crc(self) -> int | None:
|
|
486
501
|
"""Tag 9: the XXHash32 the device computed over its own 8-bit state image.
|
|
@@ -214,8 +214,21 @@ class DeviceState:
|
|
|
214
214
|
|
|
215
215
|
@property
|
|
216
216
|
def panel(self) -> Panel:
|
|
217
|
-
"""Modelled geometry,
|
|
218
|
-
|
|
217
|
+
"""Modelled geometry for this device, as the vendor server would model it.
|
|
218
|
+
|
|
219
|
+
From the raw ``DisplayType`` when it has a :data:`PANELS` row, else
|
|
220
|
+
from the size and display count the device reports in its status,
|
|
221
|
+
else the hard-coded default row. See :func:`panel_for`.
|
|
222
|
+
"""
|
|
223
|
+
status = self.last_status
|
|
224
|
+
if status is None:
|
|
225
|
+
return panel_for(-1)
|
|
226
|
+
return panel_for(
|
|
227
|
+
status.display_type if status.display_type is not None else -1,
|
|
228
|
+
width=status.display_width,
|
|
229
|
+
height=status.display_height,
|
|
230
|
+
num_displays=status.number_of_supported_displays,
|
|
231
|
+
)
|
|
219
232
|
|
|
220
233
|
@property
|
|
221
234
|
def hardware_name_id(self) -> int | None:
|
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import pytest
|
|
6
6
|
|
|
7
|
-
from pyvisionect.devices import panel_for
|
|
7
|
+
from pyvisionect.devices import driver_for, panel_for
|
|
8
8
|
from pyvisionect.devices.enums import PacketType
|
|
9
9
|
from pyvisionect.packets import (
|
|
10
10
|
DEVICE_IMAGE_FILES,
|
|
@@ -318,6 +318,26 @@ def test_panel_reports_whether_it_is_a_guess() -> None:
|
|
|
318
318
|
)
|
|
319
319
|
|
|
320
320
|
|
|
321
|
+
def test_joan_6_display_type_is_recognised() -> None:
|
|
322
|
+
# Issue #3: the Joan 6 reports 0x501100EB, which used to fall through to
|
|
323
|
+
# the 32" default and get sent a 2880x640 image it rejects as out of bounds.
|
|
324
|
+
joan6 = panel_for(0x501100EB)
|
|
325
|
+
assert joan6.is_default is False
|
|
326
|
+
assert (joan6.canvas_width, joan6.canvas_height) == (1024, 758)
|
|
327
|
+
assert joan6.displays == 1
|
|
328
|
+
assert joan6.driver_spec.mirror is False
|
|
329
|
+
assert driver_for(0x501100EB).name == "eink-generic"
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
@pytest.mark.parametrize("display_type", [6, 8, 9])
|
|
333
|
+
def test_six_inch_display_types_are_1024x758(display_type: int) -> None:
|
|
334
|
+
# Vendor server 9.2.0 sends 6, 8 (EINK_6_0_C219) and 9 (EINK_6_0_C246)
|
|
335
|
+
# down the same 1024x758 arm of SetupDisplaysType.
|
|
336
|
+
panel = panel_for(display_type)
|
|
337
|
+
assert (panel.width, panel.height, panel.displays) == (1024, 758, 1)
|
|
338
|
+
assert panel.driver == "eink-generic"
|
|
339
|
+
|
|
340
|
+
|
|
321
341
|
def test_connect_reason_name() -> None:
|
|
322
342
|
assert StatusPacket(records=[(0, 1)]).connect_reason_name == "reboot"
|
|
323
343
|
assert StatusPacket(records=[(0, 2)]).connect_reason_name == "wakeup"
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""Sizing panels the way the vendor's SetupDisplaysType default arm does.
|
|
2
|
+
|
|
3
|
+
Reference: visionect/visionect-server-v3:9.2.0, /opt/visionect/vss/bin/vss,
|
|
4
|
+
``vss/pkg/device-config.SetupDisplaysType`` and ``common/v2.DriverForDisplay``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
from pyvisionect.devices import (
|
|
12
|
+
DEFAULT_PANEL,
|
|
13
|
+
PANELS,
|
|
14
|
+
driver_for_size,
|
|
15
|
+
panel_for,
|
|
16
|
+
)
|
|
17
|
+
from pyvisionect.packets.status import StatusPacket
|
|
18
|
+
from pyvisionect.session.device import DeviceState
|
|
19
|
+
|
|
20
|
+
UNKNOWN = 0x12345678
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _geometry(panel):
|
|
24
|
+
return (panel.width, panel.height, panel.displays, panel.driver)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_unknown_type_with_reported_1024x758_is_a_single_generic_display() -> None:
|
|
28
|
+
panel = panel_for(UNKNOWN, width=1024, height=758, num_displays=1)
|
|
29
|
+
assert _geometry(panel) == (1024, 758, 1, "eink-generic")
|
|
30
|
+
assert panel.driver_spec.mirror is False
|
|
31
|
+
assert panel.is_default is False
|
|
32
|
+
assert panel.from_reported_size is True
|
|
33
|
+
assert panel.display_type == UNKNOWN
|
|
34
|
+
assert "sized from device report" in panel.describe()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.mark.parametrize(
|
|
38
|
+
("display_type", "driver"),
|
|
39
|
+
[
|
|
40
|
+
(0x60110154, "eink-42-v2"),
|
|
41
|
+
(0x60110191, "eink-42-v2"),
|
|
42
|
+
(0x80000000, "eink-42-flip"),
|
|
43
|
+
],
|
|
44
|
+
)
|
|
45
|
+
def test_four_point_two_inch_types_take_reported_size_and_named_driver(
|
|
46
|
+
display_type: int, driver: str
|
|
47
|
+
) -> None:
|
|
48
|
+
# The vendor knows these types' names, so the driver comes from the type
|
|
49
|
+
# (DisplayType.String), not the size, and the size from the report.
|
|
50
|
+
panel = panel_for(display_type, width=400, height=300, num_displays=1)
|
|
51
|
+
assert _geometry(panel) == (400, 300, 1, driver)
|
|
52
|
+
assert panel.is_default is False
|
|
53
|
+
assert panel.from_reported_size is True
|
|
54
|
+
assert panel.name in ("DISPLAY_EINK_42_V2", "DISPLAY_EINK_42")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_four_point_two_inch_flip_type_is_mirrored() -> None:
|
|
58
|
+
panel = panel_for(0x80000000, width=400, height=300, num_displays=1)
|
|
59
|
+
assert panel.driver_spec.mirror is True
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_type_zero_takes_reported_size() -> None:
|
|
63
|
+
panel = panel_for(0, width=1024, height=758, num_displays=1)
|
|
64
|
+
assert _geometry(panel) == (1024, 758, 1, "no display")
|
|
65
|
+
assert panel.name == "DISPLAY_NONE"
|
|
66
|
+
assert panel.driver_spec.mirror is False
|
|
67
|
+
assert panel.is_default is False
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_live_sign_with_its_real_reported_status_matches_the_old_default() -> None:
|
|
71
|
+
# 0xC2050128 reports 2 x 2880x640; the vendor rewrites that to
|
|
72
|
+
# 4 x 1440x640 and picks eink-flip by size -- exactly the old default row.
|
|
73
|
+
reported = panel_for(0xC2050128, width=2880, height=640, num_displays=2)
|
|
74
|
+
old = panel_for(0xC2050128)
|
|
75
|
+
assert _geometry(reported) == _geometry(old) == (1440, 640, 4, "eink-flip")
|
|
76
|
+
assert reported.driver_spec == old.driver_spec
|
|
77
|
+
assert reported.driver_spec.mirror is True
|
|
78
|
+
assert (reported.canvas_width, reported.canvas_height) == (1440, 2560)
|
|
79
|
+
assert reported.is_default is False
|
|
80
|
+
assert old.is_default is True
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_live_sign_device_state_uses_the_reported_status() -> None:
|
|
84
|
+
# The relevant records from the captured status of the live sign.
|
|
85
|
+
status = StatusPacket(
|
|
86
|
+
records=[(7, 2), (8, 0xC2050128), (22, 8), (38, 2880), (39, 640)]
|
|
87
|
+
)
|
|
88
|
+
state = DeviceState(device_id=bytes(16), last_status=status)
|
|
89
|
+
panel = state.panel
|
|
90
|
+
assert _geometry(panel) == (1440, 640, 4, "eink-flip")
|
|
91
|
+
assert panel.from_reported_size is True
|
|
92
|
+
assert panel.is_default is False
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_device_state_for_an_unknown_joan_like_device() -> None:
|
|
96
|
+
status = StatusPacket(records=[(7, 1), (8, UNKNOWN), (38, 1024), (39, 758)])
|
|
97
|
+
state = DeviceState(device_id=bytes(16), last_status=status)
|
|
98
|
+
assert _geometry(state.panel) == (1024, 758, 1, "eink-generic")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@pytest.mark.parametrize(
|
|
102
|
+
"size",
|
|
103
|
+
[
|
|
104
|
+
{},
|
|
105
|
+
{"width": 0, "height": 0, "num_displays": 0},
|
|
106
|
+
{"width": 1024, "height": 758}, # no display count
|
|
107
|
+
{"width": 1024, "num_displays": 1}, # no height
|
|
108
|
+
],
|
|
109
|
+
)
|
|
110
|
+
def test_unknown_type_without_a_full_reported_size_falls_back_to_default(
|
|
111
|
+
size: dict[str, int],
|
|
112
|
+
) -> None:
|
|
113
|
+
panel = panel_for(UNKNOWN, **size)
|
|
114
|
+
assert _geometry(panel) == _geometry(DEFAULT_PANEL)
|
|
115
|
+
assert panel.is_default is True
|
|
116
|
+
assert panel.from_reported_size is False
|
|
117
|
+
assert panel.display_type == UNKNOWN
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_device_state_with_no_status_is_the_default() -> None:
|
|
121
|
+
panel = DeviceState(device_id=bytes(16)).panel
|
|
122
|
+
assert panel.is_default is True
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@pytest.mark.parametrize("display_type", sorted(PANELS))
|
|
126
|
+
def test_known_types_ignore_the_reported_size(display_type: int) -> None:
|
|
127
|
+
if display_type == 1:
|
|
128
|
+
pytest.skip("type 1 has its own rule")
|
|
129
|
+
panel = panel_for(display_type, width=1234, height=567, num_displays=3)
|
|
130
|
+
assert _geometry(panel) == _geometry(PANELS[display_type])
|
|
131
|
+
assert panel.from_reported_size is False
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_type_1_is_600x800_only_when_reported_width_is_800() -> None:
|
|
135
|
+
assert _geometry(panel_for(1)) == (600, 800, 1, "eink-generic")
|
|
136
|
+
assert _geometry(panel_for(1, width=800, height=600, num_displays=1)) == (
|
|
137
|
+
600, 800, 1, "eink-generic",
|
|
138
|
+
)
|
|
139
|
+
other = panel_for(1, width=1024, height=758, num_displays=1)
|
|
140
|
+
assert _geometry(other) == (1024, 758, 1, "eink-generic")
|
|
141
|
+
assert other.from_reported_size is True
|
|
142
|
+
assert other.display_type == 1
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@pytest.mark.parametrize(
|
|
146
|
+
("size", "driver"),
|
|
147
|
+
[
|
|
148
|
+
((80, 32), "eink-generic"),
|
|
149
|
+
((600, 800), "eink-generic"),
|
|
150
|
+
((1024, 758), "eink-generic"),
|
|
151
|
+
((1200, 825), "eink-generic"),
|
|
152
|
+
((1600, 1200), "eink-generic"),
|
|
153
|
+
((1440, 640), "eink-flip"),
|
|
154
|
+
((1280, 960), "pl-generic"),
|
|
155
|
+
((2880, 1080), "no display"),
|
|
156
|
+
],
|
|
157
|
+
)
|
|
158
|
+
def test_driver_for_size_matches_vendor(size: tuple[int, int], driver: str) -> None:
|
|
159
|
+
assert driver_for_size(*size) == driver
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def test_driver_for_agrees_with_panel_for_given_a_reported_size():
|
|
163
|
+
from pyvisionect.devices.panels import driver_for, panel_for
|
|
164
|
+
|
|
165
|
+
unknown = 0x12345678
|
|
166
|
+
sized = dict(width=1024, height=758, num_displays=1)
|
|
167
|
+
assert driver_for(unknown).name == panel_for(unknown).driver == "eink-flip"
|
|
168
|
+
assert driver_for(unknown, **sized).name == "eink-generic"
|
|
169
|
+
assert driver_for(unknown, **sized).name == panel_for(unknown, **sized).driver
|
|
@@ -556,3 +556,53 @@ def test_server_ssl_context_is_tls_13_only_and_asks_for_no_client_cert() -> None
|
|
|
556
556
|
context = server_ssl_context(str(CERT), str(KEY))
|
|
557
557
|
assert context.minimum_version is ssl.TLSVersion.TLSv1_3
|
|
558
558
|
assert context.verify_mode is ssl.CERT_NONE
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
def test_a_connection_that_never_identifies_is_closed() -> None:
|
|
562
|
+
"""A device that completes the handshake and says nothing is a zombie.
|
|
563
|
+
|
|
564
|
+
Seen twice on real hardware after a Home Assistant restart: ``segs_in: 2``,
|
|
565
|
+
no data for minutes, the sign believing it was connected while the server
|
|
566
|
+
reported it absent. The read loop had nothing to wake it, so the socket sat
|
|
567
|
+
there forever. Closing our end makes the device re-dial.
|
|
568
|
+
"""
|
|
569
|
+
|
|
570
|
+
async def scenario() -> None:
|
|
571
|
+
store = DeviceStateStore()
|
|
572
|
+
server, port, _ = await _serve(store=store, identify_timeout=0.3)
|
|
573
|
+
try:
|
|
574
|
+
reader, writer = await asyncio.open_connection("127.0.0.1", port)
|
|
575
|
+
# connect, then say nothing at all; the server should hang up
|
|
576
|
+
assert await asyncio.wait_for(reader.read(1), timeout=3.0) == b""
|
|
577
|
+
assert server.stats.unidentified_timeouts == 1
|
|
578
|
+
assert server.stats.identified == 0
|
|
579
|
+
writer.close()
|
|
580
|
+
finally:
|
|
581
|
+
await server.close()
|
|
582
|
+
|
|
583
|
+
asyncio.run(asyncio.wait_for(scenario(), timeout=10.0))
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
def test_an_identified_device_may_go_quiet_without_being_closed() -> None:
|
|
587
|
+
"""The watchdog must not fire once a sign has introduced itself.
|
|
588
|
+
|
|
589
|
+
A mains-powered sign holds its socket open and heartbeats once a minute, so
|
|
590
|
+
a short silence after identification is normal, not a fault.
|
|
591
|
+
"""
|
|
592
|
+
|
|
593
|
+
async def scenario() -> None:
|
|
594
|
+
store = DeviceStateStore()
|
|
595
|
+
server, port, _ = await _serve(store=store, identify_timeout=0.3)
|
|
596
|
+
try:
|
|
597
|
+
reader, writer = await asyncio.open_connection("127.0.0.1", port)
|
|
598
|
+
writer.write(status_frame())
|
|
599
|
+
await writer.drain()
|
|
600
|
+
await asyncio.wait_for(reader.read(4096), timeout=2.0) # the ack
|
|
601
|
+
await asyncio.sleep(0.6) # twice the identify timeout
|
|
602
|
+
assert server.stats.unidentified_timeouts == 0
|
|
603
|
+
assert server.connection_for(UUID) is not None
|
|
604
|
+
writer.close()
|
|
605
|
+
finally:
|
|
606
|
+
await server.close()
|
|
607
|
+
|
|
608
|
+
asyncio.run(asyncio.wait_for(scenario(), timeout=10.0))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyvisionect-0.1.0 → pyvisionect-0.2.0}/tests/imaging/data/golden_canvas_1440x2560_grey8.raw.xz
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|