mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-09-01 16:48:26 +00:00
Correctness:
- {path_distance} was always blank in production. The resolution code that
builds repeater_info dropped latitude/longitude in every branch, so the
calculator could never find a coordinate. My tests passed hand-built
dicts straight to the calculator and never exercised the builder, which
is why they stayed green. Coordinates are now carried through all four
construction sites, and the new tests drive _lookup_repeater_names via
its lookup_func hook so the real builder runs.
- The #80 route guard was defeated two ways in the channel handler. When
the RF data was an uncorrelated fallback, control fell through to the
raw-hex and routing_info fallbacks below, which took the route from the
unrelated packet anyway; the guard had actually made that path
reachable. message.routing_info was also assigned unconditionally, and
the path command reads it. "Not attributable" is now a terminal branch
and the routing_info hand-off checks provenance.
- Same fix was incomplete for DMs: routing_info was captured and turned
into path_info before the provenance check ran, so the later check only
declined to overwrite an already-wrong value. Guarded at the source.
- Rendering could transmit for real. Capture only intercepts
send_response, but advert calls send_advert() directly and
send_response_chunked never checked capture_sink. Chunked sends are now
captured, and rendering is opt-in via BaseCommand.render_safe (default
False) instead of a denylist that cannot be complete. This also closes
the DM-only leak: schedule is not marked safe, so {cmd:schedule} can no
longer broadcast configuration to a channel.
- Multi-part rendered output was rejoined into one oversized send.
Scheduled messages are now split to the RF body budget and sent through
send_channel_messages_chunked, on character boundaries so multi-byte
text is not corrupted.
- _last_path_distance_km is instance state that was only set on success,
so an invalid path request could show the previous request's distance.
Reset at the start of every execute().
- Stale-contact retries were only counted on non-OK results, so timeouts
and exceptions left a contact eligible forever and could recreate the
storm. All failed attempts count now.
Web viewer:
- A failed config reload was reported as a successful save. The API and
UI now distinguish "saved and active" from "saved, restart needed".
- Preview count was unbounded; clamped to 1-20.
- update_ini_values is a read-modify-replace with no locking, so two
concurrent viewer saves could lose one. Serialised behind a lock.
82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
HF Conditions Command - Provides HF band conditions for ham radio
|
|
"""
|
|
|
|
from ..models import MeshMessage
|
|
from ..solar_conditions import hf_band_conditions
|
|
from .base_command import BaseCommand
|
|
|
|
|
|
class HfcondCommand(BaseCommand):
|
|
"""Command to get HF band conditions.
|
|
|
|
Retrieves and displays propagation conditions for High Frequency (HF) bands,
|
|
useful for amateur radio operators.
|
|
"""
|
|
|
|
# Plugin metadata
|
|
# Read-only informational output; safe for scheduled {cmd:...} rendering.
|
|
render_safe = True
|
|
name = "hfcond"
|
|
keywords = ['hfcond']
|
|
description = "Get HF band conditions for ham radio"
|
|
category = "solar"
|
|
requires_internet = True # Requires internet access for hamqsl.com API
|
|
|
|
# Documentation
|
|
short_description = "Get HF band conditions for ham radio"
|
|
usage = "hfcond"
|
|
examples = ["hfcond"]
|
|
|
|
def __init__(self, bot):
|
|
"""Initialize the hfcond command.
|
|
|
|
Args:
|
|
bot: The MeshCoreBot instance.
|
|
"""
|
|
super().__init__(bot)
|
|
self.hfcond_enabled = self.get_config_value('Hfcond_Command', 'enabled', fallback=True, value_type='bool')
|
|
|
|
def can_execute(self, message: MeshMessage, skip_channel_check: bool = False) -> bool:
|
|
"""Check if this command can be executed with the given message.
|
|
|
|
Args:
|
|
message: The message triggering the command.
|
|
|
|
Returns:
|
|
bool: True if command is enabled and checks pass, False otherwise.
|
|
"""
|
|
if not self.hfcond_enabled:
|
|
return False
|
|
return super().can_execute(message)
|
|
|
|
async def execute(self, message: MeshMessage) -> bool:
|
|
"""Execute the hfcond command.
|
|
|
|
Args:
|
|
message: The message that triggered the command.
|
|
|
|
Returns:
|
|
bool: True if executed successfully, False otherwise.
|
|
"""
|
|
try:
|
|
# Get HF band conditions
|
|
hf_info = hf_band_conditions()
|
|
|
|
# Send response using unified method
|
|
response = self.translate('commands.hfcond.header', info=hf_info)
|
|
return await self.send_response(message, response)
|
|
|
|
except Exception as e:
|
|
error_msg = self.translate('commands.hfcond.error', error=str(e))
|
|
return await self.send_response(message, error_msg)
|
|
|
|
def get_help_text(self) -> str:
|
|
"""Get help text for this command.
|
|
|
|
Returns:
|
|
str: The help text for this command.
|
|
"""
|
|
return self.translate('commands.hfcond.help')
|