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 <noreply@anthropic.com>
This commit is contained in:
Matt Johnson (via Claude) 2026-06-08 06:46:35 +00:00
commit 503c16db5e

View file

@ -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]