mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-05-09 08:25:54 +02:00
[PR #686] [MERGED] [Fix]: Properly track filament usage data in Spoolman #1100
Labels
No labels
A1
automated
automated
bug
bug
Closed due to inactivity
contrib
dependencies
dependencies
duplicate
enhancement
feedback
hold
invalid
Notes
P1S
pull-request
security
ThumbsUp
user-report
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/bambuddy-maziggy-1#1100
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/maziggy/bambuddy/pull/686
Author: @shrunbr
Created: 3/12/2026
Status: ✅ Merged
Merged: 3/13/2026
Merged by: @maziggy
Base:
dev← Head:fix/spoolmanTracking📝 Commits (10+)
7f0cec0Fixes '>=' error when attempting to store tracking data for Spoolman spool usage311e08aEnhance spool tag resolution and fallback mechanisms for printer serial handling.12597a4Add tests for fallback tag resolution and global tray ID mapping.94637adEnhance store_print_data to support explicit AMS mapping and fallback to queue mapping.b4f2278Add AMS mapping resolution for print start tracking data.bc7c6b1Add unit tests for store_print_data to prefer explicit AMS mapping.49e9217Enhance cleanup_tracking and _report_partial_usage to support last_layer_num and last_progress parameters for improved partial usage reporting.24d3a2cEnhance on_print_complete to pass last_layer_num and last_progress to _cleanup_spoolman_tracking for improved tracking accuracy.386460cEnhance _resolve_global_tray_id to accept ams_trays for improved mapping accuracy and fallback handling.ba21bccEnhance _report_spool_usage_for_slots to log tray type and external status for improved debugging.📊 Changes
3 files changed (+323 additions, -50 deletions)
View changed files
📝
backend/app/main.py(+37 -4)📝
backend/app/services/spoolman_tracking.py(+187 -46)📝
backend/tests/unit/services/test_spoolman_tracking.py(+99 -0)📄 Description
Description
Copilot generated summary
This pull request introduces significant improvements to the Spoolman filament usage tracking system, focusing on more accurate spool identification, robust partial usage reporting, and better handling of AMS tray mappings. The changes enhance the reliability of reporting filament usage for both standard and external spools, especially in cases of failed or aborted prints, and ensure deterministic spool tagging by mirroring frontend logic.
Related Issue
Fixes #677
Type of Change
Changes Made
backend/app/main.py
backend/app/services/spoolman_tracking.py
backend/tests/unit/services/test_spoolman_tracking.py
Extended tests to assert that all-zero tag_uid/tray_uuid are treated as missing and that fallback tags are generated correctly.
Screenshots
Spoolman debug at print start:

Spoolman debug at print end:

Testing
I tested this extensively on my printer. I am happy to report that filament tracking works across all AMS slots and the external slot. It works for mutli-filament prints as well.
test_frontend,test_backendandtest_dockerall pass sucessfully.Checklist
Additional Notes
There is a HUGE caveat to this change really due to how tracking works in general. When a print is started the 3mf file is downloaded and parsed by Bambuddy, it then determines where the filament changes happen including the initial start. The filament slots that it IDs are based upon the filament slots in your slicer.
For example, these are the filaments in my slicer, they are in the exact same order as they are in my AMS
If I flip around # 2 and # 4 for example, and go to print with # 4 which is now red, Bambuddy will tie that back to the filament in the 4th slot of my AMS and tracking data will go against the wrong spool
I do believe this is due to the data we're able to extract from 3mf and gcode not due to anything Bambuddy is doing. I found a line in a comment on the
extract_filament_properties_from_3mffunction inthreemf_tools.pywhich says:filament_id is 1-based (matches slot_id in slice_info.config). That correlates these findings as well.So for this to work properly, your filament slots in your slicer must match the filament slots in your AMS. These can always be overridden (at least in Bambu Studio) by clicking the "Synchronize filament" button
and then choose "Overwriting" at the top and click "Synchronize now" at the bottom
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.