From 7dfa98dcc2b4ea44f9611ebe20f0cb618daf1c85 Mon Sep 17 00:00:00 2001 From: RNL Date: Thu, 25 Jun 2026 00:18:13 +1000 Subject: [PATCH] Fix AMS HT label: add info code 1104 variant and re-derive ams_type from stored info when snapshot value is blank. --- bambu_run/models.py | 3 ++- bambu_run/views.py | 27 +++++++++++++++------------ tests/test_filament_context.py | 4 ++-- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/bambu_run/models.py b/bambu_run/models.py index 85dbff3..171d95c 100644 --- a/bambu_run/models.py +++ b/bambu_run/models.py @@ -8,7 +8,8 @@ from django.utils import timezone AMS_INFO_TO_TYPE = { "1001": "AMS", "1003": "AMS 2 Pro", - "2104": "AMS HT", + "1104": "AMS HT", # observed on production H2C (last 4 of info code 11001104) + "2104": "AMS HT", # observed in dev capture (last 4 of info code 11002104) } AMS_TYPE_CHOICES = [ diff --git a/bambu_run/views.py b/bambu_run/views.py index fa37a22..bda32c4 100644 --- a/bambu_run/views.py +++ b/bambu_run/views.py @@ -159,27 +159,30 @@ class PrinterDashboardView(LoginRequiredMixin, TemplateView): except Exception: filaments_list = [] - # Distinct AMS units represented in this snapshot, for the unit - # filter/badges in the template. Sort numeric unit ids first - # (AMS / AMS 2 Pro), HT (id 128 / bit 0x80 set) last. + # Build a lookup from unit_id → AMS unit metadata (humidity, temp, info code) + # first so we can enrich blank ams_type values derived from old snapshots. + units_meta = { + u.get('unit_id'): u for u in (latest_metric.ams_units or []) + } + + # Distinct AMS units in this snapshot. ams_type stored on FilamentSnapshot + # may be blank for rows written before the multi-AMS deploy — fall back to + # re-deriving from the unit's info code so labels always show correctly. + from .models import ams_type_from_info as _ams_type_from_info seen_units = {} for f in filaments_list: uid = f.get('ams_unit_id') if uid is not None and uid not in seen_units: - seen_units[uid] = f.get('ams_type') or '' + label = f.get('ams_type') or '' + if not label: + unit_meta = units_meta.get(str(uid), {}) + label = _ams_type_from_info(unit_meta.get('info', '')) + seen_units[uid] = label ams_units_list = [ {'ams_unit_id': uid, 'ams_type': label} for uid, label in sorted(seen_units.items()) ] - # Group trays by physical AMS unit for the panel-style dashboard layout — - # one tinted panel per unit, full-width for multi-slot units (AMS/AMS 2 Pro), - # compact for single-slot units (AMS HT) so several can flow side-by-side. - # Filaments with ams_unit_id=None (pre-multi-AMS rows) fall into a single - # unlabelled group so they still render rather than being silently dropped. - units_meta = { - u.get('unit_id'): u for u in (latest_metric.ams_units or []) - } ams_groups = [] ungrouped = [f for f in filaments_list if f.get('ams_unit_id') is None] if ungrouped: diff --git a/tests/test_filament_context.py b/tests/test_filament_context.py index c4f9cd0..9cf3eda 100644 --- a/tests/test_filament_context.py +++ b/tests/test_filament_context.py @@ -157,8 +157,8 @@ def test_dashboard_renders_wide_and_compact_panels(logged_in_client): ) html = resp.content.decode() - assert "ams-group--wide" in html - assert "ams-group--compact" in html + assert "col-12 ams-group" in html # wide group: col-12 only + assert "col-lg-3 ams-group" in html # compact group: col-lg-3 assert "AMS 2 Pro (Unit 0)" in html assert "AMS HT (Unit 128)" in html