mmrelay 1.1.2__py3-none-any.whl → 1.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mmrelay might be problematic. Click here for more details.

mmrelay/main.py CHANGED
@@ -15,6 +15,7 @@ from nio.events.room_events import RoomMemberEvent
15
15
  # Import version from package
16
16
  # Import meshtastic_utils as a module to set event_loop
17
17
  from mmrelay import __version__, meshtastic_utils
18
+ from mmrelay.constants.app import APP_DISPLAY_NAME, WINDOWS_PLATFORM
18
19
  from mmrelay.db_utils import (
19
20
  initialize_database,
20
21
  update_longnames,
@@ -27,10 +28,16 @@ from mmrelay.matrix_utils import logger as matrix_logger
27
28
  from mmrelay.matrix_utils import on_room_member, on_room_message
28
29
  from mmrelay.meshtastic_utils import connect_meshtastic
29
30
  from mmrelay.meshtastic_utils import logger as meshtastic_logger
31
+ from mmrelay.message_queue import (
32
+ DEFAULT_MESSAGE_DELAY,
33
+ get_message_queue,
34
+ start_message_queue,
35
+ stop_message_queue,
36
+ )
30
37
  from mmrelay.plugin_loader import load_plugins
31
38
 
32
39
  # Initialize logger
33
- logger = get_logger(name="M<>M Relay")
40
+ logger = get_logger(name=APP_DISPLAY_NAME)
34
41
 
35
42
  # Set the logging level for 'nio' to ERROR to suppress warnings
36
43
  logging.getLogger("nio").setLevel(logging.ERROR)
@@ -51,9 +58,9 @@ def print_banner():
51
58
 
52
59
  async def main(config):
53
60
  """
54
- Run the main asynchronous relay loop, managing connections between Meshtastic and Matrix, event handling, and graceful shutdown.
61
+ Coordinates the main asynchronous relay loop between Meshtastic and Matrix clients.
55
62
 
56
- Initializes the database, loads plugins, connects to Meshtastic and Matrix, joins configured Matrix rooms, and registers event callbacks for message and membership events. Periodically updates node names from the Meshtastic network and manages the Matrix sync loop, handling reconnections and shutdown signals. If configured, wipes the message map on both startup and shutdown.
63
+ Initializes the database, loads plugins, starts the message queue, and establishes connections to both Meshtastic and Matrix. Joins configured Matrix rooms, registers event callbacks for message and membership events, and periodically updates node names from the Meshtastic network. Monitors connection health, manages the Matrix sync loop with reconnection and shutdown handling, and ensures graceful shutdown of all components. Optionally wipes the message map on startup and shutdown if configured.
57
64
  """
58
65
  # Extract Matrix configuration
59
66
  from typing import List
@@ -90,6 +97,12 @@ async def main(config):
90
97
  # Load plugins early
91
98
  load_plugins(passed_config=config)
92
99
 
100
+ # Start message queue with configured message delay
101
+ message_delay = config.get("meshtastic", {}).get(
102
+ "message_delay", DEFAULT_MESSAGE_DELAY
103
+ )
104
+ start_message_queue(message_delay=message_delay)
105
+
93
106
  # Connect to Meshtastic
94
107
  meshtastic_utils.meshtastic_client = connect_meshtastic(passed_config=config)
95
108
 
@@ -121,7 +134,7 @@ async def main(config):
121
134
  loop = asyncio.get_running_loop()
122
135
 
123
136
  # Handle signals differently based on the platform
124
- if sys.platform != "win32":
137
+ if sys.platform != WINDOWS_PLATFORM:
125
138
  for sig in (signal.SIGINT, signal.SIGTERM):
126
139
  loop.add_signal_handler(sig, lambda: asyncio.create_task(shutdown()))
127
140
  else:
@@ -132,6 +145,9 @@ async def main(config):
132
145
  # This provides proactive connection detection for all interface types
133
146
  _ = asyncio.create_task(meshtastic_utils.check_connection())
134
147
 
148
+ # Ensure message queue processor is started now that event loop is running
149
+ get_message_queue().ensure_processor_started()
150
+
135
151
  # Start the Matrix client sync loop
136
152
  try:
137
153
  while not shutdown_event.is_set():
@@ -173,6 +189,9 @@ async def main(config):
173
189
  await shutdown()
174
190
  finally:
175
191
  # Cleanup
192
+ matrix_logger.info("Stopping message queue...")
193
+ stop_message_queue()
194
+
176
195
  matrix_logger.info("Closing Matrix client...")
177
196
  await matrix_client.close()
178
197
  if meshtastic_utils.meshtastic_client: