Przeglądaj źródła

Fix ethernet badge false positive and MQTT thread crash (#585)

    Three bugs: (1) home_flag bit 18 is set on all printers regardless
    of connection type, so every ethernet-capable model showed the badge
    even on WiFi. Replaced with wifi_signal heuristic — ethernet printers
    with WiFi disabled report a hardcoded -90 dBm sentinel. (2) The lazy
    import used `from app.utils.printer_models` which crashes with
    ModuleNotFoundError in paho-mqtt's background thread (correct path:
    backend.app.utils.printer_models). This killed the thread, causing
    all printers to go stale after 60s and disconnect/reconnect in a
    loop. (3) WiFi-only models excluded via model-based gating.
maziggy 2 miesięcy temu
rodzic
commit
374895f959
2 zmienionych plików z 15 dodań i 7 usunięć
  1. 1 1
      CHANGELOG.md
  2. 14 6
      backend/app/services/bambu_mqtt.py

+ 1 - 1
CHANGELOG.md

@@ -30,7 +30,7 @@ All notable changes to Bambuddy will be documented in this file.
 - **Bed Cooled Notification Never Fires** ([#497](https://github.com/maziggy/bambuddy/issues/497)) — The bed cooldown monitor always timed out after 30 minutes without sending a notification. After print completion, P1S (and likely other models) sends partial MQTT status updates that don't include `bed_temper`, so the cached bed temperature stayed frozen at the end-of-print value and never dropped below the threshold. The monitor now sends periodic `pushall` commands to the printer to force fresh temperature data. Also added debug logging to the polling loop for future diagnostics.
 - **Notification Provider Missing Event Toggles on Create** ([#497](https://github.com/maziggy/bambuddy/issues/497)) — When creating a new notification provider, the `on_bed_cooled` toggle and all 7 queue event toggles (`on_queue_job_added`, `on_queue_job_assigned`, `on_queue_job_started`, `on_queue_job_waiting`, `on_queue_job_skipped`, `on_queue_job_failed`, `on_queue_completed`) were silently discarded. The create endpoint manually listed each field but omitted these 8 toggles, so they always defaulted to `false` regardless of user selection. Editing an existing provider worked correctly.
 - **Clear Plate Prompt Shown for Staged Queue Items** — The "Clear Plate & Start Next" button on the printer card appeared when all pending queue items were staged (`manual_start`/Queue Only), even though the scheduler won't auto-start them. The clear plate prompt now only appears when there are auto-dispatchable items that the scheduler will actually start after the plate is cleared.
-- **Ethernet Badge Shown on WiFi-Only Printers** ([#585](https://github.com/maziggy/bambuddy/issues/585)) — The ethernet badge was shown on all printer models, including WiFi-only models like A1 and P1P that don't have an ethernet port. The `home_flag` bit 18 is set on all printers regardless of hardware. Now only parses the ethernet flag on models that actually have an ethernet port (X1C, X1E, P1S, P2S, H2D, H2D Pro, H2C, H2S). Printers connected via ethernet show an "Ethernet" badge; all others show the WiFi signal indicator.
+- **Ethernet Badge Shown on WiFi Printers / MQTT Disconnecting** ([#585](https://github.com/maziggy/bambuddy/issues/585)) — Three bugs in the ethernet badge feature: (1) `home_flag` bit 18 is set on all printers regardless of connection type, so every ethernet-capable model showed the ethernet badge even when connected via WiFi. Replaced bit 18 detection with wifi_signal-based heuristic: printers on ethernet with WiFi disabled report a hardcoded `-90 dBm` sentinel, while real WiFi signals vary. (2) The lazy import used `from app.utils.printer_models` which crashes with `ModuleNotFoundError` in paho-mqtt's background thread (correct path is `backend.app.utils.printer_models`). This killed the MQTT thread entirely, causing all printers to go stale after 60s and repeatedly disconnect/reconnect. (3) WiFi-only models (A1, P1P, etc.) that don't have an ethernet port are excluded via model-based gating. Reported by @cadtoolbox.
 - **GitHub Backup Required Cloud Login** ([#655](https://github.com/maziggy/bambuddy/issues/655)) — The GitHub backup settings card was completely blocked behind Bambu Cloud authentication, showing "Bambu Cloud login required" even though the backup feature works without it (K-profiles and app settings don't need cloud). Removed the cloud auth gate so GitHub backup can be configured and used without Bambu Cloud. The "Cloud Profiles" checkbox is disabled with a hint when not logged in. Reported by @TravisWilder.
 - **GitHub Backup Log Timestamps Off by 1 Hour** — Backup log timestamps in the history table were displayed in UTC instead of the user's local timezone. The local `formatDateTime` function didn't use `parseUTCDate`, so timezone-less timestamps from SQLite were interpreted as local time. Now uses the shared `parseUTCDate` utility for correct UTC-to-local conversion.
 - **H2D AMS Units Shown on Wrong Nozzle** ([#659](https://github.com/maziggy/bambuddy/issues/659)) — On the H2D dual-nozzle printer, AMS units were displayed on the wrong nozzle (e.g. both AMS-HT and AMS2 Pro shown on the left nozzle instead of their correct assignments). Three interrelated bugs in the AMS `info` field parsing: (1) the field was parsed as decimal instead of hexadecimal (BambuStudio uses `std::stoull(str, nullptr, 16)`), (2) the extruder ID was extracted as a single bit instead of a 4-bit field, and (3) partial MQTT updates overwrote the full extruder map instead of merging. Now correctly hex-parses the `info` field, extracts the 4-bit extruder ID from bits 8-11, skips uninitialized AMS units (`0xE`), and merges partial updates into the existing map. Reported by @cadtoolbox.

+ 14 - 6
backend/app/services/bambu_mqtt.py

@@ -556,6 +556,12 @@ class BambuMQTTClient:
                 except ValueError:
                     pass  # Ignore unparseable wifi_signal strings; field is non-critical
 
+            # Detect ethernet: wifi_signal == -90 is a sentinel for "WiFi disabled/ethernet"
+            from backend.app.utils.printer_models import has_ethernet
+
+            if has_ethernet(self.model):
+                self.state.wired_network = self.state.wifi_signal == -90
+
         # Parse developer LAN mode from top-level "fun" field
         # Some firmware versions send "fun" at the top level, others inside "print"
         if "fun" in payload and self.state.developer_mode is None:
@@ -2077,12 +2083,6 @@ class BambuMQTTClient:
                     f"[{self.serial_number}] store_to_sdcard changed: {self.state.store_to_sdcard} -> {store_to_sdcard}"
                 )
             self.state.store_to_sdcard = store_to_sdcard
-            # Bit 18 (0x00040000) indicates wired/ethernet connection
-            # Only trust this on models that actually have an ethernet port
-            from app.utils.printer_models import has_ethernet
-
-            if has_ethernet(self.model):
-                self.state.wired_network = bool((home_flag >> 18) & 1)
 
         # Parse timelapse status (recording active during print)
         if "timelapse" in data:
@@ -2127,6 +2127,14 @@ class BambuMQTTClient:
                 except ValueError:
                     pass  # Ignore unparseable wifi_signal strings; field is non-critical
 
+            # Detect ethernet connection: printers on ethernet with WiFi disabled
+            # report a hardcoded wifi_signal of -90 dBm. Real WiFi signals vary
+            # (typically -30 to -80 dBm). Only check models with an ethernet port.
+            from backend.app.utils.printer_models import has_ethernet
+
+            if has_ethernet(self.model):
+                self.state.wired_network = self.state.wifi_signal == -90
+
         # Parse print speed level (1=silent, 2=standard, 3=sport, 4=ludicrous)
         if "spd_lvl" in data:
             new_speed = data["spd_lvl"]