From d0e4734cf97d96fa8c41ee566fab7c28dc335d55 Mon Sep 17 00:00:00 2001 From: Logan Date: Tue, 21 Apr 2026 00:56:50 -0400 Subject: [PATCH] Linting + touches --- drb-edge-node/app/internal/call_recorder.py | 18 +++++++++--------- drb-edge-node/app/internal/config_manager.py | 1 - drb-edge-node/app/internal/discord_radio.py | 5 +++-- drb-edge-node/app/internal/mqtt_manager.py | 18 +++++++++--------- drb-edge-node/app/main.py | 5 ++++- icecast/Dockerfile | 1 + op25-container/Dockerfile | 2 +- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/drb-edge-node/app/internal/call_recorder.py b/drb-edge-node/app/internal/call_recorder.py index 0fd0848..5ba83d4 100644 --- a/drb-edge-node/app/internal/call_recorder.py +++ b/drb-edge-node/app/internal/call_recorder.py @@ -10,10 +10,10 @@ from app.config import settings from app.internal import credentials from app.internal.logger import logger -MAX_RECORDING_SECONDS = 600 # safety cap; drop call if it runs this long -PRE_BUFFER_SECONDS = 1.0 # seconds of audio to include before call_start -RING_BUFFER_SECONDS = 60 # how much history to keep when no call is active -READ_CHUNK_BYTES = 4096 # bytes per httpx read +MAX_RECORDING_SECONDS = 600 # safety cap; drop call if it runs this long +PRE_BUFFER_SECONDS = 1.0 # seconds of audio to include before call_start +RING_BUFFER_SECONDS = 60 # how much history to keep when no call is active +READ_CHUNK_BYTES = 4096 # bytes per httpx read class CallRecorder: @@ -119,9 +119,9 @@ class CallRecorder: if not self._call_id: return None - call_id = self._call_id - call_start = self._call_start_mono - self._call_id = None + call_id = self._call_id + call_start = self._call_start_mono + self._call_id = None self._call_start_mono = None # Slice: everything from (call_start - pre_buffer) to now @@ -180,8 +180,8 @@ class CallRecorder: return None upload_url = f"{settings.c2_url}/upload" - api_key = credentials.get_api_key() - headers = {"Authorization": f"Bearer {api_key}"} if api_key else {} + api_key = credentials.get_api_key() + headers = {"Authorization": f"Bearer {api_key}"} if api_key else {} form: dict = {"call_id": call_id, "node_id": settings.node_id} if talkgroup_id is not None: diff --git a/drb-edge-node/app/internal/config_manager.py b/drb-edge-node/app/internal/config_manager.py index 83cdeab..2d7b7bb 100644 --- a/drb-edge-node/app/internal/config_manager.py +++ b/drb-edge-node/app/internal/config_manager.py @@ -1,6 +1,5 @@ import json from pathlib import Path -from typing import Optional from app.config import settings from app.models import NodeConfig, SystemConfig from app.internal.logger import logger diff --git a/drb-edge-node/app/internal/discord_radio.py b/drb-edge-node/app/internal/discord_radio.py index f72c2a3..9f0a0bc 100644 --- a/drb-edge-node/app/internal/discord_radio.py +++ b/drb-edge-node/app/internal/discord_radio.py @@ -6,7 +6,7 @@ from app.internal.logger import logger BOT_READY_TIMEOUT = 15 # seconds to wait for Discord bot to become ready WATCHDOG_INTERVAL = 30 # seconds between voice-connection health checks -REJOIN_DELAY = 5 # seconds to wait before attempting a rejoin +REJOIN_DELAY = 5 # seconds to wait before attempting a rejoin class RadioBot: @@ -116,7 +116,8 @@ class RadioBot: def _on_stream_end(self, error): if error: logger.error(f"Stream ended with error: {error}") - if not (self._loop and self._voice_client and self._voice_client.is_connected() and not self._voice_client.is_playing()): + vc = self._voice_client + if not (self._loop and vc and vc.is_connected() and not vc.is_playing()): return if error: # Back off before retrying — prevents tight loop when PulseAudio is unavailable diff --git a/drb-edge-node/app/internal/mqtt_manager.py b/drb-edge-node/app/internal/mqtt_manager.py index 941eeb1..956afad 100644 --- a/drb-edge-node/app/internal/mqtt_manager.py +++ b/drb-edge-node/app/internal/mqtt_manager.py @@ -24,14 +24,14 @@ class MQTTManager: self.on_api_key: Optional[ApiKeyCallback] = None nid = settings.node_id - self._t_checkin = f"nodes/{nid}/checkin" - self._t_status = f"nodes/{nid}/status" - self._t_metadata = f"nodes/{nid}/metadata" - self._t_commands = f"nodes/{nid}/commands" - self._t_config = f"nodes/{nid}/config" - self._t_api_key = f"nodes/{nid}/api_key" + self._t_checkin = f"nodes/{nid}/checkin" + self._t_status = f"nodes/{nid}/status" + self._t_metadata = f"nodes/{nid}/metadata" + self._t_commands = f"nodes/{nid}/commands" + self._t_config = f"nodes/{nid}/config" + self._t_api_key = f"nodes/{nid}/api_key" self._t_key_request = f"nodes/{nid}/key_request" - self._t_discovery = "nodes/discovery/request" + self._t_discovery = "nodes/discovery/request" def _build_client(self) -> mqtt.Client: client = mqtt.Client( @@ -49,9 +49,9 @@ class MQTTManager: client.will_set(self._t_status, lwt, qos=1, retain=True) client.reconnect_delay_set(min_delay=2, max_delay=60) - client.on_connect = self._on_connect + client.on_connect = self._on_connect client.on_disconnect = self._on_disconnect - client.on_message = self._on_message + client.on_message = self._on_message return client def _on_connect(self, client, userdata, flags, reason_code, properties): diff --git a/drb-edge-node/app/main.py b/drb-edge-node/app/main.py index 635131a..795a8ff 100644 --- a/drb-edge-node/app/main.py +++ b/drb-edge-node/app/main.py @@ -44,7 +44,10 @@ async def on_call_end(data: dict): else: logger.error(f"Audio upload failed for call {data['call_id']}. Verify C2_URL and Node API Key.") else: - logger.warning(f"No recording file generated for call {data['call_id']} — call may have been too short or Icecast unreachable.") + logger.warning( + f"No recording file generated for call {data['call_id']} " + "— call may have been too short or Icecast unreachable." + ) await mqtt_manager.publish_metadata("call_end", data) await mqtt_manager.publish_status("online") diff --git a/icecast/Dockerfile b/icecast/Dockerfile index cbbc7af..9cf0e31 100644 --- a/icecast/Dockerfile +++ b/icecast/Dockerfile @@ -1,3 +1,4 @@ +# Icecast streaming server FROM debian:bookworm-slim ENV DEBIAN_FRONTEND=noninteractive diff --git a/op25-container/Dockerfile b/op25-container/Dockerfile index 59e0a23..1e4f63d 100644 --- a/op25-container/Dockerfile +++ b/op25-container/Dockerfile @@ -1,4 +1,4 @@ -## OP25 Core Container +# OP25 Core Container FROM python:slim-trixie # Set environment variables