Browse Source

Fixed bug in Spoolman sync

maziggy 4 months ago
parent
commit
d03fe7598f
1 changed files with 15 additions and 5 deletions
  1. 15 5
      backend/app/services/spoolman.py

+ 15 - 5
backend/app/services/spoolman.py

@@ -602,17 +602,28 @@ class SpoolmanClient:
     async def _find_or_create_filament(self, tray: AMSTray) -> dict | None:
         """Find existing filament or create new one.
 
+        Only matches Bambu Lab vendor filaments since this is called for
+        Bambu Lab spools. Third-party filaments (like 3DJAKE) are ignored
+        to prevent incorrect matching by color alone.
+
         Args:
             tray: The AMSTray containing filament info
 
         Returns:
             Filament dictionary or None on failure.
         """
-        # Search internal filaments first
-        filaments = await self.get_filaments()
+        # Get Bambu Lab vendor ID for filtering
+        bambu_vendor_id = await self.ensure_bambu_vendor()
         color_hex = tray.tray_color[:6]  # Strip alpha channel
 
+        # Search internal filaments - only match Bambu Lab vendor
+        filaments = await self.get_filaments()
         for filament in filaments:
+            # Only match filaments from Bambu Lab vendor
+            fil_vendor_id = filament.get("vendor_id") or filament.get("vendor", {}).get("id")
+            if fil_vendor_id != bambu_vendor_id:
+                continue
+
             # Match by material and color (handle None values)
             fil_material = filament.get("material") or ""
             fil_color = filament.get("color_hex") or ""
@@ -628,11 +639,10 @@ class SpoolmanClient:
                 # Found in external library - need to create internal copy
                 return await self._create_filament_from_external(filament, tray)
 
-        # Not found - create new filament
-        vendor_id = await self.ensure_bambu_vendor()
+        # Not found - create new Bambu Lab filament
         return await self.create_filament(
             name=tray.tray_sub_brands or tray.tray_type,
-            vendor_id=vendor_id,
+            vendor_id=bambu_vendor_id,
             material=tray.tray_type,
             color_hex=color_hex,
             weight=tray.tray_weight,