Skip to content

Fix: Incorrect Unit Scaling for Energy Capacity Fields (Off by Factor of 10)#71

Merged
eman merged 2 commits intomainfrom
fix/energy-capacity-unit-scaling
Feb 4, 2026
Merged

Fix: Incorrect Unit Scaling for Energy Capacity Fields (Off by Factor of 10)#71
eman merged 2 commits intomainfrom
fix/energy-capacity-unit-scaling

Conversation

@eman
Copy link
Copy Markdown
Owner

@eman eman commented Feb 4, 2026

Summary

  • Fixes incorrect unit scaling for total_energy_capacity and available_energy_capacity fields
  • Device reports energy in 10Wh units, but library was interpreting them as raw Wh
  • Now correctly multiplies by 10 to convert from 10Wh units to standard Wh

Issue 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)

  • 1.4 kWh ≈ 4,777 BTU
  • ΔT = 4,777 BTU / 542 lbs ≈ 8.8°F (physically impossible for hot tank)

After fix: Device reports 1404.0 → Library stores 14040.0 Wh (14.0 kWh)

  • 14.0 kWh ≈ 47,906 BTU
  • ΔT = 47,906 BTU / 542 lbs ≈ 88.4°F
  • Final temp: 53°F + 88.4°F ≈ 141.4°F (matches setpoint)

Technical Changes

  • Added mul_10() helper function to src/nwp500/converters.py
  • Applied BeforeValidator(mul_10) to energy capacity fields in DeviceStatus model
  • Added comprehensive test suite for the new converter
  • Maintained backward compatibility with existing API

Test Results

  • ✅ All existing tests pass
  • ✅ New mul_10 converter tests pass (18 test cases)
  • ✅ Conversion correctly handles integers, floats, and edge cases

eman and others added 2 commits February 4, 2026 10:10
… 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.
@eman eman requested a review from Copilot February 4, 2026 18:18
Copy link
Copy Markdown
Contributor

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 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_capacity and available_energy_capacity fields in DeviceStatus
  • Modernized InstallType enum to use StrEnum instead of str, 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

@eman eman merged commit e976428 into main Feb 4, 2026
7 checks passed
@eman eman deleted the fix/energy-capacity-unit-scaling branch February 4, 2026 18:29
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.

Fix: Incorrect Unit Scaling for Energy Capacity Fields (Off by Factor of 10)

2 participants