Skip to content

refactor(adapters): migrate MQTT, Web and UI to commands and snapshots - #218

Open
stritti wants to merge 57 commits into
mainfrom
refactor/adapter-command-snapshot-migration
Open

stritti wants to merge 57 commits into
mainfrom
refactor/adapter-command-snapshot-migration

Conversation

@stritti

@stritti stritti commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Draft architecture migration

Incrementally migrates adapter boundaries to the Core-1 typed-command / immutable-snapshot architecture while preserving existing MQTT/Web contracts.

Target

  • inbound runtime mutations become typed ControllerCommand values
  • one Core-1 application handler owns controller-state mutation
  • outbound adapters consume SystemSnapshot value copies
  • provisioning/authentication secrets and calibration stay behind dedicated service boundaries
  • legacy hand-over queues are removed only after equivalent typed-path coverage exists

Dependencies integrated in this branch

Implemented in this draft

  • instance-based ControllerCommandHandler composed in main.cpp
  • complete typed runtime-command contract with validation and persistence boundaries
  • MQTT callback reduced to fixed-size byte hand-over; no controller mutation on AsyncTCP
  • MQTT runtime topics translated to ControllerCommand on the Core-1 loop
  • independent timer-start and timer-end updates without stale-state reconstruction
  • manual pump policy centralized in the application handler
  • sensor-mapping updates routed through the typed handler
  • non-runtime MQTT operations remain delegated to their existing specialized services
  • native regression coverage for dispatch, bounded processing, timer updates, manual-pump guard and sensor mapping
  • OpenSpec task/design state kept in sync

Verified so far

  • Native Tests: green
  • PlatformIO CI: green on the current functional slice
  • cppcheck/cpplint and repository linters: green; final clang-format cleanup is being verified on the latest head
  • no open inline review threads at the last review check

Still draft

  • route Web runtime mutations through the same handler
  • route local UI mutations through the same handler
  • publish/populate SystemSnapshot from the Core-1 owner
  • migrate MQTT/Web/OLED/TFT read paths to snapshots
  • remove remaining direct mutable Nodes.hpp access from migrated adapters
  • remove the legacy MqttCommandQueue after typed hand-over equivalence is complete

The PR intentionally remains a draft until these migration steps and their contract tests are complete.

@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

❌MegaLinter analysis: Error

Descriptor Linter Files Fixed Errors Max errors Warnings Elapsed time
✅ ACTION actionlint 8 0 0 0.78s
✅ BASH bash-exec 2 0 0 0.65s
✅ BASH shellcheck 2 0 0 0.7s
✅ BASH shfmt 2 0 0 0.01s
✅ C clang-format 1 0 0 0.04s
✅ C cppcheck 1 0 0 0.03s
✅ C cpplint 1 0 0 0.34s
❌ CPP clang-format 106 2 0 0.95s
✅ CPP cppcheck 106 0 0 7.48s
✅ CPP cpplint 106 0 0 8.71s
✅ EDITORCONFIG editorconfig-checker 295 0 0 0.51s
✅ JSON jsonlint 6 0 0 0.14s
✅ JSON v8r 6 0 0 4.07s
✅ MARKDOWN markdownlint 110 0 0 3.92s
✅ YAML yamllint 27 0 0 0.78s

Detailed Issues

❌ CPP / clang-format - 2 errors
src/ControllerSnapshotPublisher.cpp:135:73: error: code should be clang-formatted [-Wclang-format-violations]
  const std::uint32_t detectedRefreshSeconds = settings.loopInterval > 0
                                                                        ^
src/ControllerSnapshotPublisher.cpp:136:56: error: code should be clang-formatted [-Wclang-format-violations]
    ? static_cast<std::uint32_t>(settings.loopInterval)
                                                       ^

Notices

⚠️ Your configuration references items that have been removed from MegaLinter and are ignored: MAKEFILE, MAKEFILE_CHECKMAKE, MARKDOWN_MARKDOWN_LINK_CHECK. See Removed linters to find their replacements.

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@10.1.0 --custom-flavor-setup --custom-flavor-linters ACTION_ACTIONLINT,BASH_EXEC,BASH_SHELLCHECK,BASH_SHFMT,C_CPPCHECK,C_CPPLINT,C_CLANG_FORMAT,CPP_CPPCHECK,CPP_CPPLINT,CPP_CLANG_FORMAT,EDITORCONFIG_EDITORCONFIG_CHECKER,JSON_JSONLINT,JSON_V8R,MARKDOWN_MARKDOWNLINT,YAML_YAMLLINT

MegaLinter is provided by OX Security
Show us your support by starring ⭐ the repository

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 48.2%
Branch Coverage 74.8%
Lines Hit/Total 392/814
Branches Hit/Total 178/238

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 48.2%
Branch Coverage 74.8%
Lines Hit/Total 392/814
Branches Hit/Total 178/238

Report from native unit tests (ASan + gcov).

4 similar comments
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 48.2%
Branch Coverage 74.8%
Lines Hit/Total 392/814
Branches Hit/Total 178/238

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 48.2%
Branch Coverage 74.8%
Lines Hit/Total 392/814
Branches Hit/Total 178/238

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 48.2%
Branch Coverage 74.8%
Lines Hit/Total 392/814
Branches Hit/Total 178/238

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 48.2%
Branch Coverage 74.8%
Lines Hit/Total 392/814
Branches Hit/Total 178/238

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.0%
Branch Coverage 75.4%
Lines Hit/Total 439/861
Branches Hit/Total 184/244

Report from native unit tests (ASan + gcov).

4 similar comments
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.0%
Branch Coverage 75.4%
Lines Hit/Total 439/861
Branches Hit/Total 184/244

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.0%
Branch Coverage 75.4%
Lines Hit/Total 439/861
Branches Hit/Total 184/244

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.0%
Branch Coverage 75.4%
Lines Hit/Total 439/861
Branches Hit/Total 184/244

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.0%
Branch Coverage 75.4%
Lines Hit/Total 439/861
Branches Hit/Total 184/244

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.5%
Branch Coverage 76.2%
Lines Hit/Total 443/861
Branches Hit/Total 186/244

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage —%
Branch Coverage —%
Lines Hit/Total 0/0
Branches Hit/Total 0/0

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.0%
Branch Coverage 76.2%
Lines Hit/Total 443/868
Branches Hit/Total 186/244

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.8%
Branch Coverage 76.2%
Lines Hit/Total 450/868
Branches Hit/Total 186/244

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.7%
Branch Coverage 76.2%
Lines Hit/Total 447/865
Branches Hit/Total 186/244

Report from native unit tests (ASan + gcov).

2 similar comments
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.7%
Branch Coverage 76.2%
Lines Hit/Total 447/865
Branches Hit/Total 186/244

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 51.7%
Branch Coverage 76.2%
Lines Hit/Total 447/865
Branches Hit/Total 186/244

Report from native unit tests (ASan + gcov).

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 52.9%
Branch Coverage 77.7%
Lines Hit/Total 467/883
Branches Hit/Total 202/260

Report from native unit tests (ASan + gcov).

stritti added a commit that referenced this pull request Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 52.9%
Branch Coverage 77.7%
Lines Hit/Total 467/883
Branches Hit/Total 202/260

Report from native unit tests (ASan + gcov).

1 similar comment
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 52.9%
Branch Coverage 77.7%
Lines Hit/Total 467/883
Branches Hit/Total 202/260

Report from native unit tests (ASan + gcov).

stritti added a commit that referenced this pull request Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 52.9%
Branch Coverage 77.7%
Lines Hit/Total 467/883
Branches Hit/Total 202/260

Report from native unit tests (ASan + gcov).

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

3 similar comments
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 87829b282b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/ControllerSnapshotPublisher.cpp Outdated
Comment thread src/ControllerCommandHandler.cpp Outdated
Comment thread src/ControllerSnapshotPublisher.cpp
Comment thread src/ControllerCommandHandler.cpp Outdated
Comment thread src/ConfigManager.cpp Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 89.2%
Branch Coverage 70.4%
Lines Hit/Total 791/887
Branches Hit/Total 439/624

Report from native unit tests (ASan + gcov).

@github-actions

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 89.2%
Branch Coverage 70.4%
Lines Hit/Total 791/887
Branches Hit/Total 439/624

Report from native unit tests (ASan + gcov).

@github-actions

Copy link
Copy Markdown
Contributor

Native Test Coverage

Metric Value
Line Coverage 89.2%
Branch Coverage 70.4%
Lines Hit/Total 791/887
Branches Hit/Total 439/624

Report from native unit tests (ASan + gcov).

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc1aaa211b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +192 to +193
settings.tempCircThreshold = command.value;
return saveSettings();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Roll back circulation settings after save failures

When NVS cannot be opened, this branch returns rejection after leaving settings.tempCircThreshold changed; the factor and maximum-runtime branches have the same behavior. The MQTT adapter then calls publishStates(), which reports the rejected value, and any later successful configuration save persists it. Preserve the previous setting and restore it when saveSettings() fails, as the setpoint branches already do.

Useful? React with 👍 / 👎.

Comment on lines +254 to +256
settings.timezoneIndex = command.integerValue;
if (!saveSettings()) {
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restore the timezone setting when persistence fails

If ConfigManager::save() fails for an MQTT timezone command, the handler returns false but leaves settings.timezoneIndex at the requested value while skipping setTimezoneIndex(). Consequently Home Assistant is republished the new timezone label even though the running clock still uses the old timezone, and an unrelated later save can persist the rejected value. Save the previous index and restore it on this failure path.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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.

1 participant