Fix: Correct temperature conversion logic in models#39
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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
Add20validator withHalfCelsiusToFfor DHW, freeze protection, and heating element temperature fields - Replaced
DeciCelsiusToFvalidator withPentaCelsiusToFfor tank, refrigerant circuit, and evaporator temperature fields - Added comprehensive test coverage in
tests/test_models.pyto 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.8instead of the canonical9/5fraction. For consistency with the code implementation (which uses9 / 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.8instead of the canonical9/5fraction. For consistency with the code implementation (which uses9 / 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, |
There was a problem hiding this comment.
Corrected spelling of 'heLowerOnTDiffempSetting' to 'heLowerOnDiffTempSetting'.
Suggested change
| "heLowerOnTDiffempSetting": 0, | |
| "heLowerOnDiffTempSetting": 0, |
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.
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:
Add20withHalfCelsiusToFfor fields that are transmitted as half-degrees Celsius.DeciCelsiusToFwithPentaCelsiusToFfor fields that are scaled by a factor of 5.A new test file
tests/test_models.pyhas been added to verify the correctness of the new conversion logic.