Add ACS712 current sensor usermod#5668
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR adds a new WLED usermod (ACS712) that measures AC current via an analog pin, applies configurable calibration (currentRatio, resolution, offset), samples and averages readings every 5s, and publishes retained numeric readings plus Home Assistant MQTT discovery. MQTT is required at compile time. ChangesACS712 Current Measurement Usermod
🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers:
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Infer (1.2.0)usermods/ACS712/ACS712.cppusermods/ACS712/ACS712.cpp:1:10: fatal error: 'wled.h' file not found ... [truncated 1042 characters] ... /install/lib/clang/18/include" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
usermods/ACS712/ACS712.cpp (1)
8-117: ⚡ Quick winUse 2-space indentation (no tabs) to match project C++ style.
This file currently uses tabs in the class body; please reindent to 2 spaces for guideline compliance and consistency.
As per coding guidelines,
**/*.cppandusermods/**/*.{cpp,h}require 2-space indentation with no tabs.🤖 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 `@usermods/ACS712/ACS712.cpp` around lines 8 - 117, Reformat the file to replace tabs with 2-space indentation throughout the class body so it follows project C++ style; update indentation for the private member declarations and all methods (_mqttInitialize, setup, loop, addToConfig, readFromConfig, appendConfigData) and their internal blocks, ensuring no tabs remain and each indent level uses exactly two spaces; preserve existing code and line structure, only change whitespace.
🤖 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 `@usermods/ACS712/ACS712.cpp`:
- Around line 52-55: The config-derived values pin, currentRatio and resolution
must be validated and clamped in readFromConfig(JsonObject& root) (and before
any use in loop/setup) so they cannot be 0 or out-of-range when passed to
pinMode() or analogRead() or used in division; update readFromConfig to clamp
pin into a sane ADC pin range (or set to -1/disabled if invalid), enforce
currentRatio and resolution to be positive non-zero (fallback to defaults if
invalid), and ensure any places that call pinMode(pin, INPUT) or analogRead(pin)
(references to pin) and any current math (division using
currentRatio/resolution) check the validated values (or return early) to avoid
divide-by-zero and invalid pin operations.
---
Nitpick comments:
In `@usermods/ACS712/ACS712.cpp`:
- Around line 8-117: Reformat the file to replace tabs with 2-space indentation
throughout the class body so it follows project C++ style; update indentation
for the private member declarations and all methods (_mqttInitialize, setup,
loop, addToConfig, readFromConfig, appendConfigData) and their internal blocks,
ensuring no tabs remain and each indent level uses exactly two spaces; preserve
existing code and line structure, only change whitespace.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 165ec204-3c2b-40d2-9b32-63f9c4c58dde
📒 Files selected for processing (2)
usermods/ACS712/ACS712.cppusermods/ACS712/library.json
Adds support for the ACS712 current sensor.
Sends current in mA to MQTT every 5 seconds.
Allows specifying:
Summary by CodeRabbit