From 45153e5b3e1d7f75fe82aa8fc22e755b9b95e6a5 Mon Sep 17 00:00:00 2001 From: Raphael Chicon Date: Thu, 19 Nov 2026 13:03:17 -0300 Subject: [PATCH 1/2] Send EDID presets under the names Pro 1.2.16 uses Pro 1.2.16 renamed its built-in EDID files (E18-4K30FPS became nanokvm-pro-3840x2160-30, and so on) and dropped E58-4K16-10, so switch_edid(EdidPreset.*) failed with "invalid EDID". - EdidPreset values are now the 1.2.16 names. switch_edid sends the old name below 1.2.16 and accepts either name as a string. - get_edid returns the preset for either name. - WQUXGA_3840X2400_30HZ is refused locally from 1.2.16. --- docs/api.md | 2 +- nanokvm/components/video.py | 18 +++++++++++++++++- nanokvm/models/pro.py | 35 +++++++++++++++++++++++------------ tests/test_video.py | 35 ++++++++++++++++++++++++++++++++++- 4 files changed, 75 insertions(+), 15 deletions(-) diff --git a/docs/api.md b/docs/api.md index c155c0a..f0d509d 100644 --- a/docs/api.md +++ b/docs/api.md @@ -148,7 +148,7 @@ while loop.time() < end: | `set_hdmi_idle_timeout` | PCIe 2.5.0 | | `set_stream_mode`, `set_stream_quality`, `set_gop` | Pro | | `get_hdmi_capture`, `set_hdmi_capture`, `get_hdmi_passthrough`, `set_hdmi_passthrough` | Pro | -| `get_edid`, `switch_edid` | Pro | +| `get_edid`, `switch_edid` | Pro; `WQUXGA_3840X2400_30HZ` below 1.2.16 | | `get_custom_edid_list`, `upload_edid`, `delete_edid` | Pro 1.2.3 | | `set_rate_control_mode` | Pro 1.2.6 | | `set_fps` | Pro 1.2.8 | diff --git a/nanokvm/components/video.py b/nanokvm/components/video.py index 0a82024..533ebb7 100644 --- a/nanokvm/components/video.py +++ b/nanokvm/components/video.py @@ -24,7 +24,9 @@ StopFrameDetectReq, ) from ..models.pro import ( + _LEGACY_EDID_NAMES, DeleteEdidReq, + EdidPreset, EdidValue, GetCustomEdidListRsp, GetEdidRsp, @@ -41,6 +43,7 @@ StreamMode, SwitchEdidReq, UploadEdidRsp, + _normalize_edid_value, ) from .session import Controller @@ -203,7 +206,20 @@ async def get_edid(self) -> GetEdidRsp: @require_hardware(HWFamily.PRO) async def switch_edid(self, edid: EdidValue) -> None: - """Switch EDID.""" + """Switch EDID. + + A preset, given by either of its names, is sent under the name the + device's firmware uses. Pro 1.2.16 dropped ``WQUXGA_3840X2400_30HZ``. + """ + edid = _normalize_edid_value(edid) + if isinstance(edid, EdidPreset): + if not await self._session.application_version_at_least(pro="1.2.16"): + edid = _LEGACY_EDID_NAMES.get(edid, edid) + elif edid is EdidPreset.WQUXGA_3840X2400_30HZ: + raise NanoKVMNotSupportedError( + "the 3840x2400 EDID preset requires Pro application version " + f"< 1.2.16 (detected: {self._session._application_version})" + ) await self._session.api_request_json( hdrs.METH_POST, "/vm/edid", diff --git a/nanokvm/models/pro.py b/nanokvm/models/pro.py index ffebd15..dc5c2a2 100644 --- a/nanokvm/models/pro.py +++ b/nanokvm/models/pro.py @@ -81,25 +81,40 @@ class LcdTimeFormat(_CaseInsensitiveStrEnum): class EdidPreset(StrEnum): - """Built-in NanoKVM Pro EDID presets.""" + """Built-in NanoKVM Pro EDID presets, named as Pro 1.2.16 names them. - UHD_4K_30HZ = "E18-4K30FPS" - UHD_4K_39HZ = "E48-4K39FPS" - QHD_1440P_60HZ = "E56-2K60FPS" - FHD_1080P_60HZ = "E54-1080P60FPS" + Pro 1.2.15 and older use other names, and only they have + ``WQUXGA_3840X2400_30HZ``. + """ + + UHD_4K_30HZ = "nanokvm-pro-3840x2160-30" + UHD_4K_39HZ = "nanokvm-pro-3840x2160-39" + QHD_1440P_60HZ = "nanokvm-pro-2560x1440-60" + FHD_1080P_60HZ = "nanokvm-pro-1920x1080-60" WQUXGA_3840X2400_30HZ = "E58-4K16-10" - ULTRAWIDE_3440X1440_60HZ = "E63-Ultrawide" + ULTRAWIDE_3440X1440_60HZ = "nanokvm-pro-3440x1440-60" EdidValue = EdidPreset | str +# Pro 1.2.15 and older names of the presets that 1.2.16 renamed. +_LEGACY_EDID_NAMES: dict[EdidPreset, str] = { + EdidPreset.UHD_4K_30HZ: "E18-4K30FPS", + EdidPreset.UHD_4K_39HZ: "E48-4K39FPS", + EdidPreset.QHD_1440P_60HZ: "E56-2K60FPS", + EdidPreset.FHD_1080P_60HZ: "E54-1080P60FPS", + EdidPreset.ULTRAWIDE_3440X1440_60HZ: "E63-Ultrawide", +} +_PRESETS_BY_LEGACY_NAME = {name: preset for preset, name in _LEGACY_EDID_NAMES.items()} + def _normalize_edid_value(value: Any) -> Any: + """Return the preset for either name of a built-in EDID, else ``value``.""" if isinstance(value, str): try: return EdidPreset(value) except ValueError: - return value + return _PRESETS_BY_LEGACY_NAME.get(value, value) return value @@ -125,13 +140,9 @@ def _normalize_edid(cls, value: Any) -> Any: class SwitchEdidReq(BaseModel): + # The client picks the name the firmware uses, so it is sent unchanged. edid: EdidValue - @field_validator("edid", mode="before") - @classmethod - def _normalize_edid(cls, value: Any) -> Any: - return _normalize_edid_value(value) - class GetCustomEdidListRsp(BaseModel): model_config = ConfigDict(populate_by_name=True) diff --git a/tests/test_video.py b/tests/test_video.py index 6067f25..1899a0e 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -6,7 +6,7 @@ from nanokvm.client import NanoKVMClient from nanokvm.exceptions import NanoKVMNotSupportedError -from nanokvm.models import HWVersion, ScreenSettingType, StreamMode +from nanokvm.models import EdidPreset, HWVersion, ScreenSettingType, StreamMode from .common import BASE_URL, mark_detected @@ -28,6 +28,39 @@ async def test_set_stream_mode_accepts_existing_string_values( assert calls[0].kwargs.get("json") == {"mode": "h264-direct"} +async def test_edid_presets_follow_the_1_2_16_rename( + client: NanoKVMClient, mocked: aioresponses +) -> None: + """Test presets are sent as the firmware names them and read under both names.""" + url = f"{BASE_URL}vm/edid" + mocked.post(url, payload={"code": 0, "msg": "success", "data": None}, repeat=True) + + mark_detected(client, HWVersion.PRO, "1.2.15") + await client.switch_edid(EdidPreset.QHD_1440P_60HZ) + await client.switch_edid("nanokvm-pro-1920x1080-60") + await client.switch_edid(EdidPreset.WQUXGA_3840X2400_30HZ) + + mark_detected(client, HWVersion.PRO, "1.2.16") + await client.switch_edid("E56-2K60FPS") + await client.switch_edid("custom.bin") + with pytest.raises(NanoKVMNotSupportedError): + await client.switch_edid(EdidPreset.WQUXGA_3840X2400_30HZ) + + calls = mocked.requests[("POST", yarl.URL(url))] + assert [call.kwargs["json"]["edid"] for call in calls] == [ + "E56-2K60FPS", + "E54-1080P60FPS", + "E58-4K16-10", + "nanokvm-pro-2560x1440-60", + "custom.bin", + ] + + for name in ("E63-Ultrawide", "nanokvm-pro-3440x1440-60"): + mocked.get(url, payload={"code": 0, "msg": "success", "data": {"edid": name}}) + rsp = await client.get_edid() + assert rsp.edid is EdidPreset.ULTRAWIDE_3440X1440_60HZ + + async def test_pause_frame_detect(client: NanoKVMClient, mocked: aioresponses) -> None: """Test the pause sends its duration and rejects non-positive ones.""" mark_detected(client, HWVersion.PCIE) From d0b19bcff98ddf5d3a97918301109434cc900eb9 Mon Sep 17 00:00:00 2001 From: Raphael Chicon Date: Thu, 19 Nov 2026 22:46:39 -0300 Subject: [PATCH 2/2] Describe how Pro 1.2.16 answers an application update Pro 1.2.16 answers POST /application/update once the package is downloaded and checked, and installs it in a separate worker. A failed install no longer reaches the caller as an error; it only leaves the old version running. --- nanokvm/components/services.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nanokvm/components/services.py b/nanokvm/components/services.py index ed2283e..056227e 100644 --- a/nanokvm/components/services.py +++ b/nanokvm/components/services.py @@ -113,7 +113,9 @@ async def update_application( The device answers once the update is installed, then restarts its server, which ends the session. Non-Pro firmware before 2.5.1 restarts - before its answer is sent, so it drops the connection instead. + before its answer is sent, so it drops the connection instead. Pro + 1.2.16 and later answer once the package is downloaded and install it + in the background, so a failed install shows only as the old version. """ drops_connection = await self._restarts_before_answering() try: