1
0
Fork 0
mirror of https://github.com/maziggy/bambuddy.git synced 2026-05-09 00:08:34 +02:00

[PR #1200] [Fix] Dual-UID spool identification, use tray_uuid end-to-end #1176

Open
opened 2026-05-07 00:16:28 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/maziggy/bambuddy/pull/1200
Author: @Keybored02
Created: 5/3/2026
Status: 🔄 Open

Base: devHead: fix/tray_uuid


📝 Commits (8)

  • 601184a Add block 9 to NFC reader
  • efdaf0a Migrate to tray_uuid
  • c40d856 fix(spool): ensure tag removal clears state for fresh card display
  • f947075 fix(spool): add optional tag_uid_2 field to MatchedSpool interface
  • 60456c7 fix(spool): add optional tag_uid_2 field to SpoolBuddy components
  • 75225ef fix(spool): add optional tag_uid_2 field to SpoolBuddyDashboard
  • 116495b fix(spool): allow tagId and tagUid to be nullable in LinkSpoolModal and SpoolInfoCard
  • 847b6c2 Merge branch 'dev' into fix/tray_uuid

📊 Changes

24 files changed (+247 additions, -150 deletions)

View changed files

📝 backend/app/api/routes/inventory.py (+29 -9)
📝 backend/app/api/routes/spoolbuddy.py (+3 -0)
📝 backend/app/core/database.py (+4 -0)
📝 backend/app/models/spool.py (+4 -1)
📝 backend/app/schemas/spool.py (+3 -0)
📝 backend/app/services/spool_tag_matcher.py (+96 -77)
📝 frontend/src/__tests__/components/AssignSpoolModal.test.tsx (+3 -0)
📝 frontend/src/__tests__/components/SpoolFormBulk.test.tsx (+1 -0)
📝 frontend/src/__tests__/components/SpoolFormModal.test.tsx (+1 -0)
📝 frontend/src/__tests__/pages/InventoryPageGrouping.test.ts (+1 -0)
📝 frontend/src/__tests__/pages/InventoryPageLowStock.test.tsx (+3 -0)
📝 frontend/src/api/client.ts (+2 -1)
📝 frontend/src/components/SpoolFormModal.tsx (+2 -2)
📝 frontend/src/components/spoolbuddy/InventorySpoolInfoCard.tsx (+7 -2)
📝 frontend/src/components/spoolbuddy/LinkSpoolModal.tsx (+1 -1)
📝 frontend/src/components/spoolbuddy/SpoolInfoCard.tsx (+8 -3)
📝 frontend/src/components/spoolbuddy/TagDetectedModal.tsx (+7 -2)
📝 frontend/src/hooks/useSpoolBuddyState.ts (+16 -2)
📝 frontend/src/pages/InventoryPage.tsx (+7 -4)
📝 frontend/src/pages/spoolbuddy/SpoolBuddyDashboard.tsx (+23 -15)

...and 4 more files

📄 Description

Description

Adds a secondary tag_uid_2 field so a spool can be identified by two different hardware UIDs (different physical tags). Fixes tray_uuid being silently dropped when adding a new spool through SpoolBuddy — it's now saved and used as the primary match identifier end-to-end. Also fixes the spool card staying visible on the SpoolBuddy dashboard after removing a freshly-added spool.

Fixes #984

Documentation

Companion docs PRs (delete lines that don't apply):

Pick one:

  • [] Docs PR(s) linked above
  • No docs update required — reason: backend update and behavior fix

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test addition or update

Changes Made

  1. Dual tag UID support (tag_uid_2)

Adds an optional secondary hardware UID column per spool, to handle the real-world case where the same physical tag is reported with a different first byte by different NFC reader hardware. The second slot is strictly opt-in — it is never auto-assigned; it can only be set explicitly via the PATCH /spools/{id}/link-tag API or the spool form.

New tag_uid_2 VARCHAR(16) column on the spool table with an inline _safe_execute migration
All matching logic (get_spool_by_tag, fuzzy fallback) searches both columns transparently via a shared _fuzzy_uid_match() helper
Conflict checks in the link-tag route cover both columns on active and archived spools
Frontend displays the primary UID with both in the tooltip; "tagged/untagged" filters and the write-tag page check both columns

  1. tray_uuid saved end-to-end through SpoolBuddy

Previously, when a Bambu Lab spool was scanned by SpoolBuddy and the user created a new inventory entry or linked it to an existing spool, the tray_uuid (read from MIFARE Classic block 9) was silently dropped. This meant subsequent scans matched by hardware UID only, losing the more-reliable UUID-based matching.

spoolbuddy_unknown_tag and spoolbuddy_tag_matched WebSocket broadcasts now include tray_uuid
useSpoolBuddyState carries tray_uuid through state (unknownTrayUuid, currentTrayUuid)
SpoolBuddyDashboard tracks displayedTrayUuid alongside displayedTagId, and passes it to createSpool and linkTagToSpool calls
tag_type is set to 'bambulab' (not 'generic') when a tray_uuid is present

  1. Dashboard card cleared on tag removal

After a quick-add, removing the spool from the scale/reader left the card visible. The tag-removal useEffect only cleared state when hiddenTagId was set (i.e. the user had closed the card), so a freshly-added spool — where the card was never manually closed — was never cleared on physical removal.

The else-branch now clears displayedTagId/displayedTrayUuid whenever either is non-null, unconditionally

Screenshots

Testing

  • I have tested this on my local machine
  • I have tested with my printer model: H2C

Checklist

  • My code follows the project's coding style
  • I have commented my code where necessary
  • My changes generate no new warnings
  • I have tested my changes thoroughly

Additional Notes


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/maziggy/bambuddy/pull/1200 **Author:** [@Keybored02](https://github.com/Keybored02) **Created:** 5/3/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `fix/tray_uuid` --- ### 📝 Commits (8) - [`601184a`](https://github.com/maziggy/bambuddy/commit/601184ad5bd1ae3b1839df7ad17817f48c591909) Add block 9 to NFC reader - [`efdaf0a`](https://github.com/maziggy/bambuddy/commit/efdaf0a2f0d5f60a36e672d7d8780ea1fce817d8) Migrate to tray_uuid - [`c40d856`](https://github.com/maziggy/bambuddy/commit/c40d856caa498ac5b6af1dee9b847ea100736998) fix(spool): ensure tag removal clears state for fresh card display - [`f947075`](https://github.com/maziggy/bambuddy/commit/f9470755608e21f2392515dbf18e9808be72901b) fix(spool): add optional tag_uid_2 field to MatchedSpool interface - [`60456c7`](https://github.com/maziggy/bambuddy/commit/60456c73692bfc77f5fea9bab1023bdc1dd26f30) fix(spool): add optional tag_uid_2 field to SpoolBuddy components - [`75225ef`](https://github.com/maziggy/bambuddy/commit/75225ef9f2d0431d8a8943a27169fc668ae117ae) fix(spool): add optional tag_uid_2 field to SpoolBuddyDashboard - [`116495b`](https://github.com/maziggy/bambuddy/commit/116495b3d71f4b16cd563679d5870de4b3d75037) fix(spool): allow tagId and tagUid to be nullable in LinkSpoolModal and SpoolInfoCard - [`847b6c2`](https://github.com/maziggy/bambuddy/commit/847b6c25d4699722c704a477992a291683d7a530) Merge branch 'dev' into fix/tray_uuid ### 📊 Changes **24 files changed** (+247 additions, -150 deletions) <details> <summary>View changed files</summary> 📝 `backend/app/api/routes/inventory.py` (+29 -9) 📝 `backend/app/api/routes/spoolbuddy.py` (+3 -0) 📝 `backend/app/core/database.py` (+4 -0) 📝 `backend/app/models/spool.py` (+4 -1) 📝 `backend/app/schemas/spool.py` (+3 -0) 📝 `backend/app/services/spool_tag_matcher.py` (+96 -77) 📝 `frontend/src/__tests__/components/AssignSpoolModal.test.tsx` (+3 -0) 📝 `frontend/src/__tests__/components/SpoolFormBulk.test.tsx` (+1 -0) 📝 `frontend/src/__tests__/components/SpoolFormModal.test.tsx` (+1 -0) 📝 `frontend/src/__tests__/pages/InventoryPageGrouping.test.ts` (+1 -0) 📝 `frontend/src/__tests__/pages/InventoryPageLowStock.test.tsx` (+3 -0) 📝 `frontend/src/api/client.ts` (+2 -1) 📝 `frontend/src/components/SpoolFormModal.tsx` (+2 -2) 📝 `frontend/src/components/spoolbuddy/InventorySpoolInfoCard.tsx` (+7 -2) 📝 `frontend/src/components/spoolbuddy/LinkSpoolModal.tsx` (+1 -1) 📝 `frontend/src/components/spoolbuddy/SpoolInfoCard.tsx` (+8 -3) 📝 `frontend/src/components/spoolbuddy/TagDetectedModal.tsx` (+7 -2) 📝 `frontend/src/hooks/useSpoolBuddyState.ts` (+16 -2) 📝 `frontend/src/pages/InventoryPage.tsx` (+7 -4) 📝 `frontend/src/pages/spoolbuddy/SpoolBuddyDashboard.tsx` (+23 -15) _...and 4 more files_ </details> ### 📄 Description ## Description Adds a secondary `tag_uid_2` field so a spool can be identified by two different hardware UIDs (different physical tags). Fixes tray_uuid being silently dropped when adding a new spool through SpoolBuddy — it's now saved and used as the primary match identifier end-to-end. Also fixes the spool card staying visible on the SpoolBuddy dashboard after removing a freshly-added spool. ## Related Issue <!-- Link to the issue this PR addresses (if applicable) --> Fixes #984 ## Documentation <!-- If this PR changes user-visible behavior, config keys, ports, CLI flags, URLs, or installation steps, link matching PRs in the docs repos below. Internal refactors, bug fixes with no observable change, and test-only changes are exempt — just check the "not required" box and say why. See CONTRIBUTING.md → Documentation Requirements for the full rules. --> **Companion docs PRs** (delete lines that don't apply): **Pick one**: - [] Docs PR(s) linked above - [x] No docs update required — reason: backend update and behavior fix ## Type of Change <!-- Mark the relevant option with an "x" --> - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Test addition or update ## Changes Made <!-- List the specific changes made in this PR --> 1. Dual tag UID support (tag_uid_2) Adds an optional secondary hardware UID column per spool, to handle the real-world case where the same physical tag is reported with a different first byte by different NFC reader hardware. The second slot is strictly opt-in — it is never auto-assigned; it can only be set explicitly via the PATCH /spools/{id}/link-tag API or the spool form. New tag_uid_2 VARCHAR(16) column on the spool table with an inline _safe_execute migration All matching logic (get_spool_by_tag, fuzzy fallback) searches both columns transparently via a shared _fuzzy_uid_match() helper Conflict checks in the link-tag route cover both columns on active and archived spools Frontend displays the primary UID with both in the tooltip; "tagged/untagged" filters and the write-tag page check both columns 2. tray_uuid saved end-to-end through SpoolBuddy Previously, when a Bambu Lab spool was scanned by SpoolBuddy and the user created a new inventory entry or linked it to an existing spool, the tray_uuid (read from MIFARE Classic block 9) was silently dropped. This meant subsequent scans matched by hardware UID only, losing the more-reliable UUID-based matching. spoolbuddy_unknown_tag and spoolbuddy_tag_matched WebSocket broadcasts now include tray_uuid useSpoolBuddyState carries tray_uuid through state (unknownTrayUuid, currentTrayUuid) SpoolBuddyDashboard tracks displayedTrayUuid alongside displayedTagId, and passes it to createSpool and linkTagToSpool calls tag_type is set to 'bambulab' (not 'generic') when a tray_uuid is present 3. Dashboard card cleared on tag removal After a quick-add, removing the spool from the scale/reader left the card visible. The tag-removal useEffect only cleared state when hiddenTagId was set (i.e. the user had closed the card), so a freshly-added spool — where the card was never manually closed — was never cleared on physical removal. The else-branch now clears displayedTagId/displayedTrayUuid whenever either is non-null, unconditionally ## Screenshots <!-- If applicable, add screenshots to demonstrate your changes --> ## Testing <!-- Describe how you tested your changes --> - [x] I have tested this on my local machine - [x] I have tested with my printer model: H2C ## Checklist - [x] My code follows the project's coding style - [x] I have commented my code where necessary - [x] My changes generate no new warnings - [x] I have tested my changes thoroughly ## Additional Notes <!-- Add any additional information that reviewers should know --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/bambuddy-maziggy-1#1176
No description provided.