Просмотр исходного кода

Fix SpoolBuddy daemon crash when read_tag module is missing

NFCReader.__init__ imported read_tag and instantiated PN5180() outside
the try/except block, so a missing module crashed the entire daemon.
Moved the import inside the existing try/except so the daemon gracefully
skips NFC polling — matching the scale reader's existing behavior.
maziggy 3 месяцев назад
Родитель
Сommit
8f3d194596
2 измененных файлов с 8 добавлено и 4 удалено
  1. 3 0
      CHANGELOG.md
  2. 5 4
      spoolbuddy/daemon/nfc_reader.py

+ 3 - 0
CHANGELOG.md

@@ -8,6 +8,9 @@ All notable changes to Bambuddy will be documented in this file.
 - **SpoolBuddy AMS Page: External Slots & Slot Configuration** — The SpoolBuddy AMS page (`/spoolbuddy/ams`) now displays external spool slots (single nozzle: "Ext", dual nozzle: "Ext-L"/"Ext-R") and AMS-HT units in a compact horizontal row below the regular AMS grid, fitting within the 1024×600 kiosk display without scrolling. Clicking any AMS, AMS-HT, or external slot opens the `ConfigureAmsSlotModal` to configure filament type and color — the same modal used on the main Printers page. Dual-nozzle printers show L/R nozzle badges on each AMS unit. Temperature and humidity are displayed with threshold-colored SVG icons (green/gold/red) matching the Bambu Lab style on the main printer cards, using the configured AMS humidity and temperature thresholds from settings.
 - **SpoolBuddy AMS Page: External Slots & Slot Configuration** — The SpoolBuddy AMS page (`/spoolbuddy/ams`) now displays external spool slots (single nozzle: "Ext", dual nozzle: "Ext-L"/"Ext-R") and AMS-HT units in a compact horizontal row below the regular AMS grid, fitting within the 1024×600 kiosk display without scrolling. Clicking any AMS, AMS-HT, or external slot opens the `ConfigureAmsSlotModal` to configure filament type and color — the same modal used on the main Printers page. Dual-nozzle printers show L/R nozzle badges on each AMS unit. Temperature and humidity are displayed with threshold-colored SVG icons (green/gold/red) matching the Bambu Lab style on the main printer cards, using the configured AMS humidity and temperature thresholds from settings.
 - **SpoolBuddy Dashboard Redesign** — Redesigned the SpoolBuddy dashboard with a two-column layout: left column shows device connection status (scale and NFC with state-colored icons — green when device is online, gray when offline) and a compact printers list with live status indicators; right column shows the current spool card. Cards use a dashed border style for a cleaner look. The large weight display card was removed in favor of the inline scale reading in the device card.
 - **SpoolBuddy Dashboard Redesign** — Redesigned the SpoolBuddy dashboard with a two-column layout: left column shows device connection status (scale and NFC with state-colored icons — green when device is online, gray when offline) and a compact printers list with live status indicators; right column shows the current spool card. Cards use a dashed border style for a cleaner look. The large weight display card was removed in favor of the inline scale reading in the device card.
 
 
+### Fixed
+- **SpoolBuddy Daemon Crashes When NFC Module Not Installed** — The `NFCReader` constructor imported `read_tag` and instantiated `PN5180()` outside the try/except block, so a missing `read_tag` module raised an uncaught `ModuleNotFoundError` that crashed the entire daemon via `asyncio.gather`. The scale reader already handled its missing module gracefully. Moved the import and instantiation inside the existing try/except so a missing NFC driver sets `ok=False` and the daemon logs "NFC reader not available" and continues running the scale and heartbeat loops.
+
 ### Improved
 ### Improved
 - **SpoolBuddy Scale Value Stabilization** — The SpoolBuddy daemon now suppresses redundant scale weight reports: only sends updates when the weight changes by ≥2g or the stability state flips (stable ↔ unstable). Previously every 1-second report interval sent a reading regardless of change, causing the dashboard weight display to bounce continuously. The frontend also applies a 3g display threshold as defense-in-depth.
 - **SpoolBuddy Scale Value Stabilization** — The SpoolBuddy daemon now suppresses redundant scale weight reports: only sends updates when the weight changes by ≥2g or the stability state flips (stable ↔ unstable). Previously every 1-second report interval sent a reading regardless of change, causing the dashboard weight display to bounce continuously. The frontend also applies a 3g display threshold as defense-in-depth.
 - **SpoolBuddy TopBar: Online Printer Selection** — The printer selector in the SpoolBuddy top bar now only shows online printers and auto-selects the first online printer. If the currently selected printer goes offline, it automatically switches to the next available online printer. Also replaced the placeholder icon with the SpoolBuddy logo.
 - **SpoolBuddy TopBar: Online Printer Selection** — The printer selector in the SpoolBuddy top bar now only shows online printers and auto-selects the first online printer. If the currently selected printer goes offline, it automatically switches to the next available online printer. Also replaced the placeholder icon with the SpoolBuddy logo.

+ 5 - 4
spoolbuddy/daemon/nfc_reader.py

@@ -16,9 +16,7 @@ class NFCState(Enum):
 
 
 class NFCReader:
 class NFCReader:
     def __init__(self):
     def __init__(self):
-        from read_tag import PN5180
-
-        self._nfc = PN5180()
+        self._nfc = None
         self._state = NFCState.IDLE
         self._state = NFCState.IDLE
         self._current_uid: str | None = None
         self._current_uid: str | None = None
         self._current_sak: int | None = None
         self._current_sak: int | None = None
@@ -26,6 +24,9 @@ class NFCReader:
         self._ok = False
         self._ok = False
 
 
         try:
         try:
+            from read_tag import PN5180
+
+            self._nfc = PN5180()
             self._nfc.reset()
             self._nfc.reset()
             self._nfc.load_rf_config(0x00, 0x80)
             self._nfc.load_rf_config(0x00, 0x80)
             time.sleep(0.010)
             time.sleep(0.010)
@@ -35,7 +36,7 @@ class NFCReader:
             self._ok = True
             self._ok = True
             logger.info("NFC reader initialized")
             logger.info("NFC reader initialized")
         except Exception as e:
         except Exception as e:
-            logger.error("NFC reader init failed: %s", e)
+            logger.error("NFC init failed: %s", e)
 
 
     @property
     @property
     def ok(self) -> bool:
     def ok(self) -> bool: