Skip to content

Mechanical refactor and code cleanup iteration#560

Merged
JanPetterMG merged 17 commits intomainfrom
chore/mechanical-refactor-and-cleanup
May 2, 2026
Merged

Mechanical refactor and code cleanup iteration#560
JanPetterMG merged 17 commits intomainfrom
chore/mechanical-refactor-and-cleanup

Conversation

@JanPetterMG
Copy link
Copy Markdown
Collaborator

@JanPetterMG JanPetterMG commented May 1, 2026

This pull request continues the mechanical refactor and static-analysis cleanup pass across the firmware codebase.

The changes are mostly non-functional, but a few small correctness and robustness fixes are included where the cleanup exposed unsafe casts, wraparound-prone loops, or brittle string handling.

Key changes

  • Standardizes static inline declaration order in headers.
  • Replaces several C-string action checks with std::string_view comparisons.
  • Removes the Home Assistant discovery ID regex dependency and uses a fixed discovery component ID instead.
  • Adds explicit casts and targeted NOLINT annotations where conversions are intentional.
  • Uses lroundf() instead of roundf() followed by integer casts for weather and thermometer values.
  • Fixes loop bounds that could be flagged as wraparound-prone when iterating over uint8_t-sized ranges.
  • Cleans up mode internals, including naming in PixelSequenceMode, draw-coordinate casts, and branch-clone suppressions.
  • Refactors MetaballsMode::handle() to reduce nesting and make the microphone guard an early return.
  • Improves metaballs brightness accumulation by using a wider intermediate type before clamping to UINT8_MAX.
  • Updates ellipse drawing to use hypotf(), clearer pitch-ratio calculations, and correct row/column bounds.
  • Adjusts CircleMode radius calculation and drawing so the effect better reflects the display geometry.
  • Avoids passing raw std::string_view::data() to Server-Sent Events by materializing a null-terminated string first.

Impact

This should reduce static-analysis noise and make the affected code easier to read and maintain without changing the public API or configuration format.

The main behavior-adjacent changes are limited to safer rendering/math internals, more robust action parsing, and corrected display geometry handling.

@JanPetterMG JanPetterMG added firmware C++ related chore This issue or pull request is a maintenance task labels May 1, 2026
@JanPetterMG JanPetterMG added this to the v2.4.0 milestone May 1, 2026
@JanPetterMG JanPetterMG marked this pull request as ready for review May 2, 2026 17:23
@JanPetterMG JanPetterMG added this pull request to the merge queue May 2, 2026
Merged via the queue into main with commit 82dce33 May 2, 2026
154 checks passed
@JanPetterMG JanPetterMG deleted the chore/mechanical-refactor-and-cleanup branch May 2, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore This issue or pull request is a maintenance task firmware C++ related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant