Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/api/BaseAPIWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ class BaseAPIWrapper(ABC):
auth_token: str | None

def __init__(self, base_url: str, auth_token: str = None):
self.base_url = base_url.rstrip('/')
self.base_url = base_url.rstrip("/")
self.auth_token = auth_token

def _get_headers(self) -> dict:
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
"Content-Type": "application/json",
"Accept": "application/json",
}
if self.auth_token:
headers['Authorization'] = f'Token {self.auth_token}'
headers["Authorization"] = f"Token {self.auth_token}"

return headers

Expand Down
8 changes: 6 additions & 2 deletions src/base_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def reply_in_channel(
"""Reply to ``message`` on the same channel it was received on."""
self.message_in_channel(message.channel, response, want_ack)

def message_in_channel(self, channel: int, response: str, want_ack: bool = False) -> None:
def message_in_channel(
self, channel: int, response: str, want_ack: bool = False
) -> None:
logging.debug("Sending message: '%s'", response)
self.bot.radio.send_text(
response,
Expand All @@ -57,7 +59,9 @@ def reply_in_dm(
) -> None:
self.message_in_dm(message.from_id, response, want_ack)

def message_in_dm(self, destination_id: str, response: str, want_ack: bool = False) -> None:
def message_in_dm(
self, destination_id: str, response: str, want_ack: bool = False
) -> None:
logging.debug("Sending DM: '%s'", response)
self.bot.radio.send_text(
response,
Expand Down
16 changes: 11 additions & 5 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
from src.persistence.packet_dump import dump_packet
from src.persistence.user_prefs import AbstractUserPrefsPersistence
from src.radio.errors import call_safely, get_global_error_counter
from src.radio.events import (ConnectionEstablished, IncomingPacket,
IncomingTextMessage, NodeUpdate)
from src.radio.events import (
ConnectionEstablished,
IncomingPacket,
IncomingTextMessage,
NodeUpdate,
)
from src.radio.interface import RadioHandlers, RadioInterface
from src.responders.responder_factory import ResponderFactory

Expand Down Expand Up @@ -93,9 +97,11 @@ def disconnect(self) -> None:

def on_apply_mc_channel_config(self, channels: list) -> None:
"""Handle apply_mc_channel_config from WebSocket (MeshCore feeders)."""
from src.meshcore.channel_sync import (apply_channels_on_device,
sync_channels_after_apply,
sync_channels_to_api)
from src.meshcore.channel_sync import (
apply_channels_on_device,
sync_channels_after_apply,
sync_channels_to_api,
)

if not hasattr(self.radio, "run_coroutine"):
logger.warning(
Expand Down
12 changes: 5 additions & 7 deletions src/commands/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from src.radio.events import IncomingTextMessage


def _rows_for_sender(rows: list[dict[str, Any]], sender_id: str) -> list[dict[str, Any]]:
def _rows_for_sender(
rows: list[dict[str, Any]], sender_id: str
) -> list[dict[str, Any]]:
return [r for r in rows if r["sender_id"] == sender_id]


Expand Down Expand Up @@ -42,9 +44,7 @@ def reset_packets(self, message: IncomingTextMessage, args: list[str]) -> None:
self.bot.node_info.reset_packets_today()
response = "Packet counter reset"
else:
response = (
f"reset: Unknown argument '{args[0]}' - options are: {available_options}"
)
response = f"reset: Unknown argument '{args[0]}' - options are: {available_options}"
self.reply(message, response)

def show_users(self, message: IncomingTextMessage, args: list[str]) -> None:
Expand All @@ -56,9 +56,7 @@ def show_users(self, message: IncomingTextMessage, args: list[str]) -> None:
return self._show_user(message, req_user)
return self._show_users(message)

def _show_user(
self, message: IncomingTextMessage, req_user: MeshNode.User
) -> None:
def _show_user(self, message: IncomingTextMessage, req_user: MeshNode.User) -> None:
since = datetime.now(timezone.utc) - timedelta(days=7)
since = since.replace(hour=0, minute=0, second=0, microsecond=0)

Expand Down
4 changes: 1 addition & 3 deletions src/commands/enroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def show_help(self, message: IncomingTextMessage, args: list[str]) -> None:
)
self.reply(message, response)

def enroll_testing(
self, message: IncomingTextMessage, args: list[str]
) -> None:
def enroll_testing(self, message: IncomingTextMessage, args: list[str]) -> None:
sender_id = message.from_id
user_prefs = self.bot.user_prefs_persistence.get_user_prefs(sender_id)
if user_prefs is None:
Expand Down
37 changes: 8 additions & 29 deletions src/commands/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,13 @@

class CommandFactory:
commands = {
"!ping": {
"class": "src.commands.ping.PingCommand",
"args": []
},
"!hello": {
"class": "src.commands.hello.HelloCommand",
"args": []
},
"!help": {
"class": "src.commands.help.HelpCommand",
"args": []
},
"!nodes": {
"class": "src.commands.nodes.NodesCommand",
"args": []
},
"!whoami": {
"class": "src.commands.template.WhoAmI",
"args": []
},
"!prefs": {
"class": "src.commands.prefs.PrefsCommandHandler",
"args": []
},
"!admin": {
"class": "src.commands.admin.AdminCommand",
"args": []
},
"!ping": {"class": "src.commands.ping.PingCommand", "args": []},
"!hello": {"class": "src.commands.hello.HelloCommand", "args": []},
"!help": {"class": "src.commands.help.HelpCommand", "args": []},
"!nodes": {"class": "src.commands.nodes.NodesCommand", "args": []},
"!whoami": {"class": "src.commands.template.WhoAmI", "args": []},
"!prefs": {"class": "src.commands.prefs.PrefsCommandHandler", "args": []},
"!admin": {"class": "src.commands.admin.AdminCommand", "args": []},
# "!enroll": {
# "class": "src.commands.enroll.EnrollCommandHandler",
# "args": ["enroll"]
Expand All @@ -45,7 +24,7 @@ class CommandFactory:
def create_command(command_name, bot):
command_info = CommandFactory.commands.get(command_name)
if command_info:
module_name, class_name = command_info["class"].rsplit('.', 1)
module_name, class_name = command_info["class"].rsplit(".", 1)
module = importlib.import_module(module_name)
command_class = getattr(module, class_name)
args = [bot] + command_info["args"]
Expand Down
4 changes: 1 addition & 3 deletions src/commands/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def send_busy_node_list(self, sender: str) -> None:
packets_today = self.bot.node_info.get_node_packets_today(node.id)
response += f"- {node.short_name} ({packets_today} pkts)\n"

response += (
f"(last reset at {self.bot.node_info.packet_counter_reset_time.strftime('%H:%M:%S')})"
)
response += f"(last reset at {self.bot.node_info.packet_counter_reset_time.strftime('%H:%M:%S')})"
self.reply_to(sender, response)

def send_detailed_nodeinfo(self, sender: str, node_id: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def pretty_print_last_heard(last_heard_timestamp: int | datetime | None) -> str:


def safe_encode_node_name(name):
return ''.join(c if c in _safe_chars else urllib.parse.quote(c) for c in name)
return "".join(c if c in _safe_chars else urllib.parse.quote(c) for c in name)
1 change: 1 addition & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
logging.getLogger("mesh_interface").setLevel(logging.WARNING)

from src.api.packet_serializer import PacketSerializer

# Now we can import the rest of our local files
from src.api.StorageAPI import StorageAPIWrapper
from src.bot import MeshflowBot
Expand Down
7 changes: 5 additions & 2 deletions src/meshcore/channel_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

CHANNEL_READ_DELAY_S = 2.0

from src.meshcore.channels import (log_device_channels, read_device_channels,
snapshot_sync_body)
from src.meshcore.channels import (
log_device_channels,
read_device_channels,
snapshot_sync_body,
)

if TYPE_CHECKING:
from src.api.StorageAPI import StorageAPIWrapper
Expand Down
11 changes: 6 additions & 5 deletions src/meshcore/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
from meshcore import MeshCore
from meshcore.events import Event, EventType
from src.meshcore.dump import dump_meshcore_event
from src.meshcore.translation import (event_to_incoming_packet,
event_to_node_update,
event_to_text_message)
from src.meshcore.translation import (
event_to_incoming_packet,
event_to_node_update,
event_to_text_message,
)
from src.radio.errors import RadioError, call_safely, get_global_error_counter
from src.radio.events import ConnectionEstablished
from src.radio.interface import RadioHandlers, RadioInterface
Expand Down Expand Up @@ -411,8 +413,7 @@ def schedule_channel_sync(
return

async def _task() -> None:
from src.meshcore.channel_sync import \
sync_channels_to_storage_apis_async
from src.meshcore.channel_sync import sync_channels_to_storage_apis_async

labels = [str(getattr(s, "base_url", "?")) for s in storage_apis]
logger.info(
Expand Down
16 changes: 12 additions & 4 deletions src/meshtastic/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def connect(self) -> None:
packet_queue=old_packet_queue,
)

logger.info("MeshtasticRadio: TCP interface created; awaiting library connect event")
logger.info(
"MeshtasticRadio: TCP interface created; awaiting library connect event"
)

def disconnect(self) -> None:
self._is_connected = False
Expand Down Expand Up @@ -111,7 +113,9 @@ def send_text(
kwargs["destinationId"] = destination_id
if hop_limit is not None:
kwargs["hopLimit"] = hop_limit
logger.debug("MeshtasticRadio: send_text dest=%s ch=%s", destination_id, channel)
logger.debug(
"MeshtasticRadio: send_text dest=%s ch=%s", destination_id, channel
)
self._interface.sendText(text, **kwargs)

def send_reaction(
Expand All @@ -137,7 +141,9 @@ def send_traceroute(
channel_index: int = 0,
) -> None:
if not self._interface or not self._is_connected:
logger.warning("MeshtasticRadio: send_traceroute called before connect; skipping")
logger.warning(
"MeshtasticRadio: send_traceroute called before connect; skipping"
)
return
_send_traceroute(self._interface, target_node_id, channel_index=channel_index)

Expand All @@ -149,7 +155,9 @@ def _ensure_pubsub_subscribed(self) -> None:
pub.subscribe(self._on_receive, "meshtastic.receive")
pub.subscribe(self._on_receive_text, "meshtastic.receive.text")
pub.subscribe(self._on_node_updated, "meshtastic.node.updated")
pub.subscribe(self._on_connection_established, "meshtastic.connection.established")
pub.subscribe(
self._on_connection_established, "meshtastic.connection.established"
)
self._pubsub_subscribed = True

def _require_interface(self) -> None:
Expand Down
Loading