Parcourir la source

Summary of Fixes

  1. "Unknown Status (255)" bug

  File: backend/app/services/printer_manager.py:291-293

  Problem: A1/P1 printers send stg_cur=255 when idle (unlike X1 which uses -1). The code treated 255 as a valid stage number and returned "Unknown stage (255)".

  Fix: Changed the condition from if state.stg_cur >= 0: to if 0 <= state.stg_cur < 255: so that 255 is now treated as "no calibration stage" (same as -1).

  2. AMS humidity/temp displaced on mobile

  File: frontend/src/pages/PrintersPage.tsx:1164-1212

  Problem: The AMS row used a rigid horizontal flex layout that didn't adapt to narrow mobile screens, causing humidity/temperature indicators to be displaced.

  Fix:
  - Added flex-wrap to allow wrapping on very narrow screens
  - Added ml-auto to humidity/temp section to keep it right-aligned
  - Added max-w-[60px] sm:max-w-none to truncate long filament names on mobile
  - Changed gap from fixed gap-3 to responsive gap-2 sm:gap-3

  Tests Added

  4 new unit tests for get_derived_status_name:
  - test_stg_cur_255_returns_none - Verifies A1/P1 idle state
  - test_stg_cur_negative_one_returns_none_when_idle - Verifies X1 idle state
  - test_valid_stage_returns_name - Verifies valid stages work
  - test_stg_cur_zero_returns_printing - Verifies printing state

  All 382 tests pass.
maziggy il y a 5 mois
Parent
commit
e9193276a6

+ 3 - 1
backend/app/services/printer_manager.py

@@ -288,7 +288,9 @@ def get_derived_status_name(state: PrinterState) -> str | None:
     when the printer is heating before a print starts.
     """
     # If we have a valid calibration stage, use it
-    if state.stg_cur >= 0:
+    # X1 models use -1 for idle, A1/P1 models use 255 for idle
+    # Valid stage numbers are 0-254
+    if 0 <= state.stg_cur < 255:
         return get_stage_name(state.stg_cur)
 
     # If not in RUNNING state, no derived status needed

+ 43 - 0
backend/tests/unit/services/test_printer_manager.py

@@ -11,6 +11,7 @@ import pytest
 
 from backend.app.services.printer_manager import (
     PrinterManager,
+    get_derived_status_name,
     init_printer_connections,
     printer_state_to_dict,
 )
@@ -734,6 +735,48 @@ class TestPrinterStateToDict:
         assert result["ams"][0]["is_ams_ht"] is False
 
 
+class TestGetDerivedStatusName:
+    """Tests for get_derived_status_name function."""
+
+    def test_stg_cur_255_returns_none(self):
+        """Verify stg_cur=255 (A1/P1 idle) returns None, not 'Unknown stage (255)'."""
+        state = MagicMock()
+        state.stg_cur = 255
+        state.state = "IDLE"
+
+        result = get_derived_status_name(state)
+
+        assert result is None
+
+    def test_stg_cur_negative_one_returns_none_when_idle(self):
+        """Verify stg_cur=-1 (X1 idle) returns None."""
+        state = MagicMock()
+        state.stg_cur = -1
+        state.state = "IDLE"
+
+        result = get_derived_status_name(state)
+
+        assert result is None
+
+    def test_valid_stage_returns_name(self):
+        """Verify valid stg_cur values return stage name."""
+        state = MagicMock()
+        state.stg_cur = 1  # Auto bed leveling
+
+        result = get_derived_status_name(state)
+
+        assert result == "Auto bed leveling"
+
+    def test_stg_cur_zero_returns_printing(self):
+        """Verify stg_cur=0 returns 'Printing'."""
+        state = MagicMock()
+        state.stg_cur = 0
+
+        result = get_derived_status_name(state)
+
+        assert result == "Printing"
+
+
 class TestInitPrinterConnections:
     """Tests for init_printer_connections function."""
 

+ 5 - 5
frontend/src/pages/PrintersPage.tsx

@@ -1161,9 +1161,9 @@ function PrinterCard({
 
                   return (
                     <div key={ams.id} className="p-2 bg-bambu-dark rounded-lg">
-                      <div className="flex items-center gap-3">
+                      <div className="flex flex-wrap items-center gap-2 sm:gap-3">
                         {/* Nozzle badge + AMS device icon */}
-                        <div className="flex items-center gap-1">
+                        <div className="flex items-center gap-1 flex-shrink-0">
                           {isDualNozzle && (isLeftNozzle || isRightNozzle) && (
                             <NozzleBadge side={isLeftNozzle ? 'L' : 'R'} />
                           )}
@@ -1190,7 +1190,7 @@ function PrinterCard({
                             {ams.tray.map((tray, i) => (
                               <div key={i} className="flex items-start">
                                 <div className="flex flex-col">
-                                  <span className="text-bambu-gray/70 truncate">
+                                  <span className="text-bambu-gray/70 truncate max-w-[60px] sm:max-w-none">
                                     {tray.tray_type ? (tray.tray_sub_brands || tray.tray_type) : '—'}
                                   </span>
                                   <span className="text-bambu-gray/50 truncate">
@@ -1207,9 +1207,9 @@ function PrinterCard({
                             ))}
                           </div>
                         </div>
-                        {/* Humidity/temp - vertically centered */}
+                        {/* Humidity/temp - responsive positioning */}
                         {(ams.humidity != null || ams.temp != null) && (
-                          <div className="flex items-center gap-2 text-xs flex-shrink-0">
+                          <div className="flex items-center gap-2 text-xs flex-shrink-0 ml-auto">
                             {ams.humidity != null && (
                               <HumidityIndicator
                                 humidity={ams.humidity}

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
static/assets/index-BCPmsaqF.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
static/assets/index-CUXYdb1N.css


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
static/assets/index-Qli2bbsj.css


+ 2 - 2
static/index.html

@@ -23,8 +23,8 @@
 
     <!-- Splash screens for iOS -->
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
-    <script type="module" crossorigin src="/assets/index-Bzc6D_QS.js"></script>
-    <link rel="stylesheet" crossorigin href="/assets/index-Qli2bbsj.css">
+    <script type="module" crossorigin src="/assets/index-BCPmsaqF.js"></script>
+    <link rel="stylesheet" crossorigin href="/assets/index-CUXYdb1N.css">
   </head>
   <body>
     <div id="root"></div>

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff