fix: Move lines=[] above lock in _read_cb() (Issue #683)

UnboundLocalError when _ser is None — lines was only assigned inside
the else branch. Move initialisation to function scope so the for-loop
outside the lock always has a valid list.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sl-firmware 2026-03-17 22:36:20 -04:00
parent 5e82878083
commit 05ba557dca

View File

@ -154,12 +154,12 @@ class SaltybotCmdNode(Node):
# ── RX — telemetry read ─────────────────────────────────────────────────── # ── RX — telemetry read ───────────────────────────────────────────────────
def _read_cb(self): def _read_cb(self):
lines = []
with self._ser_lock: with self._ser_lock:
if self._ser is None or not self._ser.is_open: if self._ser is None or not self._ser.is_open:
pass pass
else: else:
try: try:
lines = []
while self._ser.in_waiting: while self._ser.in_waiting:
raw = self._ser.readline() raw = self._ser.readline()
if raw: if raw: