Fix channel nomenclature

This commit is contained in:
Logan Cusano
2025-04-27 02:25:00 -04:00
parent 386df10fe6
commit 3871ee5970
3 changed files with 39 additions and 38 deletions

View File

@@ -3,7 +3,8 @@ import websockets
import json
import uuid
import os
from drb_cdb_api import DRBCDBAPI, ConfigGenerator
from drb_cdb_api import DRBCDBAPI
from drb_cdb_types import ConfigGenerator
from server_api import RadioAPIClient
from enum import Enum
@@ -58,21 +59,21 @@ async def join_server(system_id, guild_id, channel_id):
op25_status = await drb_api.get_op25_status()
print("OP25 status:", op25_status)
# Check if OP25 is stopped, if so set the selected channel, otherwise
# Check if OP25 is stopped, if so set the selected system, otherwise do nothing
if 'status' not in op25_status or op25_status['status'] == "stopped":
chn_details = await srv_api.get_channel_details(channel_id)
print("Channel details", chn_details)
if not chn_details:
sys_details = await srv_api.get_system_details(system_id)
print("System details:", sys_details)
if not sys_details:
# TODO - handle not having channel details
pass
# Generate the config for the channel requested
chn_config = ConfigGenerator(
type=chn_details['decode_mode'],
systemName=chn_details['name'],
channels=chn_details['frequency_list_khz'],
tags=chn_details['tags'],
whitelist=chn_details['tag_whitelist'])
type=sys_details['decode_mode'],
systemName=sys_details['name'],
frequencys=sys_details['frequency_list_khz'],
tags=sys_details['tags'],
whitelist=sys_details['tag_whitelist'])
# Set the OP25 config
drb_api.generate_op25_config(chn_config)
@@ -85,7 +86,7 @@ async def join_server(system_id, guild_id, channel_id):
async def leave_server(guild_id):
# Takes guild ID
bot_status = await drb_api.get_bot_status()
print("Bot status", bot_status)
print("Bot status:", bot_status)
# Check if the bot is running
if 'bot_running' not in bot_status or not bot_status['bot_running']:

View File

@@ -22,13 +22,13 @@ class ConfigGenerator:
self,
type: DecodeMode,
systemName: str,
channels: List[str],
frequencys: List[str],
tags: Optional[List[TalkgroupTag]] = None,
whitelist: Optional[List[int]] = None
):
self.type = type
self.systemName = systemName
self.channels = channels
self.frequencys = frequencys
self.tags = tags
self.whitelist = whitelist
@@ -37,7 +37,7 @@ class ConfigGenerator:
data = {
"type": self.type.value, # Use .value for Enum
"systemName": self.systemName,
"channels": self.channels,
"frequencys": self.frequencys,
}
if self.tags is not None:
# Convert list of TalkgroupTag objects to list of dictionaries

View File

@@ -35,7 +35,7 @@ class RadioAPIClient:
Args:
method (str): The HTTP method (e.g., 'GET', 'POST').
endpoint (str): The API endpoint path (e.g., '/channels').
endpoint (str): The API endpoint path (e.g., '/systems').
**kwargs: Additional arguments for httpx.AsyncClient.request.
Returns:
@@ -58,31 +58,31 @@ class RadioAPIClient:
print(f"An error occurred while requesting {e.request.url!r}: {e}")
raise
async def get_channels(self):
async def get_systems(self):
"""
Retrieves a summary list of all available radio channels.
Retrieves a summary list of all available radio systems.
Returns:
list: A list of channel summaries (e.g., [{"id": "channel_1", "name": "..."}]).
list: A list of system summaries (e.g., [{"id": "system_1", "name": "..."}]).
"""
print(f"Fetching channels from {self.base_url}/channels")
return await self._request("GET", "/channels")
print(f"Fetching systems from {self.base_url}/systems")
return await self._request("GET", "/systems")
async def get_channel_details(self, channel_id: str):
async def get_system_details(self, system_id: str):
"""
Retrieves detailed information for a specific channel.
Retrieves detailed information for a specific system.
Args:
channel_id (str): The unique ID of the channel.
system_id (str): The unique ID of the system.
Returns:
dict: The channel details.
dict: The system details.
Raises:
httpx.HTTPStatusError: If the channel is not found (404).
httpx.HTTPStatusError: If the system is not found (404).
"""
print(f"Fetching details for channel: {channel_id} from {self.base_url}/channels/{channel_id}")
return await self._request("GET", f"/channels/{channel_id}")
print(f"Fetching details for system: {system_id} from {self.base_url}/systems/{system_id}")
return await self._request("GET", f"/systems/{system_id}")
async def list_clients(self):
"""
@@ -132,26 +132,26 @@ async def example_api_usage():
async with RadioAPIClient("http://localhost:5000") as api_client:
print("\n--- Getting Channels ---")
try:
channels_summary = await api_client.get_channels()
print("Channels Summary:", channels_summary)
systems_summary = await api_client.get_systems()
print("Channels Summary:", systems_summary)
except Exception as e:
print(f"Error getting channels: {e}")
print(f"Error getting systems: {e}")
print("\n--- Getting Channel Details (channel_1) ---")
print("\n--- Getting Channel Details (system_1) ---")
try:
channel_details = await api_client.get_channel_details("channel_1")
print("Channel 1 Details:", channel_details)
system_details = await api_client.get_system_details("system_1")
print("Channel 1 Details:", system_details)
except Exception as e:
print(f"Error getting channel details: {e}")
print(f"Error getting system details: {e}")
print("\n--- Getting Channel Details (non-existent) ---")
try:
non_existent_channel = await api_client.get_channel_details("non_existent_channel")
print("Non-existent Channel Details:", non_existent_channel) # This should not print
non_existent_system = await api_client.get_system_details("non_existent_system")
print("Non-existent Channel Details:", non_existent_system) # This should not print
except httpx.HTTPStatusError as e:
print(f"Caught expected error for non-existent channel: {e.response.status_code} - {e.response.json()}")
print(f"Caught expected error for non-existent system: {e.response.status_code} - {e.response.json()}")
except Exception as e:
print(f"Error getting non-existent channel details: {e}")
print(f"Error getting non-existent system details: {e}")
print("\n--- Listing Connected Clients ---")