Finish writing tests for commands, fix resolution being accidentally set to lower one, improve fixtures - need rewrite

This commit is contained in:
Lorow
2025-12-06 22:42:48 +01:00
parent e2d0981e0e
commit abd10fc61a
6 changed files with 340 additions and 46 deletions

View File

@@ -8,6 +8,7 @@ OPENIRIS_DEVICE = None
class OpenIrisDeviceManager:
def __init__(self):
self._device: OpenIrisDevice | None = None
self.stored_ports = []
self._current_port: str | None = None
def get_device(self, port: str | None = None, config=None) -> OpenIrisDevice:
@@ -22,6 +23,16 @@ class OpenIrisDeviceManager:
if not port and not self._device:
raise ValueError("No device connected yet, provide a port first")
# I'm not sure if I like this approach
# maybe I need to rethink this fixture
current_ports = get_current_ports()
new_port = get_new_port(self.stored_ports, current_ports)
if new_port is not None:
self.stored_ports = current_ports
if not port:
port = new_port
if port and port != self._current_port:
print(f"Port changed from {self._current_port} to {port}, reconnecting...")
self._current_port = port
@@ -46,7 +57,9 @@ def get_current_ports() -> list[str]:
def get_new_port(old_ports, new_ports) -> str:
return list(set(new_ports) - set(old_ports))[0]
if ports_diff := list(set(new_ports) - set(old_ports)):
return ports_diff[0]
return None
class DetectPortChange: