Skip to content

Fix negative voltage value when discharging, preventing battery time estimation#490

Merged
corecoding merged 1 commit intocorecoding:mainfrom
ragotpaul:fix-negative-power
Jul 27, 2025
Merged

Fix negative voltage value when discharging, preventing battery time estimation#490
corecoding merged 1 commit intocorecoding:mainfrom
ragotpaul:fix-negative-power

Conversation

@ragotpaul
Copy link
Copy Markdown
Contributor

When the computer is running on battery, the CURRENT_NOW value in the uevent file 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_NOW values correctly so that the estimated time remaining is displayed as expected.

Copilot AI review requested due to automatic review settings July 11, 2025 22:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances battery time estimation by properly handling negative POWER_NOW values when discharging.

  • Change power check from > 0 to !== 0 so negative readings are included
  • Use Math.abs for 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_NOW is negative (discharging) and positive (charging) to verify the timeLeft calculation behaves correctly in both cases.
                    timeLeft = (output['ENERGY_NOW'] / Math.abs(output['POWER_NOW']));

Comment thread sensors.js
@corecoding
Copy link
Copy Markdown
Owner

This seems logical. Thank you. Let's give it a try!

@corecoding corecoding merged commit 81fe8b9 into corecoding:main Jul 27, 2025
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.

3 participants