feat: add bidirectional temperature conversion with Fahrenheit API#45
Merged
feat: add bidirectional temperature conversion with Fahrenheit API#45
Conversation
BREAKING CHANGES: - build_reservation_entry() now accepts temperature_f (Fahrenheit) instead of param - set_dhw_temperature() now accepts temperature_f: float instead of int - Removed set_dhw_temperature_display() which used incorrect conversion Added: - fahrenheit_to_half_celsius() utility function for Fahrenheit to device format Fixed: - Temperature encoding bug in set_dhw_temperature() that used incorrect 'subtract 20' conversion instead of proper half-degrees Celsius encoding
Contributor
There was a problem hiding this comment.
Pull request overview
This PR simplifies temperature handling by allowing direct Fahrenheit input across the API, with automatic conversion to the device's internal half-degrees Celsius format. The key improvement is fixing an incorrect "subtract 20" conversion formula that was previously used.
Key Changes:
- Replaced
paramwithtemperature_finbuild_reservation_entry()for clearer API - Fixed temperature encoding bug in
set_dhw_temperature()that used incorrect conversion - Removed
set_dhw_temperature_display()method (used incorrect formula)
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/nwp500/models.py | Added fahrenheit_to_half_celsius() utility function for proper temperature conversion |
| src/nwp500/encoding.py | Updated build_reservation_entry() to accept temperature_f parameter with validation |
| src/nwp500/mqtt_device_control.py | Fixed set_dhw_temperature() to use proper conversion, removed incorrect display method |
| src/nwp500/mqtt_client.py | Updated public API to match device controller changes |
| src/nwp500/cli/commands.py | Updated CLI to use corrected temperature range and method |
| src/nwp500/cli/main.py | Changed argument type from int to float |
| src/nwp500/init.py | Exported new utility function |
| tests/test_models.py | Added comprehensive tests for conversion function |
| tests/test_api_helpers.py | Updated tests to use new API and validate conversions |
| examples/reservation_schedule_example.py | Updated example to use new temperature parameter |
| docs/* | Updated documentation throughout to reflect API changes |
| CHANGELOG.rst | Documented breaking changes and migration guide |
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
This PR simplifies the temperature API by allowing users to pass temperatures in Fahrenheit directly, with automatic conversion to the device's internal format (half-degrees Celsius).
Breaking Changes
build_reservation_entry(): Now acceptstemperature_f(Fahrenheit) instead of rawparamvalueset_dhw_temperature(): Now acceptstemperature_f: floatinstead of raw integerset_dhw_temperature_display(): This method used an incorrect conversion formulaChanges
Added
fahrenheit_to_half_celsius()utility function exported from main packageFixed
set_dhw_temperature()that used incorrect 'subtract 20' conversion instead of proper half-degrees Celsius encodingMigration Guide
Validation