Add temperature unit for climate and water heater#168261
Add temperature unit for climate and water heater#168261jhenkens wants to merge 1 commit intohome-assistant:devfrom
Conversation
(cherry picked from commit 82dec48)
|
Hey there @jesserockz, @kbx81, @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR updates the ESPHome integration’s Climate and Water Heater platforms to respect a temperature unit provided by ESPHome, enabling entities to operate natively in Fahrenheit (and other units) instead of assuming Celsius.
Changes:
- Add a temperature-unit mapping for ESPHome climate entities and apply it during static info updates.
- Add a temperature-unit mapping for ESPHome water heater entities and apply it during static info updates.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
homeassistant/components/esphome/climate.py |
Map ESPHome-reported climate temperature unit to HA UnitOfTemperature and set _attr_temperature_unit. |
homeassistant/components/esphome/water_heater.py |
Map ESPHome-reported water heater temperature unit to HA UnitOfTemperature and set _attr_temperature_unit. |
| self._attr_temperature_unit = _WATER_HEATER_TEMPERATURE_UNIT_MAP[ | ||
| static_info.temperature_unit | ||
| ] | ||
| self._attr_min_temp = static_info.min_temperature | ||
| self._attr_max_temp = static_info.max_temperature | ||
| self._attr_target_temperature_step = static_info.target_temperature_step |
There was a problem hiding this comment.
Derive precision from the reported temperature step/unit so Fahrenheit water heaters don’t get rounded and displayed at tenths by default. With _attr_temperature_unit now potentially set to Fahrenheit/Kelvin, keeping _attr_precision = PRECISION_TENTHS can cause values like 100 to be displayed as 100.0 and may not match the device’s supported increments; consider setting _attr_precision in _on_static_info_update based on static_info.target_temperature_step (e.g., whole/halves/tenths) or based on the mapped temperature unit.
|
Closing in favor of #168747 due to branch name. |
Breaking change
Proposed change
Exposes temperature unit for climate and water_heater, with corresponding changes in home-assistant/core, aioesphome, esphome, and esphome-docs, to enable native Fahrenheit measurements on those entities. Usecase is to enable accurate temperature settings on a Fahrenheit hot tub, controlled via RS485-UART. Rather than round tripped from F -> C -> C, with various floating point errors and weirdnesses, this just makes it stay F the entire way and work much more reliably.
Tests still need to be added where appropriate - that's on the todo - but the code has been validated.
When esphome is updated, but core is not, as long as you do not set the temperature unit on a climate/water heater, everything works the same as it currently is. If you do set it, you will convert from F -> "F", as home assistant will think the incoming value from ESPHome is C, without reading the UOM. If ESPHome does not have F specified, it continues to default to C.
When HA is updated, but ESPHome is on an old version, it maintains legacy behavior of treating all climate/water_heaters as using C.
There are still some todo's, namely adding tests in every repo, and some other PR workitems, but the code is working and ready for early review.
Type of change
Additional information
#168261
esphome/aioesphomeapi#1586
esphome/esphome#15740
esphome/esphome-docs#6463
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: