fix: use monitor.vcp.set_vcp_feature (monitorcontrol v4 API), fix monitor indices 1+2

This commit is contained in:
Miłosz Matysiak
2026-04-09 10:25:21 +02:00
parent 05a96e29e4
commit 5dcdfa5221
4 changed files with 31 additions and 17 deletions

View File

@@ -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):