mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-06 14:11:35 +02:00
fix(inventory): handle PFCN cloud preset IDs in assign-via-MQTT (#1648)
Reporter on an H2D + Polymaker PLA Matte spool noticed that assigning
the spool from the Dashboard left the slicer's filament dropdown
showing "unknown", but clicking Configure right after made the
slicer recognize it correctly. "Configure" felt like a mandatory
follow-up step rather than a refinement.
Bambu cloud uses three preset-ID shapes:
GFS… — Bambu official cloud preset
PFUS… — cloud user-created preset
PFCN… — cloud shared / partner preset (Polymaker's "(Custom)"
Bambu Lab H2D variants ship this prefix)
apply_spool_to_slot_via_mqtt only routed GFS and PFUS through the
cloud-detail lookup that extracts the underlying filament_id. PFCN
slipped past the cloud-lookup branch, fell into the local-preset
int() parse path, raised ValueError, dropped into
normalize_slicer_filament which returns any P-prefix unchanged, and
the raw PFCN landed in tray_info_idx. The printer's calibration
table can't index that, so the slicer rendered "unknown". The
Configure modal rescued every assign because it does its own
getCloudSettingDetail and writes the resolved filament_id.
Extend the cloud-detail-lookup branch (inventory.py:129) and the
discard safety net (inventory.py:223) to include PFCN alongside
GFS/PFUS. Three behaviours fall out:
* Cloud-authenticated: the real filament_id from
detail["filament_id"] ships as tray_info_idx (Polymaker PLA
Matte resolves to GFL05).
* Cloud unavailable: raw PFCN discarded, the slot reuses an
existing valid P-prefix preset if material matches.
Source comment now lists all three cloud-ID shapes so the next time
Bambu invents a new prefix the maintainer doesn't have to re-derive
the structure from a bug report.
This commit is contained in:
@@ -126,7 +126,15 @@ async def apply_spool_to_slot_via_mqtt(
|
||||
|
||||
if sf:
|
||||
base_sf = sf.split("_")[0] if "_" in sf else sf
|
||||
if base_sf.startswith("GFS") or base_sf.startswith("PFUS"):
|
||||
# Cloud-side preset IDs in three known shapes:
|
||||
# GFS… — Bambu official cloud preset
|
||||
# PFUS… — cloud user-created preset
|
||||
# PFCN… — cloud shared / partner preset (e.g. Polymaker's
|
||||
# "(Custom)" Bambu Lab H2D variant, #1648)
|
||||
# All three need a cloud-detail lookup to extract the underlying
|
||||
# filament_id; without it the raw cloud id ends up in tray_info_idx
|
||||
# and the printer's calibration table can't resolve it.
|
||||
if base_sf.startswith("GFS") or base_sf.startswith("PFUS") or base_sf.startswith("PFCN"):
|
||||
setting_id = base_sf
|
||||
try:
|
||||
from backend.app.api.routes.cloud import build_authenticated_cloud
|
||||
@@ -204,7 +212,7 @@ async def apply_spool_to_slot_via_mqtt(
|
||||
setting_id = filament_id_to_setting_id(fid)
|
||||
break
|
||||
|
||||
# Defend against tray_info_idx values the slicer cannot resolve. Two
|
||||
# Defend against tray_info_idx values the slicer cannot resolve. Three
|
||||
# shapes leak through and must be discarded so the generic-material
|
||||
# fallback below can rescue the slot:
|
||||
# 1. Literal material names ("PLA", "PETG-CF") that pass through
|
||||
@@ -217,10 +225,16 @@ async def apply_spool_to_slot_via_mqtt(
|
||||
# replay path in main.py.on_ams_change passes current_user=None,
|
||||
# which skips cloud auth and leaves the raw PFUS in tray_info_idx —
|
||||
# overwriting the correctly-configured slot from the original assign.
|
||||
# 3. PFCN-prefix cloud shared / partner presets (e.g. Polymaker's
|
||||
# "(Custom)" H2D variants, #1648) — same shape problem as PFUS.
|
||||
# Valid tray_info_idx values: "GF" + letter + digits (Bambu official) or
|
||||
# "P" followed by hex (user/local presets, NOT "PFUS").
|
||||
# "P" followed by hex (user/local presets, NOT "PFUS" or "PFCN").
|
||||
_known_materials = set(MATERIAL_TEMPS.keys()) | set(_GENERIC_FILAMENT_IDS.keys())
|
||||
if tray_info_idx and (tray_info_idx.upper() in _known_materials or tray_info_idx.startswith("PFUS")):
|
||||
if tray_info_idx and (
|
||||
tray_info_idx.upper() in _known_materials
|
||||
or tray_info_idx.startswith("PFUS")
|
||||
or tray_info_idx.startswith("PFCN")
|
||||
):
|
||||
tray_info_idx = ""
|
||||
setting_id = ""
|
||||
|
||||
@@ -229,6 +243,7 @@ async def apply_spool_to_slot_via_mqtt(
|
||||
current_tray_info_idx
|
||||
and current_tray_info_idx not in _generic_id_values
|
||||
and not current_tray_info_idx.startswith("PFUS")
|
||||
and not current_tray_info_idx.startswith("PFCN")
|
||||
and current_tray_info_idx.upper() not in _known_materials
|
||||
and current_tray_type
|
||||
and current_tray_type.upper() == tray_type.upper()
|
||||
|
||||
Reference in New Issue
Block a user