Explorar el Código

Fix H2D print commands and HMS notification issues

Issue #245: H2D Pro print errors (extrusion motor overloaded)
- H2D series requires integer format (0/1) for boolean fields
- Other printers (X1C, P1S, A1) require actual booleans (true/false)
- Added model detection to use correct format per printer type
- Affected fields: timelapse, bed_leveling, flow_cali, vibration_cali,
  layer_inspect, use_ams

Closes #245
maziggy hace 3 meses
padre
commit
87cf0e83e9
Se han modificado 2 ficheros con 13 adiciones y 7 borrados
  1. 13 6
      backend/app/services/bambu_mqtt.py
  2. 0 1
      pyproject.toml

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

@@ -2049,6 +2049,10 @@ class BambuMQTTClient:
                         slot_id = tray_id % 4
                         slot_id = tray_id % 4
                         ams_mapping2.append({"ams_id": ams_id, "slot_id": slot_id})
                         ams_mapping2.append({"ams_id": ams_id, "slot_id": slot_id})
 
 
+            # H2D series requires integer values (0/1) for boolean fields
+            # Other printers (X1C, P1S, A1, etc.) require actual booleans
+            is_h2d = self.model and self.model.upper().strip() in ("H2D", "H2D PRO", "H2DPRO", "H2C", "H2S")
+
             command = {
             command = {
                 "print": {
                 "print": {
                     "sequence_id": "20000",
                     "sequence_id": "20000",
@@ -2058,13 +2062,13 @@ class BambuMQTTClient:
                     "file": filename,
                     "file": filename,
                     "md5": "",
                     "md5": "",
                     "bed_type": "auto",
                     "bed_type": "auto",
-                    "timelapse": 1 if timelapse else 0,
-                    "bed_leveling": 1 if bed_levelling else 0,
+                    "timelapse": (1 if timelapse else 0) if is_h2d else timelapse,
+                    "bed_leveling": (1 if bed_levelling else 0) if is_h2d else bed_levelling,
                     "auto_bed_leveling": 1 if bed_levelling else 0,
                     "auto_bed_leveling": 1 if bed_levelling else 0,
-                    "flow_cali": 1 if flow_cali else 0,
-                    "vibration_cali": 1 if vibration_cali else 0,
-                    "layer_inspect": 1 if layer_inspect else 0,
-                    "use_ams": 1 if use_ams else 0,
+                    "flow_cali": (1 if flow_cali else 0) if is_h2d else flow_cali,
+                    "vibration_cali": (1 if vibration_cali else 0) if is_h2d else vibration_cali,
+                    "layer_inspect": (1 if layer_inspect else 0) if is_h2d else layer_inspect,
+                    "use_ams": (1 if use_ams else 0) if is_h2d else use_ams,
                     "cfg": "0",
                     "cfg": "0",
                     "extrude_cali_flag": 0,
                     "extrude_cali_flag": 0,
                     "extrude_cali_manual_mode": 0,
                     "extrude_cali_manual_mode": 0,
@@ -2077,6 +2081,9 @@ class BambuMQTTClient:
                 }
                 }
             }
             }
 
 
+            if is_h2d:
+                logger.info(f"[{self.serial_number}] H2D series detected: using integer format for boolean fields")
+
             # P2S-specific parameter adjustments
             # P2S-specific parameter adjustments
             # P2S printer doesn't support vibration calibration like X1/P1 series
             # P2S printer doesn't support vibration calibration like X1/P1 series
             if self.model and self.model.upper().strip() in ("P2S", "N7"):
             if self.model and self.model.upper().strip() in ("P2S", "N7"):

+ 0 - 1
pyproject.toml

@@ -38,7 +38,6 @@ ignore = [
     "SIM108", # ternary operator (readability preference)
     "SIM108", # ternary operator (readability preference)
     "SIM102", # nested if (readability preference)
     "SIM102", # nested if (readability preference)
     "SIM105", # contextlib.suppress (readability preference)
     "SIM105", # contextlib.suppress (readability preference)
-    "UP038",  # isinstance tuple syntax (readability preference)
 ]
 ]
 
 
 # Allow autofix for all enabled rules
 # Allow autofix for all enabled rules