Fix filament usage tracking on auto-refill/runout (#90)#1
Draft
Fix filament usage tracking on auto-refill/runout (#90)#1
Conversation
- Add _last_tray_tar tracking to detect when tray_tar changes - Add handle_tray_change method to invalidate cached spool mappings - Clear cached spool ID when tray changes to force re-lookup of spool - Reset _last_tray_tar on print end/abort Fixes drndos#90 Agent-Logs-Url: https://github.com/csm10495/openspoolman/sessions/70fcf179-0fb6-4ccc-8862-a54a31d17ea1 Co-authored-by: csm10495 <5749838+csm10495@users.noreply.github.com>
Claude created this pull request from a session on behalf of
csm10495
April 19, 2026 03:06
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes drndos#90 - Filament usage not correctly tracked on filament runout
When using Bambu Lab's auto-refill feature (where a second spool automatically takes over when the first runs out), OpenSpoolMan was continuing to credit usage to the original spool instead of switching to the new spool. This fix detects tray changes during active printing and invalidates the cached spool mapping to ensure usage is tracked against the correct spool.
Changes
Detection of Tray Changes
_last_tray_tartracking inFilamentUsageTrackerto detect when the active tray changeson_messageto monitortray_tarchanges duringRUNNINGstate[filament-tracker] Detected tray change: 3 -> 0Handling Tray Changes
handle_tray_change(tray_tar)method that:State Management
_last_tray_tartoNonewhen print ends or is abortedTesting
All existing tests pass, including MQTT replay tests that simulate multicolor prints with tray changes. The logs show proper detection:
Impact
TRACK_LAYER_USAGE=Trueand legacy tracking🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com