Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ while loop.time() < end:
|---|---|
| `mjpeg_stream`, `mjpeg_stream_bytes`, `open_ws`, `open_webrtc_signaling` | all |
| `get_snapshot` | non-Pro, or Pro with `interrupt_webrtc=True` |
| `set_screen`, `set_frame_detect`, `pause_frame_detect` | non-Pro |
| `set_screen`, `set_frame_detect`, `pause_frame_detect` | non-Pro; `set_screen(RESOLUTION, ...)` below 2.5.4 |
| `get_input_region`, `set_input_region`, `get_input_resolution` | non-Pro 2.5.1 |
| `reset_hdmi` | PCIe 2.1.5 |
| `get_hdmi_state`, `enable_hdmi`, `disable_hdmi` | PCIe 2.2.8 |
Expand Down
13 changes: 12 additions & 1 deletion nanokvm/components/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from aiohttp import ClientTimeout, hdrs

from ..compatibility import require_hardware
from ..exceptions import NanoKVMNotSupportedError
from ..models.common import HWFamily, HWVersion
from ..models.non_pro import (
GetHdmiStateRsp,
Expand Down Expand Up @@ -102,7 +103,17 @@ async def get_input_resolution(self) -> GetInputResolutionRsp:

@require_hardware(HWFamily.NON_PRO)
async def set_screen(self, setting: ScreenSettingType, value: int) -> None:
"""Set a non-Pro NanoKVM screen setting."""
"""Set a non-Pro NanoKVM screen setting.

``RESOLUTION`` is gone from 2.5.4, where the video follows the HDMI input.
"""
if setting == ScreenSettingType.RESOLUTION and (
await self._session.application_version_at_least(non_pro="2.5.4")
):
raise NanoKVMNotSupportedError(
"screen resolution requires non-Pro application version < 2.5.4 "
f"(detected: {self._session._application_version})"
)
await self._session.api_request_json(
hdrs.METH_POST,
"/vm/screen",
Expand Down
4 changes: 3 additions & 1 deletion nanokvm/models/non_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@
class ScreenSettingType(StrEnum):
"""Screen Setting types."""

RESOLUTION = "resolution"
RESOLUTION = "resolution" # removed in 2.5.4: video follows the HDMI input
FPS = "fps"
QUALITY = "quality"
TYPE = "type" # 0 = MJPEG, any other value = H.264
GOP = "gop" # 1-100; anything else falls back to 30


class DNSMode(StrEnum):
Expand Down
25 changes: 24 additions & 1 deletion tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import yarl

from nanokvm.client import NanoKVMClient
from nanokvm.models import HWVersion, StreamMode
from nanokvm.exceptions import NanoKVMNotSupportedError
from nanokvm.models import HWVersion, ScreenSettingType, StreamMode

from .common import BASE_URL, mark_detected

Expand Down Expand Up @@ -39,3 +40,25 @@ async def test_pause_frame_detect(client: NanoKVMClient, mocked: aioresponses) -
assert calls[0].kwargs["json"] == {"duration": 3}
with pytest.raises(ValueError):
await client.pause_frame_detect(0)


async def test_set_screen_resolution_removed_in_2_5_4(
client: NanoKVMClient, mocked: aioresponses
) -> None:
"""Test resolution is refused from 2.5.4 and still sent before it."""
url = f"{BASE_URL}vm/screen"
mocked.post(url, payload={"code": 0, "msg": "success", "data": None}, repeat=True)

mark_detected(client, HWVersion.PCIE, application_version="2.5.4")
with pytest.raises(NanoKVMNotSupportedError):
await client.set_screen(ScreenSettingType.RESOLUTION, 1080)
await client.set_screen(ScreenSettingType.GOP, 60)

mark_detected(client, HWVersion.PCIE, application_version="2.5.2")
await client.set_screen(ScreenSettingType.RESOLUTION, 1080)

calls = mocked.requests[("POST", yarl.URL(url))]
assert [call.kwargs["json"] for call in calls] == [
{"type": "gop", "value": 60},
{"type": "resolution", "value": 1080},
]
Loading