Fix negative voltage value when discharging, preventing battery time estimation#490
Merged
corecoding merged 1 commit intocorecoding:mainfrom Jul 27, 2025
ragotpaul:fix-negative-power
Merged
Fix negative voltage value when discharging, preventing battery time estimation#490corecoding merged 1 commit intocorecoding:mainfrom ragotpaul:fix-negative-power
corecoding merged 1 commit intocorecoding:mainfrom
ragotpaul:fix-negative-power
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances battery time estimation by properly handling negative POWER_NOW values when discharging.
- Change power check from
> 0to!== 0so negative readings are included - Use
Math.absfor discharging time calculation - Preserve the “Discharging” status with correct estimated time
Comments suppressed due to low confidence (1)
sensors.js:466
- Add unit tests for scenarios where
POWER_NOWis negative (discharging) and positive (charging) to verify the timeLeft calculation behaves correctly in both cases.
timeLeft = (output['ENERGY_NOW'] / Math.abs(output['POWER_NOW']));
Owner
|
This seems logical. Thank you. Let's give it a try! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the computer is running on battery, the
CURRENT_NOWvalue in theueventfile can be negative. This prevents the remaining battery time from being calculated, and only the message "Discharging" is shown.This PR updates the logic to handle negative
CURRENT_NOWvalues correctly so that the estimated time remaining is displayed as expected.