From d03fe7598f9772e29e299d4a77c5c08098ed1d2b Mon Sep 17 00:00:00 2001 From: maziggy Date: Sat, 3 Jan 2026 08:11:55 +0100 Subject: [PATCH] Fixed bug in Spoolman sync --- backend/app/services/spoolman.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/app/services/spoolman.py b/backend/app/services/spoolman.py index 52190e645..14cac485f 100644 --- a/backend/app/services/spoolman.py +++ b/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,