fix: nws locations truncation — configurable word-boundary cap (default 120)

Replace hardcoded 40-char locations cap with adapter_config key
nws.locations_max_chars (default 120). Truncation now uses word-boundary
split with ellipsis, matching the swpc _trunc pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt Johnson (via Claude) 2026-06-10 02:23:22 +00:00
commit f5c1724567
2 changed files with 11 additions and 2 deletions

View file

@ -571,6 +571,11 @@ REGISTRY: dict[tuple[str, str], dict[str, Any]] = {
"type": "int",
"description": "Allow re-broadcast of the same CAP id after this many seconds (the nws_handler relaxes its dedup gate past this point and uses an Active: prefix).",
},
("nws", "locations_max_chars"): {
"default": 120,
"type": "int",
"description": "Maximum characters for the locations field on line 4 of NWS wire. Truncates at word boundary.",
},
# =================================================================
# AVALANCHE -- 1 setting (min danger level broadcast floor)

View file

@ -384,8 +384,12 @@ def _render(*, event_type, area_desc, geocoder_city, county, state,
compass, speed_mph = _parse_motion(params)
motion = f"Moving {compass} {speed_mph} mph" if compass and speed_mph else ""
locations = (desc.get("locations") or "").rstrip("., ")
if len(locations) > 40:
locations = locations[:37] + "..."
_loc_limit = int(adapter_config.nws.locations_max_chars)
if len(locations) > _loc_limit:
cut = locations[:_loc_limit].rsplit(" ", 1)[0]
if not cut:
cut = locations[:_loc_limit]
locations = cut + "\u2026"
if motion and locations:
line4 = f"{motion}{locations}"
elif motion: