diff --git a/config/config.json b/config/config.json index da70d99..ba39632 100644 --- a/config/config.json +++ b/config/config.json @@ -6,8 +6,14 @@ "name": "PC1 — DP", "hotkey": "ctrl+alt+1", "monitor_inputs": [ - {"monitor_index": 0, "vcp_value": 15}, - {"monitor_index": 1, "vcp_value": 15} + { + "monitor_index": 1, + "vcp_value": 15 + }, + { + "monitor_index": 2, + "vcp_value": 15 + } ] }, { @@ -15,8 +21,14 @@ "name": "PC2 — HDMI", "hotkey": "ctrl+alt+2", "monitor_inputs": [ - {"monitor_index": 0, "vcp_value": 17}, - {"monitor_index": 1, "vcp_value": 17} + { + "monitor_index": 1, + "vcp_value": 17 + }, + { + "monitor_index": 2, + "vcp_value": 17 + } ] } ], @@ -41,4 +53,4 @@ "minimize_to_tray": true, "debounce_ms": 500 } -} +} \ No newline at end of file diff --git a/core/switcher.py b/core/switcher.py index 771bcf5..c869518 100644 --- a/core/switcher.py +++ b/core/switcher.py @@ -29,7 +29,7 @@ class MonitorSwitcher: continue try: with monitors[idx] as monitor: - monitor.set_vcp_feature(VCP_INPUT_SOURCE, vcp_value) + monitor.vcp.set_vcp_feature(VCP_INPUT_SOURCE, vcp_value) logger.info("Monitor %d -> VCP input %d", idx, vcp_value) except Exception as exc: logger.warning("Monitor %d DDC/CI error: %s", idx, exc) @@ -46,8 +46,8 @@ class MonitorSwitcher: for idx, monitor_handle in enumerate(get_monitors()): try: with monitor_handle as monitor: - current = monitor.get_vcp_feature(VCP_INPUT_SOURCE) - result.append({"index": idx, "current_vcp": current.value}) + current = monitor.vcp.get_vcp_feature(VCP_INPUT_SOURCE) + result.append({"index": idx, "current_vcp": current[0]}) except Exception as exc: logger.warning("Cannot query monitor %d: %s", idx, exc) result.append({"index": idx, "current_vcp": None}) diff --git a/detect_vcp.py b/detect_vcp.py index aae88bc..2562748 100644 --- a/detect_vcp.py +++ b/detect_vcp.py @@ -10,8 +10,9 @@ print("Skanowanie monitorow (VCP code 0x60 - Input Source)...") for i, handle in enumerate(get_monitors()): with handle as monitor: try: - current = monitor.get_vcp_feature(VCP_INPUT_SOURCE) - print(f" Monitor {i}: VCP input = {current.value} (0x{current.value:02X})") + current = monitor.vcp.get_vcp_feature(VCP_INPUT_SOURCE) + val = current[0] + print(f" Monitor {i}: VCP input = {val} (0x{val:02X})") except Exception as e: print(f" Monitor {i}: blad odczytu - {e}") print() diff --git a/tests/test_switcher.py b/tests/test_switcher.py index 1d82a77..3f90a4d 100644 --- a/tests/test_switcher.py +++ b/tests/test_switcher.py @@ -13,6 +13,7 @@ def _make_mock_monitor(): m = MagicMock() m.__enter__ = MagicMock(return_value=m) m.__exit__ = MagicMock(return_value=False) + m.vcp = MagicMock() return m @@ -24,8 +25,8 @@ def test_apply_profile_sends_vcp_to_both_monitors(config): sw = MonitorSwitcher(config) sw.apply_profile("pc1_dp") - mon0.set_vcp_feature.assert_called_once_with(0x60, 15) - mon1.set_vcp_feature.assert_called_once_with(0x60, 15) + mon0.vcp.set_vcp_feature.assert_called_once_with(0x60, 15) + mon1.vcp.set_vcp_feature.assert_called_once_with(0x60, 15) def test_apply_profile_hdmi(config): @@ -36,8 +37,8 @@ def test_apply_profile_hdmi(config): sw = MonitorSwitcher(config) sw.apply_profile("pc2_hdmi") - mon0.set_vcp_feature.assert_called_once_with(0x60, 17) - mon1.set_vcp_feature.assert_called_once_with(0x60, 17) + mon0.vcp.set_vcp_feature.assert_called_once_with(0x60, 17) + mon1.vcp.set_vcp_feature.assert_called_once_with(0x60, 17) def test_apply_profile_skips_missing_monitor(config): @@ -47,19 +48,19 @@ def test_apply_profile_skips_missing_monitor(config): sw = MonitorSwitcher(config) sw.apply_profile("pc1_dp") - mon0.set_vcp_feature.assert_called_once_with(0x60, 15) + mon0.vcp.set_vcp_feature.assert_called_once_with(0x60, 15) def test_apply_profile_continues_on_monitor_error(config): mon0 = _make_mock_monitor() mon1 = _make_mock_monitor() - mon0.set_vcp_feature.side_effect = Exception("DDC/CI error") + mon0.vcp.set_vcp_feature.side_effect = Exception("DDC/CI error") with patch("core.switcher.get_monitors", return_value=[mon0, mon1]): sw = MonitorSwitcher(config) sw.apply_profile("pc1_dp") - mon1.set_vcp_feature.assert_called_once_with(0x60, 15) + mon1.vcp.set_vcp_feature.assert_called_once_with(0x60, 15) def test_apply_profile_unknown_profile_does_nothing(config):