Skip to content

Fix: Correct temperature conversion logic in models#39

Merged
eman merged 7 commits intomainfrom
fix/temperature-conversion
Nov 21, 2025
Merged

Fix: Correct temperature conversion logic in models#39
eman merged 7 commits intomainfrom
fix/temperature-conversion

Conversation

@eman
Copy link
Copy Markdown
Owner

@eman eman commented Nov 21, 2025

The previous temperature conversion logic used a hardcoded 20-degree Fahrenheit offset for some fields and an incorrect scaling factor for others.

This was based on an approximation of the device's behavior.

Analysis of the decompiled mobile application revealed the precise conversion formulas used for different temperature sensors.

This commit replaces the previous validators with new, more accurate ones that reflect the app's implementation:

  • Replaced Add20 with HalfCelsiusToF for fields that are transmitted as half-degrees Celsius.
  • Replaced DeciCelsiusToF with PentaCelsiusToF for fields that are scaled by a factor of 5.

A new test file tests/test_models.py has been added to verify the correctness of the new conversion logic.

eman added 5 commits November 21, 2025 12:28
The previous temperature conversion logic used a hardcoded 20-degree Fahrenheit offset for some fields and an incorrect scaling factor for others.

This was based on an approximation of the device's behavior.

Analysis of the decompiled mobile application revealed the precise conversion formulas used for different temperature sensors.

This commit replaces the previous validators with new, more accurate ones that reflect the app's implementation:

- Replaced `Add20` with `HalfCelsiusToF` for fields that are transmitted as half-degrees Celsius.
- Replaced `DeciCelsiusToF` with `PentaCelsiusToF` for fields that are scaled by a factor of 5.

A new test file `tests/test_models.py` has been added to verify the correctness of the new conversion logic.
@eman eman requested a review from Copilot November 21, 2025 20:53
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 corrects temperature conversion logic in src/nwp500/models.py based on analysis of the decompiled mobile application. The previous implementation used incorrect approximations (Add20 for a 20°F offset, and DeciCelsiusToF for tenths of Celsius conversion). The new implementation uses accurate formulas (HalfCelsiusToF for half-degree Celsius values, and PentaCelsiusToF for values scaled by a factor of 5).

Key Changes:

  • Replaced Add20 validator with HalfCelsiusToF for DHW, freeze protection, and heating element temperature fields
  • Replaced DeciCelsiusToF validator with PentaCelsiusToF for tank, refrigerant circuit, and evaporator temperature fields
  • Added comprehensive test coverage in tests/test_models.py to verify conversion accuracy

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_models.py New test file with fixtures and conversion validation tests
src/nwp500/models.py Updated validators and type annotations with correct conversion formulas
docs/python_api/models.rst Updated documentation to reflect new conversion approach
docs/protocol/device_status.rst Updated field conversion references throughout
docs/protocol/data_conversions.rst Comprehensive documentation updates explaining new conversion logic
Comments suppressed due to low confidence (2)

docs/protocol/data_conversions.rst:1

  • [nitpick] The formula uses 1.8 instead of the canonical 9/5 fraction. For consistency with the code implementation (which uses 9 / 5) and other formulas in this document, consider using (raw_value / 2.0) * 9/5 + 32.
Data Conversions and Units Reference

docs/protocol/data_conversions.rst:1

  • [nitpick] The formula uses 1.8 instead of the canonical 9/5 fraction. For consistency with the code implementation (which uses 9 / 5) and other formulas in this document, consider using (raw_value / 5.0) * 9/5 + 32.
Data Conversions and Units Reference

"hpLowerOffDiffTempSetting": 0,
"heUpperOnDiffTempSetting": 0,
"heUpperOffDiffTempSetting": 0,
"heLowerOnTDiffempSetting": 0,
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'heLowerOnTDiffempSetting' to 'heLowerOnDiffTempSetting'.

Suggested change
"heLowerOnTDiffempSetting": 0,
"heLowerOnDiffTempSetting": 0,

Copilot uses AI. Check for mistakes.
@eman eman merged commit 3298f09 into main Nov 21, 2025
10 checks passed
@eman eman deleted the fix/temperature-conversion branch November 21, 2025 21:11
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.

2 participants