Add support for PiKVM Switch and related features

This commit introduces several new components and improvements:
- Added Switch module with firmware update and configuration support
- Implemented new media streaming capabilities
- Updated various UI elements and CSS styles
- Enhanced keyboard and mouse event handling
- Added new validators and configuration options
- Updated Python version support to 3.13
- Improved error handling and logging
This commit is contained in:
mofeng-git
2025-02-01 01:08:36 +00:00
parent 5db37797ea
commit 7b3335ea94
117 changed files with 5342 additions and 479 deletions

View File

@@ -8,6 +8,8 @@ RUN echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch
&& pacman-key --populate archlinux
RUN pacman --noconfirm --ask=4 -Syy \
&& pacman --needed --noconfirm --ask=4 -S \
archlinux-keyring \
&& pacman --needed --noconfirm --ask=4 -S \
glibc \
pacman \
@@ -17,7 +19,6 @@ RUN pacman --noconfirm --ask=4 -Syy \
&& pacman --noconfirm --ask=4 -Syu \
&& pacman --needed --noconfirm --ask=4 -S \
p11-kit \
archlinux-keyring \
ca-certificates \
ca-certificates-mozilla \
ca-certificates-utils \
@@ -48,6 +49,7 @@ RUN pacman --noconfirm --ask=4 -Syy \
python-pyotp \
python-qrcode \
python-pyserial \
python-pyudev \
python-setproctitle \
python-psutil \
python-netifaces \

View File

@@ -39,6 +39,7 @@ disable =
consider-using-f-string,
unnecessary-lambda-assignment,
too-many-positional-arguments,
no-else-continue,
# https://github.com/PyCQA/pylint/issues/3882
[CLASSES]

View File

@@ -57,3 +57,28 @@ Dumper.ignore_aliases
_auth_server_port_fixture
_test_user
Switch.__x_set_port_names
Switch.__x_set_atx_cp_delays
Switch.__x_set_atx_cpl_delays
Switch.__x_set_atx_cr_delays
Nak.INVALID_COMMAND
Nak.BUSY
Nak.NO_DOWNLINK
Nak.DOWNLINK_OVERFLOW
UnitFlags.flashing_busy
StateCache.get_port_names
StateCache.get_atx_cp_delays
StateCache.get_atx_cpl_delays
StorageContext.write_edids
StorageContext.write_colors
StorageContext.write_port_names
StorageContext.write_atx_cp_delays
StorageContext.write_atx_cpl_delays
StorageContext.write_atx_cr_delays
StorageContext.read_edids
StorageContext.read_colors
StorageContext.read_port_names
StorageContext.read_atx_cp_delays
StorageContext.read_atx_cpl_delays
StorageContext.read_atx_cr_delays

View File

@@ -0,0 +1,180 @@
# ========================================================================== #
# #
# KVMD - The main PiKVM daemon. #
# #
# Copyright (C) 2018-2024 Maxim Devaev <mdevaev@gmail.com> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
# #
# ========================================================================== #
from typing import Any
import pytest
from kvmd.validators import ValidatorError
from kvmd.validators.switch import valid_switch_port_name
from kvmd.validators.switch import valid_switch_edid_id
from kvmd.validators.switch import valid_switch_edid_data
from kvmd.validators.switch import valid_switch_color
from kvmd.validators.switch import valid_switch_atx_click_delay
# =====
@pytest.mark.parametrize("arg, retval", [
("\tMac OS Host #1/..", "Mac OS Host #1/.."),
("\t", ""),
("", ""),
])
def test_ok__valid_msd_image_name(arg: Any, retval: str) -> None:
assert valid_switch_port_name(arg) == retval
@pytest.mark.parametrize("arg", [None])
def test_fail__valid_msd_image_name(arg: Any) -> None:
with pytest.raises(ValidatorError):
valid_switch_port_name(arg)
# =====
@pytest.mark.parametrize("arg", [
"550e8400-e29b-41d4-a716-446655440000",
" 00000000-0000-0000-C000-000000000046 ",
" 00000000-0000-0000-0000-000000000000 ",
])
def test_ok__valid_switch_edid_id__no_default(arg: Any) -> None:
assert valid_switch_edid_id(arg, allow_default=False) == arg.strip().lower() # type: ignore
@pytest.mark.parametrize("arg", [
"550e8400-e29b-41d4-a716-44665544",
"ffffuuuu-0000-0000-C000-000000000046",
"default",
"",
None,
])
def test_fail__valid_switch_edid_id__no_default(arg: Any) -> None:
with pytest.raises(ValidatorError):
valid_switch_edid_id(arg, allow_default=False)
# =====
@pytest.mark.parametrize("arg", [
"550e8400-e29b-41d4-a716-446655440000",
" 00000000-0000-0000-C000-000000000046 ",
" 00000000-0000-0000-0000-000000000000 ",
" Default",
])
def test_ok__valid_switch_edid_id__allowed_default(arg: Any) -> None:
assert valid_switch_edid_id(arg, allow_default=True) == arg.strip().lower() # type: ignore
@pytest.mark.parametrize("arg", [
"550e8400-e29b-41d4-a716-44665544",
"ffffuuuu-0000-0000-C000-000000000046",
"",
None,
])
def test_fail__valid_switch_edid_id__allowed_default(arg: Any) -> None:
with pytest.raises(ValidatorError):
valid_switch_edid_id(arg, allow_default=True)
# =====
@pytest.mark.parametrize("arg", [
"f" * 512,
"0" * 512,
"1a" * 256,
])
def test_ok__valid_switch_edid_data(arg: Any) -> None:
assert valid_switch_edid_data(arg) == arg.upper() # type: ignore
@pytest.mark.parametrize("arg", [
"f" * 511,
"0" * 511,
"1a" * 255,
"F" * 513,
"0" * 513,
"1A" * 257,
"",
None,
])
def test_fail__valid_switch_edid_data(arg: Any) -> None:
with pytest.raises(ValidatorError):
valid_switch_edid_data(arg)
# =====
@pytest.mark.parametrize("arg, retval", [
("000000:00:0000", "000000:00:0000"),
(" 0f0f0f:0f:0f0f ", "0F0F0F:0F:0F0F"),
])
def test_ok__valid_switch_color__no_default(arg: Any, retval: str) -> None:
assert valid_switch_color(arg, allow_default=False) == retval
@pytest.mark.parametrize("arg", [
"550e8400-e29b-41d4-a716-44665544",
"ffffuuuu-0000-0000-C000-000000000046",
"000000:00:000000000:00:000G",
"000000:00:000",
"000000:00:000G",
"default",
" Default",
"",
None,
])
def test_fail__valid_switch_color__no_default(arg: Any) -> None:
with pytest.raises(ValidatorError):
valid_switch_color(arg, allow_default=False)
# =====
@pytest.mark.parametrize("arg, retval", [
("000000:00:0000", "000000:00:0000"),
(" 0f0f0f:0f:0f0f ", "0F0F0F:0F:0F0F"),
(" Default", "default"),
])
def test_ok__valid_switch_color__allow_default(arg: Any, retval: str) -> None:
assert valid_switch_color(arg, allow_default=True) == retval
@pytest.mark.parametrize("arg", [
"550e8400-e29b-41d4-a716-44665544",
"ffffuuuu-0000-0000-C000-000000000046",
"000000:00:000000000:00:000G",
"000000:00:000",
"000000:00:000G",
"",
None,
])
def test_fail__valid_switch_color__allow_default(arg: Any) -> None:
with pytest.raises(ValidatorError):
valid_switch_color(arg, allow_default=True)
# =====
@pytest.mark.parametrize("arg", [0, 1, 5, "5 ", "5.0 ", " 10"])
def test_ok__valid_switch_atx_click_delay(arg: Any) -> None:
value = valid_switch_atx_click_delay(arg)
assert type(value) is float # pylint: disable=unidiomatic-typecheck
assert value == float(str(arg).strip())
@pytest.mark.parametrize("arg", ["test", "", None, -6, "-6", "10.1"])
def test_fail__valid_switch_atx_click_delay(arg: Any) -> None:
with pytest.raises(ValidatorError):
print(valid_switch_atx_click_delay(arg))

View File

@@ -3,7 +3,7 @@ envlist = flake8, pylint, mypy, vulture, pytest, eslint, htmlhint, shellcheck
skipsdist = true
[testenv]
basepython = python3.12
basepython = python3.13
sitepackages = true
changedir = /src

View File

@@ -35,6 +35,8 @@ kvmd:
- "--process-name-prefix={process_name_prefix}"
- "--notify-parent"
- "--no-log-colors"
- "--jpeg-sink=kvmd::ustreamer::jpeg"
- "--jpeg-sink-mode=0660"
gpio:
drivers:
@@ -148,8 +150,6 @@ vnc:
enabled: true
memsink:
jpeg:
sink: ""
h264:
sink: ""