From 795ab84ef545a94d56f1b3775f7bc6453f8963f5 Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Sat, 28 Feb 2026 10:31:48 -0800 Subject: [PATCH] Fix 3.9 compatibility --- contact/message_handlers/rx_handler.py | 5 ++--- contact/utilities/telemetry_beautifier.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/contact/message_handlers/rx_handler.py b/contact/message_handlers/rx_handler.py index 4a9cfdf..148dc14 100644 --- a/contact/message_handlers/rx_handler.py +++ b/contact/message_handlers/rx_handler.py @@ -5,9 +5,10 @@ import shutil import time import subprocess import threading +from typing import Any, Dict, Optional # Debounce notification sounds so a burst of queued messages only plays once. _SOUND_DEBOUNCE_SECONDS = 0.8 -_sound_timer: threading.Timer | None = None +_sound_timer: Optional[threading.Timer] = None _sound_timer_lock = threading.Lock() _last_sound_request = 0.0 @@ -42,8 +43,6 @@ def schedule_notification_sound(delay: float = _SOUND_DEBOUNCE_SECONDS) -> None: _sound_timer = threading.Timer(delay, _fire, args=(now,)) _sound_timer.daemon = True _sound_timer.start() -from typing import Any, Dict - from contact.utilities.utils import ( refresh_node_list, add_new_message, diff --git a/contact/utilities/telemetry_beautifier.py b/contact/utilities/telemetry_beautifier.py index 720ff00..e0fa4b6 100644 --- a/contact/utilities/telemetry_beautifier.py +++ b/contact/utilities/telemetry_beautifier.py @@ -68,19 +68,19 @@ def get_chunks(data): # Leave it string as last resort value = value - match key: + # Python 3.9-compatible alternative to match/case. + if key == "uptime_seconds": # convert seconds to hours, for our sanity - case "uptime_seconds": - value = round(value / 60 / 60, 1) + value = round(value / 60 / 60, 1) + elif key in ("longitude_i", "latitude_i"): # Convert position to degrees (humanize), as per Meshtastic protobuf comment for this telemetry # truncate to 6th digit after floating point, which would be still accurate - case "longitude_i" | "latitude_i": - value = round(value * 1e-7, 6) + value = round(value * 1e-7, 6) + elif key == "wind_direction": # Convert wind direction from degrees to abbreviation - case "wind_direction": - value = humanize_wind_direction(value) - case "time": - value = datetime.datetime.fromtimestamp(int(value)).strftime("%d.%m.%Y %H:%m") + value = humanize_wind_direction(value) + elif key == "time": + value = datetime.datetime.fromtimestamp(int(value)).strftime("%d.%m.%Y %H:%m") if key in sensors: parsed+= f"{sensors[key.strip()]['icon']}{value}{sensors[key]['unit']} "