No description
Find a file
Jeremiah K ea6715f18a
Some checks failed
Tests and Coverage / test (3.10) (push) Has been cancelled
Tests and Coverage / test (3.11) (push) Has been cancelled
Tests and Coverage / test (3.12) (push) Has been cancelled
Add type hints and return type annotations throughout codebase, extend tests & address uncovered bugs (#387)
* refactor: add type annotations to utility functions

* refactor: add type annotations to plugins and utilities

* refactor(plugins): add type annotations to plugins and database manager

Add comprehensive type hints and annotations across plugins (map, nodes, telemetry, weather) and the database runtime module to improve type safety, code clarity, and IDE support. Includes handling of optional values and protocol definitions for better static analysis.

* refactor(linting): fix type issues and linting errors

- Remove unused imports (typing.List, meshtastic.protobuf.portnums_pb2)
- Fix lambda function type annotations in matrix_utils.py
- Format code with black/isort to pass trunk checks
- Clean up E2EE import structure in cli.py

* refactor(linting): fix type ignores and code cleanup issues

* fix(base_plugin): correct get_my_node_id caching logic

Change hasattr check to None check since _my_node_id is always
initialized in __init__. This ensures proper caching behavior
and fixes failing tests where get_my_node_id returns None.

* fix(base_plugin): handle deleted _my_node_id in tests

Add hasattr check before accessing _my_node_id to handle test cases
that explicitly delete the attribute to simulate no-cache state.

* refactor(linting): remove type ignore comments and update type annotations

- Remove `# type: ignore[no-untyped-call]` comments from function calls across multiple modules
- Update type annotations, such as changing `List` to `list` and parameter types in plugins
- Fix variable naming in logging and add unused variable handling in plugin callbacks
- Clean up imports and docstrings for consistency and linting compliance

* refactor(linting): remove type ignore comments and update type annotations

- Remove unnecessary type ignore comments across multiple modules
- Update function signatures to use specific types like E2EEStatus
- Clean up code formatting and minor refactoring in CLI and plugin utilities
- Improve type safety without changing functionality

* fix(plugin_loader): remove unnecessary module execution in plugin loading

* refactor(linting): remove type ignore comments and update type annotations

- Replace type ignore comments with explicit cast() calls in db_utils.py
- Update Callable type annotations in message_queue.py
- Add missing imports and refine type hints in plugin_loader.py
- Change import ignore comment in mesh_relay_plugin.py

* 📝 Add docstrings to `maint-12-1` (#388)

Docstrings generation was requested by @jeremiah-k.

* https://github.com/jeremiah-k/meshtastic-matrix-relay/pull/387#issuecomment-3706484555

The following files were modified:

* `src/mmrelay/cli.py`
* `src/mmrelay/cli_utils.py`
* `src/mmrelay/config.py`
* `src/mmrelay/db_utils.py`
* `src/mmrelay/e2ee_utils.py`
* `src/mmrelay/log_utils.py`
* `src/mmrelay/main.py`
* `src/mmrelay/matrix_utils.py`
* `src/mmrelay/meshtastic_utils.py`
* `src/mmrelay/message_queue.py`
* `src/mmrelay/plugin_loader.py`
* `src/mmrelay/plugins/base_plugin.py`
* `src/mmrelay/plugins/debug_plugin.py`
* `src/mmrelay/plugins/drop_plugin.py`
* `src/mmrelay/plugins/health_plugin.py`
* `src/mmrelay/plugins/help_plugin.py`
* `src/mmrelay/plugins/map_plugin.py`
* `src/mmrelay/plugins/mesh_relay_plugin.py`
* `src/mmrelay/plugins/nodes_plugin.py`
* `src/mmrelay/plugins/ping_plugin.py`
* `src/mmrelay/plugins/telemetry_plugin.py`
* `src/mmrelay/plugins/weather_plugin.py`
* `src/mmrelay/setup_utils.py`
* `src/mmrelay/tools/__init__.py`

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* refactor(linting): remove type ignore comments and update type annotations

* style: add trailing newlines to source files

* refactor(linting): update type annotations and improve docstrings

- Add return type annotation to `is_service_enabled()` in setup_utils.py
- Update type ignore comments in ping_plugin.py
- Refine docstring wording and add comments in debug_plugin.py and nodes_plugin.py
- Change docstring to raw string in health_plugin.py

* refactor(matrix_utils): improve code formatting and add E2EE status storage on client

- Reformat lambda functions and global statements for better readability
- Simplify exception handling in alias resolution
- Store E2EE status on matrix_client for access by other functions

* docs(db_utils): update delete_plugin_data docstring

* refactor(linting): remove type ignore comments and add type casts

- Removed `# type: ignore[...]` comments from imports and function calls across multiple modules
- Added explicit `cast()` calls to improve type safety and resolve mypy issues
- Updated import statements to remove unnecessary type ignore annotations

This refactoring enhances code maintainability and type checking without altering functionality.

* refactor(types): update type annotations and remove linting comments

- Remove noqa comments from imports in cli.py
- Add Awaitable type hint and improve resolver function signature in matrix_utils.py
- Update type annotations for config parameters and add config_override support
- Enhance prefix format handling with null checks
- Improve logout_others parameter handling in login_matrix_bot
- Update meshnet_name usage in matrix_relay for better relay support
- Refactor plugin data methods in base_plugin.py to use helper function
- Add unused variable assignments in drop_plugin.py for consistency
- Improve matrix_rooms config handling in mesh_relay_plugin.py
- Adjust service status output in setup_utils.py to handle errors gracefully

These changes enhance code maintainability and type safety without altering functionality.

* refactor(mmrelay): optimize message storage config retrieval

Move msgs_to_keep config retrieval outside the try block in matrix_relay to avoid redundant calls.

Update tests in test_setup_utils.py and test_setup_utils_systemctl.py to use check=False and mock OSError for better error handling in systemctl status checks.

* refactor(plugins): improve error handling and code deduplication in E2EE checks and mesh relay plugin

- Add helper function for E2EE dependency checks to reduce duplication in CLI
- Enhance packet validation and error logging in mesh relay plugin
- Update debug messages and test assertions for consistency
- Fix minor docstring formatting in matrix utils

* refactor(mmrelay): update imports and type annotations for better compatibility

- Use importlib for dynamic optional imports in CLI to improve error handling
- Modernize type hints from Union to | syntax in matrix_utils
- Remove unused Union import and type ignore comments
- Add packet ID initialization in mesh relay plugin
- Fix en-dash to hyphen in Windows utils docstring

* refactor(mmrelay): update type annotations and error handling for better type checking

- Add type ignore comments for untyped imports in matrix_utils.py and plugins
- Simplify exception logging in mesh relay plugin
- Update testing guide with mypy type checking instructions

Addresses compatibility issues with strict type checking and improves code maintainability.

* refactor(mmrelay): update imports and type annotations for mypy strict compliance

- Reorganize nio exception and response imports with type ignores to align with mypy --strict requirements
- Add clarifying comments for untyped imports and private API usage
- Update documentation code block syntax for consistency

* refactor(mmrelay): update type annotations and imports for mypy strict compliance

- Refine handle_room_message method signatures in base_plugin and all plugins to use specific Matrix event types instead of generic Any/dict
- Group nio imports with type ignore comments to reduce mypy noise
- Add error handling for meshtastic_id normalization in matrix_utils
- Extract room config iteration logic in mesh_relay_plugin for better maintainability

This change improves type safety and static analysis without altering functionality.

* refactor(mmrelay): improve reply handling and import organization

Consolidate nio imports into grouped statements with type ignores for mypy strict compliance.
Enhance handle_matrix_reply to send broadcast replies instead of failing when meshtastic_id is non-numeric,
preserving compatibility and preventing lost replies. Update logging to reflect new behavior.

* refactor(mmrelay): update type annotations and parameter naming for mypy strict compliance

- Reorganize imports in matrix_utils.py and cli.py for better mypy alignment
- Add type checking and error handling in map_plugin.py and mesh_relay_plugin.py
- Normalize data storage in base_plugin.py to handle various input types
- Rename unused parameters in plugin handlers to avoid mypy warnings
- Improve reply handling in matrix_utils.py to prefer original meshnet name

* refactor(mmrelay): update parameter naming and imports for mypy strict compliance

- Grouped nio imports in matrix_utils.py to reduce mypy unused-ignore noise
- Removed underscores from unused parameters in plugin handlers for consistency
- Added mock checks and compatibility comments to maintain test functionality
- Ensured type annotations align with strict mypy requirements across plugins

* refactor(mmrelay): update parameter naming and imports for mypy strict compliance

- Rename unused parameters in plugin handlers to avoid mypy warnings while maintaining test compatibility
- Reorganize and group nio exception imports in matrix_utils.py for clarity and strict mypy compliance
- Add comprehensive test cases for edge cases, error handling, and new functionality in plugins and utilities
- Ensure import fallbacks and type annotations align with strict mypy requirements across modules

These changes continue the ongoing effort to achieve full mypy --strict compliance, improving code quality and type safety without altering runtime behavior. New tests enhance coverage for previously untested paths, particularly around client availability, payload validation, and import error handling.

* refactor(mmrelay): update comments, imports, and code for mypy strict compliance

- Standardize import-untyped comments for matrix-nio across all files
- Refactor _iter_room_alias_entries to use helper functions for setters
- Improve type checking in _get_msgs_to_keep_config with explicit dict checks
- Simplify telemetry data extraction in telemetry_plugin
- Update low battery threshold to <= 10% in health_plugin and tests
- Rename mock parameters in test_main for consistency

* refactor(mmrelay): update imports, type checks, and tests for mypy strict compliance

- Reorganize and group imports in matrix_utils.py with type ignore comments
- Refactor scheduler variable handling in plugin_loader.py to avoid races
- Simplify node data normalization in base_plugin.py by removing Sequence handling
- Streamline staticmaps image casting in map_plugin.py
- Add unused variable assignment in nodes_plugin.py
- Update test mocks in test_matrix_utils.py to use AsyncMock for async functions

* refactor(mmrelay): update type annotations, imports, and code for mypy strict compliance

- Enhance import grouping and type ignores in matrix_utils.py for cleaner mypy handling
- Add NoReturn annotation and fix variable reference in plugin_loader.py
- Improve map centering logic and type annotations in map_plugin.py
- Refine config handling in mesh_relay_plugin.py
- Add timeout test case in test_matrix_utils.py

* refactor(mmrelay): update imports, comments, and tests for mypy strict compliance

- Grouped and simplified nio exception/response imports in matrix_utils.py
- Added helper function for config retrieval to reduce duplication
- Updated comments to avoid mypy unused-ignore warnings
- Preserved parameter names in plugin callbacks for API compatibility
- Added new test cases for dict normalization and room config filtering
- Removed obsolete timeout test and added dependency install retry test
- Ensured import-time wiring for nio exceptions in tests

* refactor(mmrelay): update code and tests for mypy strict compliance

- Simplify boolean return in drop plugin
- Update variable reference in drop plugin
- Enhance docstring parameters in drop plugin
- Add mock return value and assertions in matrix utils tests
- Add patches and logging assertions in plugin loader tests

* test(matrix_utils): add assertions to verify mock calls in tests

- Add assert_called_once for mock_get_interface and mock_queue in test_send_reply_to_meshtastic_defaults_config_when_missing
- Update call_args unpacking to ignore kwargs in test_on_room_message_creates_mapping_info

* Fix: Alias plugins.base_plugin to prevent double-loading and config reset

* Compat: Support synchronous plugins in message handlers for parity with main

* refactor(mmrelay): update code formatting and test assertions

- Format global variable declarations in matrix_utils.py for readability
- Simplify exception handling in alias resolution
- Add inspect import for potential mypy compliance
- Update test assertion in meshtastic message paths to verify plugin call instead of logger warning

* fix(mmrelay): handle missing telemetry metrics and improve client cleanup

- Store None for missing telemetry fields instead of default 0 to preserve data integrity
- Add None check before appending telemetry values in averaging logic
- Initialize temp_client to None and check before closing in logout function
- Update tests to assert None for missing metrics and use context managers for patches
- Adjust comment indentation in plugin loader for consistency

* refactor(mmrelay): improve error handling and function return types

- Enhance logout error logging in cli_utils.py for better diagnostics
- Update send_reply_to_meshtastic to return bool indicating success
- Simplify exception handling and reformat globals in matrix_utils.py
- Rename variables for clarity in plugin_loader.py
- Adjust telemetry plugin to use method for command list

BREAKING CHANGE: send_reply_to_meshtastic now returns bool instead of None, callers must handle the return value

* 📝 Add docstrings to `maint-12-2` (#390)

Docstrings generation was requested by @jeremiah-k.

* https://github.com/jeremiah-k/meshtastic-matrix-relay/pull/389#issuecomment-3707991591

The following files were modified:

* `src/mmrelay/cli.py`
* `src/mmrelay/cli_utils.py`
* `src/mmrelay/config.py`
* `src/mmrelay/db_utils.py`
* `src/mmrelay/log_utils.py`
* `src/mmrelay/main.py`
* `src/mmrelay/matrix_utils.py`
* `src/mmrelay/meshtastic_utils.py`
* `src/mmrelay/message_queue.py`
* `src/mmrelay/plugin_loader.py`
* `src/mmrelay/plugins/base_plugin.py`
* `src/mmrelay/plugins/debug_plugin.py`
* `src/mmrelay/plugins/drop_plugin.py`
* `src/mmrelay/plugins/health_plugin.py`
* `src/mmrelay/plugins/help_plugin.py`
* `src/mmrelay/plugins/map_plugin.py`
* `src/mmrelay/plugins/mesh_relay_plugin.py`
* `src/mmrelay/plugins/nodes_plugin.py`
* `src/mmrelay/plugins/ping_plugin.py`
* `src/mmrelay/plugins/telemetry_plugin.py`
* `src/mmrelay/plugins/weather_plugin.py`
* `src/mmrelay/setup_utils.py`
* `src/mmrelay/tools/__init__.py`
* `src/mmrelay/windows_utils.py`
* `tests/test_main.py`
* `tests/test_mesh_relay_plugin.py`
* `tests/test_meshtastic_utils.py`
* `tests/test_message_queue.py`
* `tests/test_plugin_loader.py`
* `tests/test_plugin_loader_edge_cases.py`
* `tests/test_telemetry_plugin.py`

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* style: fix code formatting and whitespace consistency

- Remove trailing spaces from docstrings and code lines
- Adjust indentation in docstrings for consistency
- Ensure consistent spacing in function definitions and comments
- Remove trailing newlines at end of files where present
- Minor import reordering for better organization

These changes improve code readability and maintain style consistency across the codebase.

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-01-04 06:12:59 -06:00
.devcontainer Trunk fixes 2025-03-14 16:05:52 -05:00
.github deps: bump actions/cache from 4 to 5 (#374) 2025-12-26 10:26:40 -06:00
.trunk Improve matrix_utils.py test coverage (#383) 2025-12-31 10:50:50 -06:00
docs Add type hints and return type annotations throughout codebase, extend tests & address uncovered bugs (#387) 2026-01-04 06:12:59 -06:00
scripts Refactor: Core async improvements, Windows support, and general maintenance (#296) 2025-09-21 14:24:53 -05:00
src/mmrelay Add type hints and return type annotations throughout codebase, extend tests & address uncovered bugs (#387) 2026-01-04 06:12:59 -06:00
tests Add type hints and return type annotations throughout codebase, extend tests & address uncovered bugs (#387) 2026-01-04 06:12:59 -06:00
.coderabbit.yml Refactor signal handling with fire-and-forget utility (#377) 2025-12-26 08:43:53 -06:00
.coveragerc Matrix E2EE Support (#154) 2025-08-22 15:51:19 -05:00
.dockerignore Add Complete Docker Support and Improved Disconnection Detection (#199) 2025-07-08 08:00:23 -05:00
.gitignore Fix Coverage Components and Test Warnings (#243) 2025-08-06 07:32:36 -05:00
AGENTS.md Improve matrix_utils.py test coverage (#383) 2025-12-31 10:50:50 -06:00
codecov.yml Database Modernization and Security Enhancements (#334) 2025-11-07 07:45:50 -06:00
Dockerfile Modernize authentication & fix Windows installer issues (#284) 2025-08-29 12:37:47 -05:00
LICENSE Merge main with GPLv3 license fixes 2025-07-28 06:44:15 -05:00
Makefile Add prebuilt Docker image option while preserving build-from-source 2025-08-02 10:12:22 -05:00
MANIFEST.in Update MANIFEST.in 2025-05-09 07:28:52 -05:00
pyproject.toml Remove setuptools_scm and simplify version handling 2025-04-10 09:07:59 -05:00
pytest.ini Refactor core plugins (#359) 2025-12-01 12:50:48 -06:00
README.md Refactor: Core async improvements, Windows support, and general maintenance (#296) 2025-09-21 14:24:53 -05:00
requirements-e2e.txt Matrix E2EE Support (#154) 2025-08-22 15:51:19 -05:00
requirements.txt deps: bump coverage from 7.13.0 to 7.13.1 (#382) 2025-12-31 10:55:56 -06:00
setup.py deps: bump matplotlib from 3.10.7 to 3.10.8 (#376) 2025-12-26 10:25:56 -06:00

MMRelay

(Meshtastic <=> Matrix Relay)

A powerful and easy-to-use relay between Meshtastic devices and Matrix chat rooms, allowing seamless communication across platforms. This opens the door for bridging Meshtastic devices to many other platforms.

Features

  • Bidirectional message relay between Meshtastic devices and Matrix chat rooms, capable of supporting multiple meshnets
  • Supports serial, network, and BLE (now too!) connections for Meshtastic devices
  • Custom fields are embedded in Matrix messages for relaying messages between multiple meshnets
  • Truncates long messages to fit within Meshtastic's payload size
  • SQLite database to store node information for improved functionality
  • Customizable logging level for easy debugging
  • Configurable through a simple YAML file
  • Supports mapping multiple rooms and channels 1:1
  • Relays messages to/from an MQTT broker, if configured in the Meshtastic firmware
  • Bidirectional replies and reactions support
  • Native Docker support
  • 🔐 Matrix End-to-End Encryption (E2EE) support 🔐 NEW in v1.2!

MMRelay v1.2 introduces Matrix End-to-End Encryption support for secure communication in encrypted rooms. Messages are automatically encrypted/decrypted when communicating with encrypted Matrix rooms, with simple setup using mmrelay auth login or automatic credentials creation from config.yaml.

Documentation

MMRelay supports multiple deployment methods including Docker, pip installation, and standalone executables. For complete setup instructions and all deployment options, see:


Plugins

MMRelay supports plugins for extending its functionality, enabling customization and enhancement of the relay to suit specific needs.

Core Plugins

Generate a map of your nodes:

Map Plugin Screenshot

Produce high-level details about your mesh:

Mesh Details Screenshot

See the full list of core plugins.

Community & Custom Plugins

MMRelay's plugin system allows you to extend functionality in two ways:

  • Custom Plugins: Create personal plugins for your own use, stored in ~/.mmrelay/plugins/custom/
  • Community Plugins: Share your creations with others or use plugins developed by the community

Check the Community Plugins Development Guide in our wiki to get started.

Visit the Community Plugins List!

Install a Community Plugin

Add the repository under the community-plugins section in config.yaml:

community-plugins:
  example-plugin:
    active: true
    repository: https://github.com/jeremiah-k/mmr-plugin-template.git
    tag: main

Plugin System

Plugins make it easy to extend functionality without modifying the core program. MMRelay features a powerful plugin system with standardized locations:

  • Core Plugins: Pre-installed with the package
  • Custom Plugins: Your own plugins in ~/.mmrelay/plugins/custom/
  • Community Plugins: Third-party plugins in ~/.mmrelay/plugins/community/

Getting Started with Matrix

See our Wiki page Getting Started With Matrix & MMRelay.


Already on Matrix?

Join us!