Fix AMS HT label: add info code 1104 variant and re-derive ams_type from stored info when snapshot value is blank.

This commit is contained in:
RNL
2026-06-25 00:18:13 +10:00
parent 0a1da46d1f
commit 7dfa98dcc2
3 changed files with 19 additions and 15 deletions

View File

@@ -8,7 +8,8 @@ from django.utils import timezone
AMS_INFO_TO_TYPE = { AMS_INFO_TO_TYPE = {
"1001": "AMS", "1001": "AMS",
"1003": "AMS 2 Pro", "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 = [ AMS_TYPE_CHOICES = [

View File

@@ -159,27 +159,30 @@ class PrinterDashboardView(LoginRequiredMixin, TemplateView):
except Exception: except Exception:
filaments_list = [] filaments_list = []
# Distinct AMS units represented in this snapshot, for the unit # Build a lookup from unit_id → AMS unit metadata (humidity, temp, info code)
# filter/badges in the template. Sort numeric unit ids first # first so we can enrich blank ams_type values derived from old snapshots.
# (AMS / AMS 2 Pro), HT (id 128 / bit 0x80 set) last. 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 = {} seen_units = {}
for f in filaments_list: for f in filaments_list:
uid = f.get('ams_unit_id') uid = f.get('ams_unit_id')
if uid is not None and uid not in seen_units: 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_units_list = [
{'ams_unit_id': uid, 'ams_type': label} {'ams_unit_id': uid, 'ams_type': label}
for uid, label in sorted(seen_units.items()) 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 = [] ams_groups = []
ungrouped = [f for f in filaments_list if f.get('ams_unit_id') is None] ungrouped = [f for f in filaments_list if f.get('ams_unit_id') is None]
if ungrouped: if ungrouped:

View File

@@ -157,8 +157,8 @@ def test_dashboard_renders_wide_and_compact_panels(logged_in_client):
) )
html = resp.content.decode() html = resp.content.decode()
assert "ams-group--wide" in html assert "col-12 ams-group" in html # wide group: col-12 only
assert "ams-group--compact" in html assert "col-lg-3 ams-group" in html # compact group: col-lg-3
assert "AMS 2 Pro (Unit 0)" in html assert "AMS 2 Pro (Unit 0)" in html
assert "AMS HT (Unit 128)" in html assert "AMS HT (Unit 128)" in html