Fix: Incorrect Unit Scaling for Energy Capacity Fields (Off by Factor of 10)#71
Merged
Fix: Incorrect Unit Scaling for Energy Capacity Fields (Off by Factor of 10)#71
Conversation
… of 10) - Add mul_10 helper function to converters.py for multiplying by 10.0 - Apply BeforeValidator to total_energy_capacity and available_energy_capacity fields - Device reports energy in 10Wh units, library now correctly converts to Wh - Add comprehensive tests for mul_10 converter - Addresses issue #70 where fully heated tank reported 1.4 kWh instead of 14 kWh Physics verification: 65-gallon tank heated from 53°F to 141°F requires ~14 kWh, not 1.4 kWh as previously calculated. Co-authored-by: eman <19387+eman@users.noreply.github.com>
Resolves ruff UP042 warning about class inheriting from both str and Enum. Updated to use StrEnum from enum module which is the modern approach.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a unit scaling bug where energy capacity fields were off by a factor of 10. The device reports energy in 10Wh units, but the library was treating these values as standard Wh, resulting in physically impossible readings (e.g., 1.4 kWh for a fully heated 65-gallon tank instead of 14 kWh).
Changes:
- Added
mul_10()converter function to correctly scale 10Wh device units to standard Wh - Applied the converter to
total_energy_capacityandavailable_energy_capacityfields inDeviceStatus - Modernized
InstallTypeenum to useStrEnuminstead ofstr, Enum
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/nwp500/converters.py | Added mul_10() converter function to multiply values by 10 |
| src/nwp500/models.py | Applied TenWhToWh type annotation with mul_10 validator to energy capacity fields |
| src/nwp500/enums.py | Refactored InstallType to use StrEnum instead of str, Enum |
| tests/test_model_converters.py | Added comprehensive test suite for mul_10 converter with 18 test cases |
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.
Summary
total_energy_capacityandavailable_energy_capacityfieldsIssue Reference
Fixes #70
Physics Verification
The fix addresses a physics impossibility where a fully heated 65-gallon tank was reporting only 1.4 kWh instead of the physically correct ~14 kWh:
Before fix: Device reported 1404.0 → Library stored 1404.0 Wh (1.4 kWh)
After fix: Device reports 1404.0 → Library stores 14040.0 Wh (14.0 kWh)
Technical Changes
mul_10()helper function tosrc/nwp500/converters.pyBeforeValidator(mul_10)to energy capacity fields inDeviceStatusmodelTest Results
mul_10converter tests pass (18 test cases)