Skip to content

Refetch spools before treating a Bambu tag as unknown; don't reset the AMS tray for it - #104

Open
vindavs wants to merge 1 commit into
drndos:mainfrom
vindavs:mv/refetch-unknown-tray-tag
Open

vindavs wants to merge 1 commit into
drndos:mainfrom
vindavs:mv/refetch-unknown-tray-tag

Conversation

@vindavs

@vindavs vindavs commented Oct 30, 2026

Copy link
Copy Markdown

Should address #95.

The MQTT loop matches tray tags against fetchSpools(cached=True), which is filled once and only refreshed when a web route runs. A spool tagged in SpoolMan after that is reported as "Not found. Update spool tag!", and for an unknown tag the loop sends ams_filament_setting with blank values on every status report. That command discards the filament data the printer just read from the spool's RFID tag, which matches #95: a new Bambu spool is identified, then reverts to "?" until OpenSpoolMan knows its tag.

Seen on an X1C (firmware 01.12.00.00, cloud mode, v0.3.0): spools were added through the SpoolMan API while OpenSpoolMan was running, the cache filled mid-import, and three tagged trays were reported as unknown, so their usage went untracked and each got the reset on every report (222 in 10 minutes). This printer refuses it in cloud mode (mqtt message verify failed), so only tracking was affected here. Opening the web UI or restarting fixed the matching.

  • spools_with_tag(): on a cache miss, refetch from SpoolMan, at most once per 60 s (TAG_REFETCH_INTERVAL_S).
  • Unknown Bambu tag: clear only the SpoolMan assignment, once per (tray, tag); no ams_filament_setting. The web UI's _augment_tray already handles an unmapped tag this way.
  • fetchSpoolList() gets a 10 s timeout (SPOOLMAN_TIMEOUT_S); without one, a SpoolMan that accepts but never answers stalls the MQTT thread, and the refetch adds a path into it. If the lookup fails, the tray is left as is for that report rather than treated as unknown, and the other trays in the report are still processed.
  • The tray UUID is read before the lookup. Previously it was set inside the spool loop, so with an empty SpoolMan a Bambu spool was logged as "non Bambulab Spool!"; it is now "Not found".

Not tested on a printer that accepts the reset (LAN-only + Developer mode), so #95 is addressed by reasoning from the report, not reproduced.

Tests: tests/test_tray_tag_matching.py (7 cases). On the old code, the stale-cache, no-reset, failed-refetch and timeout cases fail (no match; 5 resets for 5 reports; later trays skipped; no timeout); the interval case fails if the refetch only ever runs once. Full suite: 28 passed, 2 skipped; flake8 gate as in CI passes.

  • Scope is minimal; no unrelated refactors
  • No secrets or sensitive values introduced
  • Errors handled (timeouts, retries/backoff if applicable): spool-list fetch has a timeout; the refetch is rate-limited and a failure leaves the tray untouched
  • Tests added/updated
  • README/config updated if behavior or configuration changed: no new configuration
  • Docker/Helm impact considered: none
  • Filament matching rules preserved: tag matching only; material/sub-brand matching untouched

…e AMS tray for it

The MQTT loop matched tray tags against a spool list cached on first use and
never refreshed, so a spool tagged in SpoolMan later was reported as unknown
until the cache happened to reload. For an unknown tag it also sent
ams_filament_setting with blank values on every status report, discarding the
filament data the printer had read from the spool's RFID tag (drndos#95).

- Refetch the spool list on a cache miss, at most once a minute.
- For an unknown Bambu tag, clear only the SpoolMan assignment, once per tray
  and tag, as the web UI already does; never reset the tray on the printer.
- Give fetchSpoolList a 10 s timeout, and leave a tray as is when SpoolMan
  can't be read instead of treating its tag as unknown.
- Read the tray UUID before the lookup, so a Bambu spool counts as one even
  when SpoolMan has no spools yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant