Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usermod INA219 Current, Voltage & Power Sensor #4237

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open

Conversation

KrX3D
Copy link

@KrX3D KrX3D commented Oct 31, 2024

Hi,

i created a usermod for the ina219 Current, Voltage & Power Sensor:

INA219-Pin-Outs

I took a liking to the INA226 Usermod here:

https://github.com/Aircoookie/WLED/tree/0_15/usermods/INA226_v2

and took some parts and added my 3 cents to it.

I hope the readme states everything needed to get what can be done.

the only think i couldnt solved is to add the sensors data to the wled home assistant integration page (if thats even possible) so instead it is added just to mqtt. if there is a way to have the autodiscover to add it directly to the wled integrations page, i would be more than happy to change the usermod.

also i hope i added everything correctly in git, since its my first time working like this in git

Summary by CodeRabbit

  • New Features

    • Introduced INA219 sensor integration for WLED, enabling monitoring of voltage, current, power, and energy consumption (daily, monthly, and total) directly via the WLED interface.
    • Added support for MQTT publishing and Home Assistant discovery for seamless connectivity.
  • Documentation

    • Included comprehensive setup and configuration instructions to help users integrate and utilize the new energy monitoring features through the WLED web interface.

@DedeHai
Copy link
Collaborator

DedeHai commented Nov 1, 2024

since you keep adding commits, is this work in progress? if so, mark it as such or better yet: commit to this PR once you are finished.

@KrX3D
Copy link
Author

KrX3D commented Nov 1, 2024

since you keep adding commits, is this work in progress? if so, mark it as such or better yet: commit to this PR once you are finished.

Hi,

no its finsied. I just did some small formatting changes while waiting for a reply. But now im happy with it ;)

EDIT: im also using it for like 2 weeks now without any problems

@DedeHai
Copy link
Collaborator

DedeHai commented Nov 1, 2024

ok nice. did you test it working on different ESPs?

@KrX3D
Copy link
Author

KrX3D commented Nov 1, 2024

i tested it on an ESP32 S2 (lolin_s2_mini) and an C3 (esp32c3dev) where it is working.

like i said its already running for around 2 weeks

@KrX3D
Copy link
Author

KrX3D commented Nov 14, 2024

Hi,

i tested it now also with an ESp32 Wroom-32 (esp32dev) and it also worked.

did i forget something so it will be added to version 0,15?
im new to git with all this pull request stuff

@DedeHai
Copy link
Collaborator

DedeHai commented Nov 14, 2024

looks fine, needs more testing and review, there are a few usermods in pipeline so please be patient.

changed uint8_t to int8_t for _sdaPin and _sclPin --->  to be able to pick "unused" in pin selection which is -1,
Several optimizations for WLED_MQTT_CONNECTED and if Usermod is enabled/disabled
@netmindz netmindz changed the base branch from 0_15 to main December 16, 2024 13:29
@KrX3D KrX3D requested a review from DedeHai January 29, 2025 18:31
KrX3D added 3 commits January 30, 2025 18:34
- Moved configurable settings to the top of the file for better readability.
- Defined default values for each configuration option using #ifndef directives.
- Updated default I2C pins to WLED ESP32 defaults (SDA: 21, SCL: 22).
- Cleaned up variable initialization to use pre-defined constants for configuration.
@KrX3D KrX3D requested a review from DedeHai January 31, 2025 16:59
@DedeHai
Copy link
Collaborator

DedeHai commented Feb 1, 2025

looks good now.
did you test that the UM compiles on all platforms? if it does not: throw compile errors for platforms not supported.

@DedeHai DedeHai added the usermod usermod related label Feb 1, 2025
@KrX3D
Copy link
Author

KrX3D commented Feb 1, 2025

Hi,
i updated ReadMe and pictues since i removed the SDA/SCL pin selection from the usermod.


im not sure if i also should add this under lib_deps inside platformio.ini:
wollewald/INA219_WE@~1.3.8

i already added the info to the readme. I mean here:

image


i compiled it for all default_envs (v0.15) and got no errors:

image


for my own info, is there a way to exclude COM1 from beeing uploaded? compiling was taking to long that way

Solve for: This branch has conflicts that must be resolved
Copy link

coderabbitai bot commented Feb 22, 2025

Walkthrough

The changes introduce support for the INA219 sensor usermod. A new README file documents the usermod’s features, while a header file implements the UsermodINA219 class that handles voltage, current, power measurements, energy calculations, MQTT communication, and Home Assistant integration. Additionally, a new usermod ID is defined, and the registration list is updated to conditionally include the INA219 usermod.

Changes

File(s) Change Summary
usermods/INA219/Readme.md
usermods/INA219/usermod_ina219.h
Added INA219 sensor usermod documentation and implementation. The header defines the UsermodINA219 class with methods for sensor initialization, periodic reading, energy computation, MQTT message handling, JSON state/config management, and Home Assistant integration.
wled00/const.h
wled00/usermods_list.cpp
Introduced a new usermod ID (USERMOD_ID_INA219 58) and updated the registration list by conditionally including the INA219 usermod header and adding its instance to the usermod manager.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (9)
usermods/INA219/usermod_ina219.h (5)

6-8: Consolidate default configuration flags.

Having multiple #define blocks for all default settings is helpful, but consider consolidating them within one file or grouping them in a dedicated section if they are solely used here. This can improve maintainability and readability.


178-180: Consider using a more time-accurate daily/monthly reset strategy.

You reset daily energy after 86,400 seconds and monthly after 2,592,000 seconds. If the device sleeps or reboots, this simple accumulation might drift from actual calendar days. For improved accuracy, consider integrating with NTP or a real-time clock-based approach.


185-207: Clarify MQTT topic deletion logic.

When mqttPublish is toggled off (line 199), the code publishes an empty string with retain to remove the sensor from Home Assistant (line 204). This is a valid pattern, but ensure users are aware it fully removes historical data in some setups. Documenting this behavior improves transparency.


316-357: Add units to JSON keys for clarity.

You produce JSON keys like "current", "power", etc. Consider including explicit suffixes (e.g., current_A, power_W) so end-consumers of the data are unambiguously aware of units.


423-475: Optimize sanitizeMqttClientID.

The function handles character-by-character validations and transformations (lines 427-472). This logic works but can be simplified and made more maintainable by using a dictionary/map for replacements instead of large condition blocks. This reduces complexity and potential off-by-one errors.

usermods/INA219/Readme.md (4)

44-60: Replace Hard Tabs with Spaces in the ADC Modes Table.
This block (lines 44–60) is indented using hard tabs, which triggers markdownlint MD010. To comply with markdown best practices and ensure consistent rendering across different editors, please replace these tabs with spaces (e.g., 2 or 4 spaces).

Below is a sample diff for the first line of this block:

-		### Options for `INA219_CONVERSION_TIME`
+    ### Options for `INA219_CONVERSION_TIME`
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

44-44: Hard tabs
Column: 1

(MD010, no-hard-tabs)


46-46: Hard tabs
Column: 1

(MD010, no-hard-tabs)


48-48: Hard tabs
Column: 1

(MD010, no-hard-tabs)


49-49: Hard tabs
Column: 1

(MD010, no-hard-tabs)


50-50: Hard tabs
Column: 1

(MD010, no-hard-tabs)


51-51: Hard tabs
Column: 1

(MD010, no-hard-tabs)


52-52: Hard tabs
Column: 1

(MD010, no-hard-tabs)


53-53: Hard tabs
Column: 1

(MD010, no-hard-tabs)


54-54: Hard tabs
Column: 1

(MD010, no-hard-tabs)


55-55: Hard tabs
Column: 1

(MD010, no-hard-tabs)


56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


57-57: Hard tabs
Column: 1

(MD010, no-hard-tabs)


58-58: Hard tabs
Column: 1

(MD010, no-hard-tabs)


59-59: Hard tabs
Column: 1

(MD010, no-hard-tabs)


60-60: Hard tabs
Column: 1

(MD010, no-hard-tabs)


62-71: Convert Hard Tabs to Spaces in the Decimal Factor Options Section.
The section detailing the options for INA219_DECIMAL_FACTOR (lines 62–71) uses hard tabs for indentation. Converting these to spaces will resolve the markdownlint MD010 warnings and improve consistency.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

62-62: Hard tabs
Column: 1

(MD010, no-hard-tabs)


64-64: Hard tabs
Column: 1

(MD010, no-hard-tabs)


66-66: Hard tabs
Column: 1

(MD010, no-hard-tabs)


67-67: Hard tabs
Column: 1

(MD010, no-hard-tabs)


68-68: Hard tabs
Column: 1

(MD010, no-hard-tabs)


69-69: Hard tabs
Column: 1

(MD010, no-hard-tabs)


70-70: Hard tabs
Column: 1

(MD010, no-hard-tabs)


71-71: Hard tabs
Column: 1

(MD010, no-hard-tabs)


73-82: Remove Hard Tabs from the I2C Address Options Section.
Lines 73–82, which list the available I2C address options, are indented with hard tabs. Please replace these with spaces to adhere to markdown style guidelines and eliminate MD010 errors.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

73-73: Hard tabs
Column: 1

(MD010, no-hard-tabs)


75-75: Hard tabs
Column: 1

(MD010, no-hard-tabs)


77-77: Hard tabs
Column: 1

(MD010, no-hard-tabs)


78-78: Hard tabs
Column: 1

(MD010, no-hard-tabs)


79-79: Hard tabs
Column: 1

(MD010, no-hard-tabs)


80-80: Hard tabs
Column: 1

(MD010, no-hard-tabs)


81-81: Hard tabs
Column: 1

(MD010, no-hard-tabs)


82-82: Hard tabs
Column: 1

(MD010, no-hard-tabs)


98-110: Standardize Indentation in the Predefine Options Block.
The predefine options (lines 98–110) are currently indented using hard tabs. Replacing these tabs with spaces will resolve markdownlint MD010 issues and maintain consistency throughout the document.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

100-100: Hard tabs
Column: 1

(MD010, no-hard-tabs)


101-101: Hard tabs
Column: 1

(MD010, no-hard-tabs)


102-102: Hard tabs
Column: 1

(MD010, no-hard-tabs)


103-103: Hard tabs
Column: 1

(MD010, no-hard-tabs)


104-104: Hard tabs
Column: 1

(MD010, no-hard-tabs)


105-105: Hard tabs
Column: 1

(MD010, no-hard-tabs)


106-106: Hard tabs
Column: 1

(MD010, no-hard-tabs)


107-107: Hard tabs
Column: 1

(MD010, no-hard-tabs)


108-108: Hard tabs
Column: 1

(MD010, no-hard-tabs)


109-109: Hard tabs
Column: 1

(MD010, no-hard-tabs)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6641508 and b0a3ee3.

⛔ Files ignored due to path filters (4)
  • usermods/INA219/img/homeassistant.png is excluded by !**/*.png
  • usermods/INA219/img/info.png is excluded by !**/*.png
  • usermods/INA219/img/usermod_settings.png is excluded by !**/*.png
  • usermods/INA219/img/usermod_settings_pins_selection.png is excluded by !**/*.png
📒 Files selected for processing (4)
  • usermods/INA219/Readme.md (1 hunks)
  • usermods/INA219/usermod_ina219.h (1 hunks)
  • wled00/const.h (1 hunks)
  • wled00/usermods_list.cpp (2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
usermods/INA219/Readme.md

44-44: Hard tabs
Column: 1

(MD010, no-hard-tabs)


46-46: Hard tabs
Column: 1

(MD010, no-hard-tabs)


48-48: Hard tabs
Column: 1

(MD010, no-hard-tabs)


49-49: Hard tabs
Column: 1

(MD010, no-hard-tabs)


50-50: Hard tabs
Column: 1

(MD010, no-hard-tabs)


51-51: Hard tabs
Column: 1

(MD010, no-hard-tabs)


52-52: Hard tabs
Column: 1

(MD010, no-hard-tabs)


53-53: Hard tabs
Column: 1

(MD010, no-hard-tabs)


54-54: Hard tabs
Column: 1

(MD010, no-hard-tabs)


55-55: Hard tabs
Column: 1

(MD010, no-hard-tabs)


56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


57-57: Hard tabs
Column: 1

(MD010, no-hard-tabs)


58-58: Hard tabs
Column: 1

(MD010, no-hard-tabs)


59-59: Hard tabs
Column: 1

(MD010, no-hard-tabs)


60-60: Hard tabs
Column: 1

(MD010, no-hard-tabs)


62-62: Hard tabs
Column: 1

(MD010, no-hard-tabs)


64-64: Hard tabs
Column: 1

(MD010, no-hard-tabs)


66-66: Hard tabs
Column: 1

(MD010, no-hard-tabs)


67-67: Hard tabs
Column: 1

(MD010, no-hard-tabs)


68-68: Hard tabs
Column: 1

(MD010, no-hard-tabs)


69-69: Hard tabs
Column: 1

(MD010, no-hard-tabs)


70-70: Hard tabs
Column: 1

(MD010, no-hard-tabs)


71-71: Hard tabs
Column: 1

(MD010, no-hard-tabs)


73-73: Hard tabs
Column: 1

(MD010, no-hard-tabs)


75-75: Hard tabs
Column: 1

(MD010, no-hard-tabs)


77-77: Hard tabs
Column: 1

(MD010, no-hard-tabs)


78-78: Hard tabs
Column: 1

(MD010, no-hard-tabs)


79-79: Hard tabs
Column: 1

(MD010, no-hard-tabs)


80-80: Hard tabs
Column: 1

(MD010, no-hard-tabs)


81-81: Hard tabs
Column: 1

(MD010, no-hard-tabs)


82-82: Hard tabs
Column: 1

(MD010, no-hard-tabs)


100-100: Hard tabs
Column: 1

(MD010, no-hard-tabs)


101-101: Hard tabs
Column: 1

(MD010, no-hard-tabs)


102-102: Hard tabs
Column: 1

(MD010, no-hard-tabs)


103-103: Hard tabs
Column: 1

(MD010, no-hard-tabs)


104-104: Hard tabs
Column: 1

(MD010, no-hard-tabs)


105-105: Hard tabs
Column: 1

(MD010, no-hard-tabs)


106-106: Hard tabs
Column: 1

(MD010, no-hard-tabs)


107-107: Hard tabs
Column: 1

(MD010, no-hard-tabs)


108-108: Hard tabs
Column: 1

(MD010, no-hard-tabs)


109-109: Hard tabs
Column: 1

(MD010, no-hard-tabs)

🔇 Additional comments (10)
usermods/INA219/usermod_ina219.h (4)

64-74: Validate after disabling the usermod.

When enabled is set to false (line 64) due to invalid pins or other reasons, ensure that checks later in the code (e.g., sensor read in main loop) skip operations or handle the disabled scenario gracefully. You might want to log a message or update logs to clarify that the usermod is disabled.


128-132: Confirm pin usage and resource allocation.

You disabled the usermod when i2c_scl < 0 || i2c_sda < 0. This prevents improper usage, but consider also logging an actionable message or referencing the WLED global I2C settings if these pins are not automatically set. This helps users debug their hardware setup more easily.


231-247: Remove references with consistent naming or placeholders.

In lines 236-242, you remove previously created sensors by calling mqttRemoveHassSensor(...). Notice that “Shunt-Voltage,” “Daily-Energy,” “Monthly-Energy,” etc., have hyphens, while your create calls do not. For consistency, confirm the names match exactly so sensors are correctly removed.


480-505: Check for potential integer overflow in time-based calculations.

When using durationMs (unsigned long) to accumulate daily or monthly reset times, watch for potential overflows if the device runs for very long without a reset. Consider using a larger data type (e.g., uint64_t) if that is a concern for extremely long uptimes.

wled00/usermods_list.cpp (1)

185-187: Ensure consistent inclusion guard usage.

You conditionally include "usermod_ina219.h" with #ifdef USERMOD_INA219 but verify that the configuration macros are properly declared in build settings. This is consistent with other usermods. No immediate issues found here.

wled00/const.h (1)

209-209: New usermod ID assignment looks correct.

Assigning USERMOD_ID_INA219 to 58 is consistent with existing values. Just ensure there are no merges or reassignments that accidentally reuse 58 later.

usermods/INA219/Readme.md (4)

1-43: Excellent Documentation Structure and Clarity.
The initial sections—title, introductory description, and feature list—are well structured and clear. The content effectively communicates the purpose of the INA219 WLED Usermod and its relevant features.


84-97: Usage Section is Clear and Effective.
The usage instructions (lines 84–97) are concise and provide clear step‐by‐step guidance for users on how to integrate the usermod. No changes are needed here.


111-117: Energy Calculation Section is Concise and Informative.
The explanation of energy calculations (lines 111–117) clearly communicates how total, daily, and monthly energy are handled, providing valuable context for users.


119-134: Dependencies and I2C Configuration Section is Well-Documented.
The final section (lines 119–134) outlining required library dependencies and mandatory I2C configuration steps is comprehensive and clear, ensuring that users know how to set up the hardware communication before enabling the usermod.

Fix missing pound in #endif.

Line 504 has “endif” without a leading #. This is likely a small typographical mistake that can break compilation.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
wled00/usermods_list.cpp (1)

502-504: Consider moving the registration to maintain alphabetical order.

The registration code is correctly implemented but could be moved to maintain alphabetical order with other usermods (between INA226 and LD2410).

Apply this diff to move the registration:

  #ifdef USERMOD_INA226
  UsermodManager::add(new UsermodINA226());
  #endif
+ 
+ #ifdef USERMOD_INA219
+ UsermodManager::add(new UsermodINA219());
+ #endif
  
  #ifdef USERMOD_LD2410
  UsermodManager::add(new LD2410Usermod());
  #endif

  #ifdef USERMOD_POV_DISPLAY
  UsermodManager::add(new PovDisplayUsermod());
  #endif

  #ifdef USERMOD_DEEP_SLEEP
  UsermodManager::add(new DeepSleepUsermod());
  #endif

  #ifdef USERMOD_RF433
  UsermodManager::add(new RF433Usermod());
  #endif
  
  #ifdef USERMOD_BRIGHTNESS_FOLLOW_SUN
  UsermodManager::add(new UsermodBrightnessFollowSun());
  #endif
- 
- #ifdef USERMOD_INA219
- UsermodManager::add(new UsermodINA219());
- #endif
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0a3ee3 and a7dc6e9.

📒 Files selected for processing (1)
  • wled00/usermods_list.cpp (2 hunks)
🔇 Additional comments (1)
wled00/usermods_list.cpp (1)

185-188: LGTM! Include directive is well-placed.

The include directive follows the established pattern and is properly placed in alphabetical order among other sensor usermods.

Handle INA219 initialization failure more robustly.

Currently, you only log "INA219 initialization failed!" if _ina219->init() fails. Consider disabling enabled or providing fallback logic to avoid subsequent read attempts on a failed initialization, preventing usage of a potentially invalid object.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
usermods/INA219/usermod_ina219.h (4)

127-147: Consider preserving the existing Wire object for I2C.
Calling delete _ina219; and creating a new instance on every settings update is acceptable, but it reinitializes the sensor each time. If the sensor’s configuration changes frequently, this can introduce unnecessary overhead. Reusing or reconfiguring the same instance might be more efficient.


365-413: Check for potential naming collisions in MQTT topics.
When creating Home Assistant sensors, the unique_id is built from mqttClientID and replaces spaces with hyphens. Ensure that collisions won’t occur if multiple devices share similar names or if character replacements become identical. Adding additional uniqueness factors like _i2cAddress might help.


424-476: Remove or clarify leftover commented-out code.
Multiple lines (e.g., 435, 438, 442, 446, 450, 454, 458, 459) contain references to extended replacements (“ue”, “oe”, “ss”) that are now commented out. Unless these are intentionally kept for later reference, removing them will reduce confusion and improve readability.

Here’s a sample snippet to remove them:

-          //sanitizedID += "ue"; // Replace ü with ue
+          sanitizedID += "u"; // Replace ü with u

(Similarly remove all other commented-out replacements in the same pattern.)


634-668: Guard against invalid intervals in config.
Your fallback handling in lines 643–647 helps avoid invalid intervals, but consider logging a message or storing an error code if check_interval is out of range. This ensures end users can diagnose misconfigurations quickly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7dc6e9 and a7dac9d.

📒 Files selected for processing (1)
  • usermods/INA219/usermod_ina219.h (1 hunks)
🔇 Additional comments (5)
usermods/INA219/usermod_ina219.h (5)

6-8: Good use of conditional compilation and default value.
Defining INA219_ENABLED to false by default is a clean approach for conditionally enabling the usermod. No concerns here.


163-201: Ensure consecutive loops handle sensor reads accurately.
Within the loop() method, the sensor data is fetched every checkInterval. However, if the device is under heavy load or the loop is sometimes delayed, consider whether the time-based calculations remain accurate if millis() increments significantly between checks. If major timing delays are possible, further checks or accumulative error handling may be needed to maintain consistent measurement intervals.


253-255: Threshold-based comparison approach looks correct.
The method hasSignificantChange() with a fixed threshold of 0.01f is a straightforward solution for filtering out minor fluctuations. Ensure 0.01 suits your precision and application needs.


481-506: Verify resetting logic for daily and monthly energy.
The conditions to reset (>= 86400 seconds for daily, >= 2592000 seconds for monthly) are straightforward but assume fully continuous uptime. Long sleep or downtime might throw these counters off. Consider tracking real dates for more robust resets if system time is available.


581-596: Confirm storage of fundamental parameters in the usermod config.
Storing all key operational settings (like i2c_address, check_interval) is helpful for permanent record. Just ensure future changes (e.g., correction factor or advanced sensor options) also get included.

coderabbitai ->

502-504: Consider moving the registration to maintain alphabetical order.

The registration code is correctly implemented but could be moved to maintain alphabetical order with other usermods (between INA226 and LD2410).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants