Skip to content

feat: add bidirectional temperature conversion with Fahrenheit API#45

Merged
eman merged 1 commit intomainfrom
feature/fahrenheit-temperature-api
Dec 3, 2025
Merged

feat: add bidirectional temperature conversion with Fahrenheit API#45
eman merged 1 commit intomainfrom
feature/fahrenheit-temperature-api

Conversation

@eman
Copy link
Copy Markdown
Owner

@eman eman commented Dec 3, 2025

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 accepts temperature_f (Fahrenheit) instead of raw param value
  • set_dhw_temperature(): Now accepts temperature_f: float instead of raw integer
  • Removed set_dhw_temperature_display(): This method used an incorrect conversion formula

Changes

Added

  • fahrenheit_to_half_celsius() utility function exported from main package

Fixed

  • Temperature encoding bug in set_dhw_temperature() that used incorrect 'subtract 20' conversion instead of proper half-degrees Celsius encoding

Migration Guide

# Reservations - OLD
build_reservation_entry(..., param=120)

# Reservations - NEW  
build_reservation_entry(..., temperature_f=140.0)

# DHW Temperature - OLD
await mqtt.set_dhw_temperature(device, 120)
await mqtt.set_dhw_temperature_display(device, 140)

# DHW Temperature - NEW
await mqtt.set_dhw_temperature(device, 140.0)

Validation

  • ✅ Linting: All checks passed
  • ✅ Type checking: No errors
  • ✅ Tests: 127 passed

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
@eman eman requested a review from Copilot December 3, 2025 18:44
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 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 param with temperature_f in build_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

@eman eman merged commit 77fac92 into main Dec 3, 2025
10 checks passed
@eman eman deleted the feature/fahrenheit-temperature-api branch December 3, 2025 18:54
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