async def test_maintain_serial_devices_no_devs( ovshell: testing.OpenVarioShellStub, serial_testbed: SerialTestbed ) -> None: # GIVEN maintainer = serial.maintain_serial_devices(ovshell) async with task_started(maintainer): # WHEN await asyncio.sleep(0) # THEN # No devices registered assert len(ovshell.devices.list()) == 0
def start(self) -> None: self.shell.processes.start(serial.maintain_serial_devices(self.shell)) gpsstate = gpstime.GPSTimeState() self.shell.processes.start(gpstime.gps_time_sync(self.shell, gpsstate)) self.shell.processes.start(gpstime.clock_indicator(self.shell.screen, gpsstate)) simfile = os.environ.get("OVSHELL_CORE_SIMULATE_DEVICE") if simfile: devsim.run_simulated_device(self.shell, simfile) self.shell.processes.start(devindicators.show_device_indicators(self.shell))
async def test_maintain_serial_devices_bad_device( ovshell: testing.OpenVarioShellStub, serial_testbed: SerialTestbed ) -> None: # GIVEN serial_testbed.lookup.stub_set_devices(["/dev/ttyFAKE"]) serial_testbed.serial_opener.open_raises = SerialException("File not found") maintainer = serial.maintain_serial_devices(ovshell) async with task_started(maintainer): # WHEN await asyncio.sleep(0.01) # THEN # No devices registered assert len(ovshell.devices.list()) == 0
async def test_maintain_serial_devices_opened( ovshell: testing.OpenVarioShellStub, serial_testbed: SerialTestbed ) -> None: serial_testbed.lookup.stub_set_devices(["/dev/ttyFAKE"]) maintainer = serial.maintain_serial_devices(ovshell) async with task_started(maintainer): # WHEN await asyncio.sleep(0.01) # THEN # One device registered devs = ovshell.devices.list() assert len(devs) == 1 dev = devs[0] assert isinstance(dev, serial.SerialDeviceImpl) assert dev.id == "/dev/ttyFAKE" assert dev.name == "ttyFAKE" assert dev.path == "/dev/ttyFAKE" assert dev.baudrate == 9600
async def test_maintain_serial_devices_reconnect( ovshell: testing.OpenVarioShellStub, serial_testbed: SerialTestbed) -> None: serial_testbed.lookup.stub_set_devices(["/dev/ttyFAKE"]) maintainer = serial.maintain_serial_devices(ovshell) async with task_started(maintainer): # Device is detected await asyncio.sleep(0.02) assert len(ovshell.devices.list()) == 1 # ttyFAKE is gone ovshell.devices.stub_remove_device("/dev/ttyFAKE") assert len(ovshell.devices.list()) == 0 serial_testbed.lookup.stub_set_devices([]) await asyncio.sleep(0.02) # ttyFAKE reappears serial_testbed.lookup.stub_set_devices(["/dev/ttyFAKE"]) await asyncio.sleep(0.02) assert len(ovshell.devices.list()) == 1
def start(self) -> None: self.shell.processes.start(serial.maintain_serial_devices(self.shell)) self.shell.processes.start(gpstime.gps_time_sync(self.shell))
def start(self) -> None: devlookup = serial.SerialDeviceLookupImpl() self.shell.processes.start( serial.maintain_serial_devices(self.shell, devlookup))