Run KVM switch in background and target DDM by monitor model

This commit is contained in:
Lago
2026-03-27 14:49:28 +01:00
parent 8591e22a7b
commit 33e762c182
5 changed files with 164 additions and 21 deletions
+72
View File
@@ -167,3 +167,75 @@ def test_polling_switches_when_trigger_matches_device_role(monkeypatch: pytest.M
assert status["samsung_session_attempted"] is True
assert status["samsung_session_successful"] is True
assert status["last_switch_result"] == "switched"
def test_polling_switches_with_monitor_targeting_when_slot_is_unavailable(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setenv(DEVICE_ROLE_ENV_VAR, "tower")
service_module = _require_module("app.service")
hardware_module = _require_module("app.hardware")
ddm_module = _require_module("app.ddm")
KvmSwitcherService = getattr(service_module, "KvmSwitcherService", None)
HardwareScan = getattr(hardware_module, "HardwareScan", None)
DDMCommandResult = getattr(ddm_module, "DDMCommandResult", None)
if KvmSwitcherService is None or HardwareScan is None or DDMCommandResult is None:
pytest.skip("Service backend interfaces are not available yet.")
class FakeMonitorBackend:
def __init__(self) -> None:
self.call_count = 0
def scan(self):
self.call_count += 1
if self.call_count == 1:
return HardwareScan(
samsung_present=True,
trigger_input_code=15,
alienware_detected=True,
alienware_input_code=19,
errors=[],
)
return HardwareScan(
samsung_present=True,
trigger_input_code=15,
alienware_detected=True,
alienware_input_code=15,
errors=[],
)
class FakeDDMBackend:
def __init__(self) -> None:
self.calls: list[tuple[int, str]] = []
def is_available(self) -> bool:
return True
def supports_monitor_targeting(self) -> bool:
return True
def resolve_alienware_slot(self, force: bool = False) -> int | None:
return None
def invalidate_slot(self) -> None:
return None
def switch_to_port(self, slot: int, port_name: str):
self.calls.append((slot, port_name))
return DDMCommandResult(True, "ok")
config_path = Path(tempfile.mkdtemp()) / "config.json"
backend = FakeDDMBackend()
service = KvmSwitcherService(
config_store=ConfigStore(config_path),
monitor_backend=FakeMonitorBackend(),
ddm_backend=backend,
poll_interval_seconds=0.01,
retry_wait_seconds=0.0,
)
status = service.save_settings(device_role="tower", device_port="DP1")
assert status["ddm_ready"] is True
assert status["ddm_slot"] is None
assert status["last_switch_result"] == "switched"
assert backend.calls == [(0, "DP1")]