Avoid creating log files when no serial device is connected

This commit is contained in:
2026-02-13 02:39:51 +01:00
parent dcc3e2052c
commit 0e765aff55

View File

@@ -158,7 +158,6 @@ class SerialBridge(threading.Thread):
self._log_file.write(f"{ts} {line}\n") self._log_file.write(f"{ts} {line}\n")
def run(self) -> None: def run(self) -> None:
self._open_log()
try: try:
while not self._stop_event.is_set(): while not self._stop_event.is_set():
if self._serial is None: if self._serial is None:
@@ -180,6 +179,7 @@ class SerialBridge(threading.Thread):
except Exception as exc: except Exception as exc:
self.broadcaster.publish(f"[bridge] disconnected: {exc}") self.broadcaster.publish(f"[bridge] disconnected: {exc}")
self._close_serial() self._close_serial()
self._close_log()
time.sleep(2) time.sleep(2)
finally: finally:
self._close_serial() self._close_serial()