Skip to content

add support for .cfg export/import#944

Merged
ianmcorvidae merged 3 commits into
meshtastic:masterfrom
tylerpieper:master
Jul 2, 2026
Merged

add support for .cfg export/import#944
ianmcorvidae merged 3 commits into
meshtastic:masterfrom
tylerpieper:master

Conversation

@tylerpieper

@tylerpieper tylerpieper commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds support for exporting and importing binary device profiles (.cfg), bringing the Python CLI to feature parity with the Android app's configuration backup functionality.

Key Changes

  • Binary Profile Support: The CLI can now export and import configurations by serializing and deserializing a DeviceProfile protobuf message. This captures all the same settings as the existing yaml import/export.
  • New CLI Arguments:
    • Added --import-config as a clear alias for the existing --configure command.
    • Added --export-format (accepts auto, yaml, binary, or protobuf) to explicitly override format detection during both imports and exports (binary, and protobuf both do the same thing).
  • Robust Autodetection:
    • Exporting: --export-config defaults to auto and generates a binary protobuf if the target file extension ends in .cfg. Otherwise, it falls back to the existing YAML behavior.
    • Importing: --configure and --import-config rely on file contents rather than extensions. It attempts to parse the file as a YAML dictionary; if it fails (e.g., throwing a decode error on binary data), it assumes the file is a binary DeviceProfile protobuf and parses it accordingly.

Summary by CodeRabbit

  • New Features
    • Added support for importing and exporting device configuration in both text (YAML) and binary (protobuf) formats.
    • Import can automatically detect the input format or be set explicitly.
    • Export format can be selected (including binary), with improved handling for file vs console output.
  • Bug Fixes
    • Improved configuration application to remote devices, including correct fixed-position handling and safer application of optional settings.
    • Adjusted YAML exports to omit location details unless fixed-position is enabled.
  • Tests
    • Expanded coverage for configuration export/import, conversions, and error handling.

adds binary import and export to mirror functionality of android (and soon ios) app
@CLAassistant

CLAassistant commented Jun 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds protobuf DeviceProfile import/export support alongside YAML, with CLI flags for explicit or autodetected formats. Import now applies profile fields through a settings transaction, and export can emit YAML or binary output. Tests cover round-trips, format detection, and fixed-position behavior.

Changes

Binary config import/export

Layer / File(s) Summary
CLI argument additions
meshtastic/__main__.py
Adds --import-config and expands --export-format to support auto, yaml, binary, and protobuf.
Profile import/export flow
meshtastic/__main__.py
Adds profile parsing/serialization helpers, routes configure/export through YAML or protobuf DeviceProfile, applies node settings from imported profiles, and adjusts YAML export location handling.
Import/export test coverage
meshtastic/tests/test_main.py
Adds tests for protobuf/YAML profile conversion, CLI configure/export paths, round-trips, autodetection, and mocked binary file reads.

Estimated code review effort: 4 (Complex) | ~45 minutes

Poem

🐇 I hop through YAML, bytes, and beams,
A DeviceProfile packed with config dreams.
cfg goes binary, or text can stay,
The warren exports both night and day.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding .cfg export/import support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

- Unify parsing for yaml/DeviceProfile paths
- Improve autodetection
- Ensure partial-config behavior with yaml
- gate configuration to local node (avoiding some pre-existing bugs)
- gate fixed position updates behind explicit opt-in via position settings field
- use setOwner properly
- tests, tests, and more tests
@ianmcorvidae ianmcorvidae requested a review from Copilot July 1, 2026 21:00
@ianmcorvidae

Copy link
Copy Markdown
Contributor

@coderabbitai full review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds binary .cfg (protobuf DeviceProfile) import/export support to the Meshtastic Python CLI, enabling configuration backup/restore parity with the Android app while keeping existing YAML behavior and adding explicit format control.

Changes:

  • Added DeviceProfile-based export/import flow with autodetection and explicit --export-format override (auto|yaml|binary|protobuf).
  • Updated --configure to support binary profiles and added --import-config as an alias.
  • Expanded unit tests to cover binary serialization, autodetection, error cases, and YAML/binary consistency.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
meshtastic/__main__.py Implements binary profile import/export, format autodetection/override, and profile/YAML conversion helpers.
meshtastic/tests/test_main.py Adds extensive unit coverage for new binary profile behavior and round-trip expectations.

Comment thread meshtastic/__main__.py
Comment thread meshtastic/__main__.py
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.52427% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.84%. Comparing base (74cce6b) to head (b05e545).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
meshtastic/__main__.py 82.52% 36 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #944      +/-   ##
==========================================
+ Coverage   64.68%   66.84%   +2.15%     
==========================================
  Files          25       25              
  Lines        4619     4741     +122     
==========================================
+ Hits         2988     3169     +181     
+ Misses       1631     1572      -59     
Flag Coverage Δ
unittests 66.84% <82.52%> (+2.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
meshtastic/tests/test_main.py (1)

2420-2438: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert fixed-position arguments, not just call count.

This test would pass even if import re-rounds protobuf microdegrees through floats. Use a precision-sensitive coordinate and verify the exact setFixedPosition() arguments.

🧪 Proposed test strengthening
-        "location:\n  lat: 35.0\n  lon: -93.0\n  alt: 100\n"
+        "location:\n  lat: -49.82207\n  lon: 0\n  alt: 0\n"
         "config:\n  position:\n    fixed_position: true\n"
@@
-        iface.getNode.return_value.setFixedPosition.assert_called_once()
+        iface.getNode.return_value.setFixedPosition.assert_called_once_with(-498220700, 0, 0)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@meshtastic/tests/test_main.py` around lines 2420 - 2438, The test only checks
that `main()` calls `iface.getNode.return_value.setFixedPosition()` once, so it
can miss precision regressions. Strengthen
`test_main_configure_calls_setfixedposition_when_config_opt_in` by using a
precision-sensitive `location` value and asserting the exact arguments passed to
`setFixedPosition`, not just the call count, so the behavior in `main()` and the
`setFixedPosition` path is verified precisely.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@meshtastic/__main__.py`:
- Around line 1470-1490: Guard the myinfo result from interface.getMyNodeInfo()
before accessing position data, since it can be None and cause a crash in the
fixed_position branch. In the export flow around getMyNodeInfo(), check that
myinfo is present before calling myinfo.get("position"), and skip or safely
handle the position copy when it is missing. Use the existing profile and
interface.localNode.localConfig/moduleConfig logic as the anchor for where to
add the guard.

---

Nitpick comments:
In `@meshtastic/tests/test_main.py`:
- Around line 2420-2438: The test only checks that `main()` calls
`iface.getNode.return_value.setFixedPosition()` once, so it can miss precision
regressions. Strengthen
`test_main_configure_calls_setfixedposition_when_config_opt_in` by using a
precision-sensitive `location` value and asserting the exact arguments passed to
`setFixedPosition`, not just the call count, so the behavior in `main()` and the
`setFixedPosition` path is verified precisely.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9488dfa5-5e88-436e-b515-a190afef5e4e

📥 Commits

Reviewing files that changed from the base of the PR and between 6d76edf and b05e545.

📒 Files selected for processing (2)
  • meshtastic/__main__.py
  • meshtastic/tests/test_main.py

Comment thread meshtastic/__main__.py
@ianmcorvidae ianmcorvidae merged commit e2844cb into meshtastic:master Jul 2, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants