Browse Source

Fan control: H2 series and H3C confirm the exhaust fan too (#3521)

- The backend's EXHAUST_FAN_LABEL_MODELS missed the H2 series and the
  H3C, so the set-fan confirmation still said "Chamber fan" while the
  card said "Exhaust". Added their display names and model codes; the
  lookup compares without spaces so "H2D Pro" matches.
- Tests for the new models; the H2D now expects "Exhaust fan".
maziggy 1 week ago
parent
commit
d3fed72805

+ 1 - 1
CHANGELOG.md

@@ -27,7 +27,7 @@ All notable changes to Bambuddy will be documented in this file.
 - **"Any model" jobs go to the printer with the fewest print hours (#3480, sponsor vote Q4 2026)** — When several printers of a model can take a job, the queue used to pick the first one in its list, so on a farm the same printer got most of the work. It now picks the one with the fewest print hours (the Maintenance counter, including baseline hours entered there), so jobs and wear spread across the farm. Preferred colours still come first, and the queue powers on the least used printer too when it has to switch one on with an Auto Power On plug.
 
 ### Fixed
-- **The H2 series' and the H3C's exhaust fan is labelled Exhaust (#3521, reported by @Spegeli)** — The printer card called fan 3 "Chamber Fan" on the H2D, H2D Pro, H2C, H2S and H3C. On these printers it is the exhaust fan in the back wall, which Bambu Studio names "Exhaust", as on the P2S and X2D. Only the X1 series and P1S call it the chamber fan. The badge is still always shown on these printers, since the fan is built in.
+- **The H2 series' and the H3C's exhaust fan is labelled Exhaust (#3521, reported by @Spegeli)** — The printer card called fan 3 "Chamber Fan" on the H2D, H2D Pro, H2C, H2S and H3C. On these printers it is the exhaust fan in the back wall, which Bambu Studio names "Exhaust", as on the P2S and X2D. Only the X1 series and P1S call it the chamber fan. The badge is still always shown on these printers, since the fan is built in, and the confirmation after setting the fan names it the exhaust fan too.
 - **Spools keep their ids when the inventory moves by CSV (#3520, reported by @hurr1k4ne)** — The CSV export had no id column, so importing it on another instance numbered the spools anew, in the order of the file, and every printed label, whose QR code carries the spool's id, found the wrong spool or none. The export now writes each spool's id, and the import keeps it when that instance has never used it, which on a fresh instance is every id. An id already used there, also by a deleted spool, or named twice in the file gets a new one, and the preview says how many. The preview shows the id each spool keeps. A CSV without the column imports as before.
 - **A spool with a custom cloud preset gets it from a SpoolBuddy client too (#3519, reported by @pleasantone)** — With login on, each user signs in to Bambu Cloud separately. Assigning a spool from an API key, as a SpoolBuddy client does, had no signed-in user, so its custom preset (PFUS or PFCN) could not be looked up and the slot got Generic PLA, while the same assign from the web UI got the preset's own filament. Configuring a pre-assigned slot when the spool is inserted had the same problem, even for assignments made in the web UI. Both now use a user's sign-in: the API key's owner, and whoever made the assignment. A custom preset that still can't be looked up is now named in the log.
 - **Closing a camera view no longer leaves a CPU core at 100% (#3515, reported by @BrainDeLook)** — A viewer leaving while its stream was reading from the SQLite database could leave that connection's close waiting forever, on a bug in aiosqlite (omnilib/aiosqlite#403). Bambuddy then kept one CPU core fully busy, even with every viewer closed, and other pages such as Projects and Spool Inventory became very slow until a restart. Bambuddy now works around the aiosqlite bug, for every database connection, not only the camera's, and the camera stream's short reads (the chamber light settings and the periodic access check) finish before a leaving viewer ends the stream. PostgreSQL was not affected.

+ 29 - 14
backend/app/utils/printer_models.py

@@ -282,34 +282,53 @@ NOZZLE_RACK_MODELS = frozenset(
 )
 
 
-# Models where Bambu's own firmware/UI names the enclosure fan (big_fan2 /
-# airduct part id 3) "Exhaust" rather than "Chamber". On these the printer's
-# touchscreen and Bambu Studio both call it the exhaust fan, and on the P2S it
-# is an add-on kit rather than built-in hardware. Other enclosed models
-# (X1 / P1S / H2 series) keep the "Chamber" naming.
+# Models where Bambu names the enclosure fan (big_fan2 / airduct part id 3)
+# "Exhaust" rather than "Chamber". Bambu Studio calls part 3 "Exhaust" unless a
+# printer's file renames it, and only the X1 Carbon, X1, X1E and P1S files
+# rename it to "Chamber". On the P2S it is an add-on kit rather than built-in
+# hardware. The H2 series and the H3C were missing (#3521). Must match
+# MODELS_WITH_EXHAUST_LABEL in frontend PrintersPage.tsx (a test checks).
 EXHAUST_FAN_LABEL_MODELS = frozenset(
     [
-        # Display names (uppercase, no spaces)
+        # Display names, as the printer card spells them
         "P2S",
         "X2D",
+        "H2D",
+        "H2D Pro",
+        "H2C",
+        "H2S",
+        "H3C",
         # Internal codes
         "N7",  # P2S
         "N6",  # X2D
+        "O1D",  # H2D
+        "O1E",  # H2D Pro
+        "O2D",  # H2D Pro
+        "O1C",  # H2C
+        "O1C2",  # H2C
+        "O1S",  # H2S
+        "N10",  # H3C
     ]
 )
 
 
+def _model_key(model: str | None) -> str:
+    return model.strip().upper().replace(" ", "").replace("-", "") if isinstance(model, str) else ""
+
+
+_EXHAUST_FAN_LABEL_KEYS = frozenset(_model_key(m) for m in EXHAUST_FAN_LABEL_MODELS)
+
+
 def uses_exhaust_fan_label(model: str | None) -> bool:
     """Return True if this model calls the big_fan2 enclosure fan "Exhaust".
 
-    P2S/X2D name that fan "Exhaust" in Bambu's firmware/UI; everything else
-    enclosed calls it the chamber fan. Used so the UI badge and the API
+    The models in EXHAUST_FAN_LABEL_MODELS name that fan "Exhaust"; the X1
+    series and P1S call it the chamber fan. Used so the UI badge and the API
     response message agree on what the user sees.
     """
     if not model:
         return False
-    normalized = model.strip().upper().replace(" ", "").replace("-", "")
-    return normalized in EXHAUST_FAN_LABEL_MODELS
+    return _model_key(model) in _EXHAUST_FAN_LABEL_KEYS
 
 
 # Models whose airduct part 10 is the RIGHT auxiliary fan and part 2 the left
@@ -397,10 +416,6 @@ PROGRESS_INCLUDES_START_SEQUENCE_MODELS = frozenset(["H3C", "N10"])
 AMS3H_MODELS = frozenset(["H3C", "N10"])
 
 
-def _model_key(model: str | None) -> str:
-    return model.strip().upper().replace(" ", "").replace("-", "") if isinstance(model, str) else ""
-
-
 def progress_includes_start_sequence(model: str | None) -> bool:
     """True when the printer's progress percent counts its start sequence (H3C)."""
     return _model_key(model) in PROGRESS_INCLUDES_START_SEQUENCE_MODELS

+ 2 - 1
backend/tests/integration/test_printers_api.py

@@ -4919,7 +4919,8 @@ class TestSetFanSpeedAPI:
             ("X2D", "Exhaust fan"),
             ("X1C", "Chamber fan"),
             ("P1S", "Chamber fan"),
-            ("H2D", "Chamber fan"),
+            ("H2D", "Exhaust fan"),
+            ("H3C", "Exhaust fan"),
         ],
     )
     async def test_chamber_fan_message_matches_model_label(

+ 26 - 5
backend/tests/unit/services/test_p2s_accessory_fans.py

@@ -314,10 +314,31 @@ class TestExhaustFanLabelModels:
         for model in ("P2S", "X2D", "p2s", " P2S ", "N7", "N6"):
             assert uses_exhaust_fan_label(model) is True, model
 
+    def test_h2_series_and_h3c_use_exhaust_label(self):
+        """Bambu Studio doesn't rename their part 3, so it is "Exhaust" (#3521)."""
+        from backend.app.utils.printer_models import uses_exhaust_fan_label
+
+        for model in (
+            "H2D",
+            "H2D Pro",
+            "H2DPRO",
+            "H2C",
+            "H2S",
+            "H3C",
+            "O1D",
+            "O1E",
+            "O2D",
+            "O1C",
+            "O1C2",
+            "O1S",
+            "N10",
+        ):
+            assert uses_exhaust_fan_label(model) is True, model
+
     def test_other_enclosed_models_keep_chamber_label(self):
         from backend.app.utils.printer_models import uses_exhaust_fan_label
 
-        for model in ("X1C", "X1", "X1E", "P1S", "H2D", "H2C", "H2S", "A1"):
+        for model in ("X1C", "X1", "X1E", "P1S", "A1"):
             assert uses_exhaust_fan_label(model) is False, model
 
     def test_unknown_or_missing_model_defaults_to_chamber(self):
@@ -331,8 +352,8 @@ class TestExhaustFanLabelModels:
 class TestExhaustLabelModelListsAgree:
     """The exhaust-label model list is duplicated across the stack.
 
-    The backend keeps ``EXHAUST_FAN_LABEL_MODELS`` (display names plus the N7/N6
-    internal codes, since the API can be handed either) and the frontend keeps
+    The backend keeps ``EXHAUST_FAN_LABEL_MODELS`` (display names plus the internal
+    codes, since the API can be handed either) and the frontend keeps
     ``MODELS_WITH_EXHAUST_LABEL`` in PrintersPage.tsx (display names only —
     ``printer.model`` is always a display name by the time it reaches the card).
     Both are correct as written, but nothing stopped them drifting apart: adding
@@ -378,8 +399,8 @@ class TestExhaustLabelModelListsAgree:
     def test_every_backend_display_name_is_handled_by_the_frontend(self):
         from backend.app.utils.printer_models import EXHAUST_FAN_LABEL_MODELS
 
-        # N7/N6 are internal codes that never reach the card, so exclude them.
-        internal_codes = {"N7", "N6"}
+        # Internal codes never reach the card, so exclude them.
+        internal_codes = {"N7", "N6", "O1D", "O1E", "O2D", "O1C", "O1C2", "O1S", "N10"}
         backend_display = set(EXHAUST_FAN_LABEL_MODELS) - internal_codes
         missing = backend_display - self._frontend_models()
         assert not missing, (