mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-21 10:15:04 +02:00
Fix AMS slot auto-config falling back to Generic instead of spool's slicer preset
Two bugs caused spool assignments to always configure AMS slots with generic Bambu filament IDs (e.g. GFB99 "Generic ABS") instead of the spool's actual slicer preset: 1. PFUS* IDs (cloud-synced custom presets) were blanket-rejected and replaced with generic IDs in both assign_spool and configure_ams_slot 2. Generic fallback IDs (GFB99, GFL99, etc.) were treated as "good" presets by the slot-reuse logic, making them sticky once set New priority: spool's own slicer_filament > slot's non-generic preset (same material) > generic fallback.
This commit is contained in:
@@ -733,14 +733,34 @@ async def assign_spool(
|
||||
|
||||
# Resolve tray_info_idx for the MQTT command.
|
||||
# Priority:
|
||||
# 1. Reuse the slot's existing tray_info_idx if it's a recognised
|
||||
# preset (GF*/P*) for the same material — this preserves the
|
||||
# slicer's K-profile association.
|
||||
# 2. Replace PFUS* (user-local IDs unknown to other slicers) and
|
||||
# empty IDs with a generic Bambu filament ID.
|
||||
if (
|
||||
# 1. Use the spool's own slicer_filament if set (including
|
||||
# cloud-synced custom presets like PFUS* / P*).
|
||||
# 2. Reuse the slot's existing tray_info_idx if it's a specific
|
||||
# (non-generic) preset for the same material.
|
||||
# 3. Fall back to a generic Bambu filament ID.
|
||||
_GENERIC_IDS = {
|
||||
"PLA": "GFL99",
|
||||
"PETG": "GFG99",
|
||||
"ABS": "GFB99",
|
||||
"ASA": "GFB98",
|
||||
"PC": "GFC99",
|
||||
"PA": "GFN99",
|
||||
"NYLON": "GFN99",
|
||||
"TPU": "GFU99",
|
||||
"PVA": "GFS99",
|
||||
"HIPS": "GFS98",
|
||||
"PLA-CF": "GFL98",
|
||||
"PETG-CF": "GFG98",
|
||||
"PA-CF": "GFN98",
|
||||
"PETG HF": "GFG96",
|
||||
}
|
||||
_GENERIC_ID_VALUES = set(_GENERIC_IDS.values())
|
||||
|
||||
if tray_info_idx:
|
||||
logger.info("Spool assign: using spool's slicer_filament=%r", tray_info_idx)
|
||||
elif (
|
||||
current_tray_info_idx
|
||||
and not current_tray_info_idx.startswith("PFUS")
|
||||
and current_tray_info_idx not in _GENERIC_ID_VALUES
|
||||
and fingerprint_type
|
||||
and fingerprint_type.upper() == tray_type.upper()
|
||||
):
|
||||
@@ -750,27 +770,11 @@ async def assign_spool(
|
||||
tray_type,
|
||||
)
|
||||
tray_info_idx = current_tray_info_idx
|
||||
elif (not tray_info_idx or tray_info_idx.startswith("PFUS")) and tray_type:
|
||||
_GENERIC_IDS = {
|
||||
"PLA": "GFL99",
|
||||
"PETG": "GFG99",
|
||||
"ABS": "GFB99",
|
||||
"ASA": "GFB98",
|
||||
"PC": "GFC99",
|
||||
"PA": "GFN99",
|
||||
"NYLON": "GFN99",
|
||||
"TPU": "GFU99",
|
||||
"PVA": "GFS99",
|
||||
"HIPS": "GFS98",
|
||||
"PLA-CF": "GFL98",
|
||||
"PETG-CF": "GFG98",
|
||||
"PA-CF": "GFN98",
|
||||
"PETG HF": "GFG96",
|
||||
}
|
||||
elif tray_type:
|
||||
material = tray_type.upper().strip()
|
||||
generic = _GENERIC_IDS.get(material) or _GENERIC_IDS.get(material.split("-")[0].split(" ")[0]) or ""
|
||||
if generic:
|
||||
logger.info("Spool assign: replacing %r with generic %r", tray_info_idx, generic)
|
||||
logger.info("Spool assign: falling back to generic %r for material %r", generic, tray_type)
|
||||
tray_info_idx = generic
|
||||
|
||||
# Temperature: use spool overrides if set, else material defaults
|
||||
|
||||
@@ -1667,13 +1667,12 @@ async def configure_ams_slot(
|
||||
raise HTTPException(status_code=400, detail="Printer not connected")
|
||||
|
||||
# Resolve tray_info_idx for the MQTT command.
|
||||
# PFUS* IDs are user-local preset IDs that only the originating slicer
|
||||
# recognises. When Bambuddy sends them, BambuStudio sees an unknown
|
||||
# filament and actively resets the slot to empty.
|
||||
# Priority:
|
||||
# 1. If the slot already has a recognised preset (GF*/P*) for the same
|
||||
# material, reuse it — preserves slicer's K-profile association.
|
||||
# 2. Replace PFUS* / empty with a generic Bambu filament ID.
|
||||
# 1. Use the provided tray_info_idx if set (including cloud-synced
|
||||
# custom presets like PFUS* / P*).
|
||||
# 2. Reuse the slot's existing tray_info_idx if it's a specific
|
||||
# (non-generic) preset for the same material.
|
||||
# 3. Fall back to a generic Bambu filament ID.
|
||||
_GENERIC_FILAMENT_IDS = {
|
||||
"PLA": "GFL99",
|
||||
"PETG": "GFG99",
|
||||
@@ -1690,10 +1689,11 @@ async def configure_ams_slot(
|
||||
"PA-CF": "GFN98",
|
||||
"PETG HF": "GFG96",
|
||||
}
|
||||
_GENERIC_ID_VALUES = set(_GENERIC_FILAMENT_IDS.values())
|
||||
effective_tray_info_idx = tray_info_idx
|
||||
|
||||
if not tray_info_idx or tray_info_idx.startswith("PFUS"):
|
||||
# Check if the slot already has a recognised preset for same material
|
||||
if not tray_info_idx:
|
||||
# No preset provided — try slot reuse or generic fallback
|
||||
current_tray_info_idx = ""
|
||||
current_tray_type = ""
|
||||
state = printer_manager.get_status(printer_id)
|
||||
@@ -1724,7 +1724,7 @@ async def configure_ams_slot(
|
||||
|
||||
if (
|
||||
current_tray_info_idx
|
||||
and not current_tray_info_idx.startswith("PFUS")
|
||||
and current_tray_info_idx not in _GENERIC_ID_VALUES
|
||||
and current_tray_type
|
||||
and current_tray_type.upper() == tray_type.upper()
|
||||
):
|
||||
@@ -1742,10 +1742,7 @@ async def configure_ams_slot(
|
||||
or ""
|
||||
)
|
||||
if generic:
|
||||
if tray_info_idx:
|
||||
logger.info("[configure_ams_slot] Replacing user-local %r with generic %r", tray_info_idx, generic)
|
||||
else:
|
||||
logger.info("[configure_ams_slot] Deriving tray_info_idx=%r from tray_type=%r", generic, tray_type)
|
||||
logger.info("[configure_ams_slot] Falling back to generic %r for material %r", generic, tray_type)
|
||||
effective_tray_info_idx = generic
|
||||
|
||||
# Send filament setting + K-profile commands
|
||||
|
||||
Reference in New Issue
Block a user