Commit Graph
41 Commits
Author SHA1 Message Date
maziggyandClaude Opus 4.5 ca2bd6bf57 Fix timelapse auto-download and browser tab crash on print completion
1. Timelapse auto-download rewrite (main.py)
   - New retry mechanism with short delays (5s, 10s, 20s)
   - Grabs most recent file directly without mtime comparison
   - Works with printers that have wrong clock (LAN-only mode)
   - Checks multiple paths: /timelapse, /timelapse/video, /record, /recording

2. Browser tab crash fix (PrintersPage.tsx)
   - Throttled query cache subscription using requestAnimationFrame
   - Prevents rapid re-render cascade on print completion events

3. WebSocket optimization (main.py)
   - Removed large raw_data field from print_complete message
   - Only sends necessary fields: status, filename, subtask_name, timelapse_was_active

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 08:46:38 +01:00
maziggy e85e5fa33e Backend changes:
1. bambu_mqtt.py: Added hms_errors to the completion callback data, which includes the HMS error codes when a print fails
  2. archive.py: Updated update_archive_status() to accept an optional failure_reason parameter
  3. main.py: Added auto-detection of failure reasons:
    - status == "aborted" → failure_reason = "User cancelled"
    - status == "failed" with HMS errors → maps module codes to reasons:
        - Module 0x07 (Filament) → "Filament runout"
      - Module 0x0C (Motion Controller) → "Layer shift"
      - Module 0x05 (Nozzle) → "Clogged nozzle"

  Frontend changes:

  1. ArchivesPage.tsx:
    - Badge now shows "cancelled" for aborted prints, "failed" for failed prints
    - "Failed Prints" collection and "Hide Failed" filter now include both failed and aborted statuses
  2. EditArchiveModal.tsx: Failure reason field now shows for both failed and aborted prints

  New tests added:
  - test_hms_errors_included_in_failed_completion_callback
  - test_aborted_status_when_cancelled

  The HMS error module mapping is basic and can be expanded as you observe more failure types. The actual Bambu HMS error codes are documented in their wiki - we can add
  more mappings as needed.
2025-12-13 10:13:54 +01:00
maziggy ae55884858 1. ArchiveService import shadowing bug (main.py:978) - Local import was shadowing module-level import, causing "cannot access local variable" error
2. Timelapse race condition (bambu_mqtt.py) - xcam data was parsed before _was_running was set, so timelapse wasn't detected at print start
  3. Added exception handling (printer_manager.py) - _schedule_async now logs exceptions instead of swallowing them silently
  4. Added debug logging (main.py) - [CALLBACK] logs at key decision points to help debug future issues
  5. Added code quality tests (test_code_quality.py) - Static analysis to catch import shadowing bugs automatically
2025-12-13 09:39:14 +01:00
maziggy 3fe49f6af5 1. Timelapse Race Condition Fix (bambu_mqtt.py)
Problem: xcam data was parsed BEFORE _was_running was set to True, so timelapse detection failed when both arrived in the same message.

  Fix: Added timelapse detection at two critical points:

  # Lines 1375-1381: When entering RUNNING state
  if self.state.state == "RUNNING" and current_file:
      if not self._was_running:
          if self.state.timelapse:
              self._timelapse_during_print = True
              logger.info(f"[{self.serial_number}] Timelapse detected when entering RUNNING state")

  # Lines 1391-1399: When print start detected
  if self.state.timelapse:
      self._timelapse_during_print = True
      logger.info(f"[{self.serial_number}] Timelapse detected at print start")

  2. Callback Error Handling (main.py + printer_manager.py)

  Problem: The on_print_complete callback was hanging silently - no logs after "Found archive".

  Fixes:
  - Added try/except wrapper around "Update archive status" section (line 749-767)
  - Added [CALLBACK] log messages at start and end of callback
  - Added exception handler to _schedule_async in printer_manager.py to log any exceptions from async callbacks

  3. New Integration Tests (test_bambu_mqtt.py)

  Added TestRealisticMessageFlow class with 5 new tests that simulate real MQTT message sequences:

  1. test_timelapse_detected_at_print_start_in_same_message - The critical race condition test
  2. test_timelapse_not_detected_when_disabled
  3. test_timelapse_detected_when_enabled_after_print_start
  4. test_print_complete_includes_timelapse_flag_full_flow - Full lifecycle test
  5. test_print_failed_includes_timelapse_flag

  These tests process messages through _process_message() with proper {"print": {...}} wrapping, matching real MQTT flow.

  Files Modified:

  - backend/app/services/bambu_mqtt.py - Timelapse race condition fix
  - backend/app/main.py - Error handling + logging for on_print_complete
  - backend/app/services/printer_manager.py - Exception capture in _schedule_async
  - backend/tests/unit/services/test_bambu_mqtt.py - New integration tests

  Next Steps

  You should restart the application to apply these changes. The next print will show:
  - [CALLBACK] on_print_complete started for printer X
  - [ARCHIVE] Updating archive X status...
  - [ENERGY], [PHOTO], [AUTO-OFF] logs (if those features trigger)
  - [CALLBACK] on_print_complete finished for printer X, archive X
2025-12-13 09:16:58 +01:00
maziggy ee2b674278 Issue 1: Print Start Notification - Estimated Time Unknown
Problem: At print start, the MQTT mc_remaining_time was often 0 or unavailable because the printer hadn't fully processed the gcode yet.

  Solution: Modified the notification system to prioritize the print_time_seconds from the 3MF file parsing (which is always available after archive creation) over the
  MQTT remaining time.

  Files changed:
  - backend/app/services/notification_service.py:
    - Added optional archive_data parameter to on_print_start() method
    - Added priority logic: archive data > MQTT remaining_time > raw_data mc_remaining_time
  - backend/app/main.py:
    - Created _send_print_start_notification() helper function
    - Moved notification sending to AFTER archive creation (when print_time_seconds is available)
    - Added fallback notification sending at early return points (auto_archive disabled, file not found, etc.)

  Issue 2: Timelapse Auto-Assignment

  Problem: Timelapses couldn't be auto-assigned reliably because printer dates could be off in LAN-only mode, making timestamp matching unreliable.

  Solution: Track whether timelapse recording was active during the print via MQTT, and if so, auto-fetch the most recent timelapse file on print completion.

  Files changed:
  - backend/app/services/bambu_mqtt.py:
    - Added _timelapse_during_print instance variable
    - Track when timelapse is active during a print (in both data and xcam parsing)
    - Reset the flag on new print start
    - Include timelapse_was_active in the print complete callback data
  - backend/app/main.py:
    - Added timelapse auto-scan logic in on_print_complete()
    - If timelapse_was_active is True and status is "completed":
        - Wait 5 seconds for timelapse to finalize
      - Scan printer's timelapse directory
      - Find most recent file by mtime
      - Verify it was modified within 30 minutes of print completion
      - Download and attach to archive
      - Send WebSocket update
2025-12-12 15:35:46 +01:00
maziggy 1a4f146dd0 Notifications:
- Separate AMS and AMS-HT notification switches (one per device type)
  - Fix notification variables not showing (duration, filament, estimated_time)
  - Add fallback values for empty notification variables ("Unknown" instead of blank)

  Settings:
  - Fix API keys badge count only showing after visiting tab
  - Move External Links card to third column above Updates
  - Add Release Notes modal for viewing full notes before updating

  Statistics:
  - Fix filament usage trends not showing (wrong API parameters)
  - Move dashboard controls (Hidden, Reset Layout) to header row
  - Remove duplicate Reset Layout button

  Camera:
  - Fix ffmpeg processes not killed when closing webcam window
  - Add /camera/stop endpoint with POST support for sendBeacon
  - Track active streams and proper cleanup on disconnect
2025-12-12 09:18:59 +01:00
maziggy 7048bafff3 Added anonymous stats 2025-12-11 13:35:59 +01:00
maziggy 77a66ea867 Added system info page 2025-12-11 12:45:38 +01:00
maziggy ea6d84031a Removed PWA P´push notification 2025-12-11 11:37:13 +01:00
maziggy 2f1ac92598 Restored some files that were deleted by mistake 2025-12-11 11:15:25 +01:00
maziggy c3026632da Improved auto power off scheduler 2025-12-11 08:02:15 +01:00
maziggy e392597192 Added notification module for AMS humidity and temperature 2025-12-10 20:02:22 +01:00
maziggy 0dc76746b4 Add AMS humidity/temperature history tracking with charts
- Add database model for storing AMS sensor history (humidity, temperature)
  - Record sensor data every 5 minutes via background task
  - Add API endpoint to retrieve history with min/max/avg statistics
  - Create AMSHistoryModal component with Recharts line charts
  - Make humidity/temperature indicators clickable to open history
  - Support time range selection (6h, 24h, 48h, 7d)
  - Show threshold reference lines on charts (Good/Fair levels)
  - Add configurable data retention (default 30 days) in Settings
  - Auto-cleanup old data daily
  - Fix dark theme styling in modal using inline styles
  - Add Escape key to close modal
2025-12-10 19:45:38 +01:00
maziggy dbcbde0b16 Improved email notification provider 2025-12-10 19:12:49 +01:00
maziggy d1518083fc ## New Features
### Projects / Print Grouping
  - Create projects to group related prints (e.g., "Voron Build" with 50 parts)
  - Track progress with target count and completion percentage
  - Assign archives to projects via edit modal or context menu
  - Project cards show archive thumbnails with clickable links
  - Color-coded project badges on archive cards
  - Filter and manage projects by status (active/completed/archived)

  ### Full-Text Search (FTS5)
  - SQLite FTS5 virtual table for efficient searching
  - Search across print_name, filename, tags, notes, designer, filament_type
  - Automatic index sync with triggers for INSERT/UPDATE/DELETE

  ### Webhooks & API Keys
  - API key authentication with granular permissions
  - Permissions: can_read_status, can_manage_queue, can_control_printer
  - Secure key generation with prefix display only after creation
  - Settings page API Keys tab for key management
  - Webhook endpoints for external integrations

  ### Failure Analysis
  - Dashboard widget showing failure rate with color coding
  - Correlate failures with conditions (filament type, printer, time)
  - Top failure reasons breakdown
  - Weekly trend visualization

  ### Archive Comparison
  - Select 2-5 archives to compare side-by-side
  - Highlight differences in print settings (yellow)
  - Success/failure correlation insights
  - Modal with close via button, X, Escape, or backdrop

  ### CSV/Excel Export
  - Export archives and statistics with current filters
  - Support for both CSV and Excel (.xlsx) formats
  - openpyxl dependency added

  ## Bug Fixes
  - Fixed context menu submenu not showing (removed overflow-hidden)
  - Fixed project card thumbnails using correct API endpoint
  - Fixed EditArchiveModal to invalidate projects query on save
  - Fixed clipboard API fallback for HTTP contexts
  - Fixed archive PATCH 500 error (FTS5 index rebuild)
  - Fixed FastAPI trailing slash routing for projects endpoint

  ## UI Improvements
  - Context menu submenu with hover/click support
  - Project badge on archive cards with project color
  - "Go to Project" context menu item for assigned archives
  - Clickable project card thumbnails linking to archives
  - Reset Layout button moved to Stats page header
2025-12-10 17:06:43 +00:00
maziggy 711140ddf9 Added mobile PWA support 2025-12-10 11:21:25 +00:00
maziggy 36b57bbafb - External links can now be embedded into sidebar navigation 2025-12-09 12:06:58 +00:00
maziggy 6d71261de7 Renaming app to Bambuddy 2025-12-09 08:55:59 +00:00
maziggy c74f24353a - Added smart plug monitoring and scheduling
- Added daily digest to notification module
2025-12-08 16:30:53 +00:00
maziggy 29aadfb774 Added template system to notification module. 2025-12-08 15:23:17 +00:00
maziggy 06bfaa3c74 Completely removed control page and all it's related code 2025-12-07 10:19:25 +00:00
Martin Ziegler 088b40cefa Some small layout fixes for control page 2025-12-02 16:18:48 +01:00
Martin Ziegler 37caef239f Started to implement full printer control 2025-12-01 16:25:54 +01:00
Martin Ziegler f126b0a075 Added auto app update; Added maintenance module with notifications 2025-12-01 08:39:07 +01:00
Martin Ziegler 8571236bc0 Added update module 2025-12-01 07:34:25 +01:00
Martin Ziegler 8bc263ad02 Added Spoolman support to add unknown Bambu Lab spools and track them 2025-11-30 19:37:36 +01:00
Martin Ziegler a862958deb Added Spoolman support to add unknown Bambu Lab spools and track them 2025-11-30 19:30:14 +01:00
Martin Ziegler 17c37a7ccd Added notification module 2025-11-30 16:51:27 +01:00
Martin Ziegler 301eec98fb Added option to track energy only per print or in total 2025-11-30 16:00:38 +01:00
Martin Ziegler 5548b05f27 Added k profile management 2025-11-30 15:31:55 +01:00
Martin Ziegler 28a5e786e9 Added configurable logging; Major improvements and bugfixes 2025-11-30 12:55:00 +01:00
Martin Ziegler ba302394d5 Fixed websocket bug 2025-11-30 09:23:10 +01:00
Martin Ziegler b642644cbb Fixed websocket bug 2025-11-30 09:02:17 +01:00
Martin Ziegler af8120604b Added scheduling and queueing; Misc improvements 2025-11-29 14:47:19 +01:00
Martin Ziegler 0c2a187191 Added power consumption costs calculation 2025-11-29 12:16:53 +01:00
Martin Ziegler 3031c2ae3e Minor bugfixes 2025-11-29 12:09:58 +01:00
Martin Ziegler 12f763efde Added feature to take a photo from printer camera when print completes 2025-11-29 11:35:10 +01:00
Martin Ziegler a3167562bb Fixed bug archiving file on print start 2025-11-29 09:30:16 +01:00
Martin Ziegler 5c27da41c5 Added support for Tasmota based smart power plugs and automation 2025-11-28 13:17:22 +01:00
Martin Ziegler 0f964e16a5 Changed version to 0.1.2 2025-11-28 11:01:39 +01:00
Martin Ziegler 09677861ba Added screenshots 2025-11-28 10:23:59 +01:00