From 503c16db5e5ea173507e6ffcb69a06cb261fe2eb Mon Sep 17 00:00:00 2001 From: "Matt Johnson (via Claude)" Date: Mon, 8 Jun 2026 06:46:35 +0000 Subject: [PATCH] nws: add _SAME_INSTRUCTION map and tighten instruction to 40-byte limit Short, actionable instructions keyed by SAME event code (TOR -> "Seek shelter immediately.", SVR -> "Move indoors now.", etc.). Falls back to the CAP instruction field when no SAME code matches. Truncates at 40 UTF-8 bytes to keep wire size compact for mesh broadcast. Co-Authored-By: Claude Opus 4.6 --- meshai/central/nws_handler.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/meshai/central/nws_handler.py b/meshai/central/nws_handler.py index ade56e5..2209858 100644 --- a/meshai/central/nws_handler.py +++ b/meshai/central/nws_handler.py @@ -73,6 +73,20 @@ _SAME_EMOJI = { "MAW": "🌊", "ADR": "⚠️", } +_SAME_INSTRUCTION = { + "TOR": "Seek shelter immediately.", + "SVR": "Move indoors now.", + "FFW": "Turn around, don't drown.", + "FLW": "Move to higher ground.", + "WSW": "Avoid travel if possible.", + "BZW": "Avoid travel.", + "EWW": "Secure outdoor objects.", + "HWW": "Secure outdoor objects.", + "FRW": "Evacuate if ordered.", + "SMW": "Move indoors now.", + "MAW": "Move away from water.", +} + _NWS_OFFICE_SHORT = { "KBOI": "Boise", "KPIH": "Pocatello", "KMSO": "Missoula", "KOTX": "Spokane", "KSLC": "Salt Lake City", "KMFR": "Medford", @@ -326,10 +340,10 @@ def _render(*, event_type, area_desc, geocoder_city, county, state, expires_seg = _format_expires_short(expires_epoch, now=now) if expires_epoch else "" line5 = f"Expires: {expires_seg}" if expires_seg else "" - # Line 6: instruction (max 80 chars) - instruction = (d.get("instruction") or "").strip() - if len(instruction) > 80: - instruction = instruction[:77] + "..." + # Line 6: instruction — prefer short SAME-keyed text, fall back to CAP field + instruction = _SAME_INSTRUCTION.get(same_code) or (d.get("instruction") or "").strip() + if len(instruction.encode("utf-8")) > 40: + instruction = instruction[:37] + "..." line6 = instruction lines = [l for l in (line1, line2, line3, line4, line5, line6) if l]