Skip to content

Add unit_of_measurement to climate and water_heater#168747

Draft
jhenkens wants to merge 12 commits intohome-assistant:devfrom
jhenkens:add-temperature-unit-to-climate-and-water-heater
Draft

Add unit_of_measurement to climate and water_heater#168747
jhenkens wants to merge 12 commits intohome-assistant:devfrom
jhenkens:add-temperature-unit-to-climate-and-water-heater

Conversation

@jhenkens
Copy link
Copy Markdown
Contributor

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

esphome/aioesphomeapi#1600
esphome/esphome#15815

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings April 22, 2026 03:22
@home-assistant home-assistant Bot added cla-signed integration: esphome new-feature small-pr PRs with less than 30 lines. Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage Top 50 Integration is ranked within the top 50 by usage labels Apr 22, 2026
@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @jesserockz, @kbx81, @bdraco, mind taking a look at this pull request as it has been labeled with an integration (esphome) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of esphome can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign esphome Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

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 updates the ESPHome integration’s climate and water_heater entities to expose the temperature unit_of_measurement from the device’s static info, enabling native Fahrenheit (and other units) end-to-end.

Changes:

  • Add TemperatureUnitUnitOfTemperature mapping for ESPHome climate entities.
  • Add TemperatureUnitUnitOfTemperature mapping for ESPHome water_heater entities.
  • Set _attr_temperature_unit from ESPHome static info during entity info updates.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
homeassistant/components/esphome/climate.py Maps ESPHome-reported temperature units onto HA’s climate entity unit handling.
homeassistant/components/esphome/water_heater.py Maps ESPHome-reported temperature units onto HA’s water heater entity unit handling.

Comment on lines +48 to +52
_WATER_HEATER_TEMPERATURE_UNIT_MAP: dict[TemperatureUnit, UnitOfTemperature] = {
TemperatureUnit.CELSIUS: UnitOfTemperature.CELSIUS,
TemperatureUnit.FAHRENHEIT: UnitOfTemperature.FAHRENHEIT,
TemperatureUnit.KELVIN: UnitOfTemperature.KELVIN,
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Deduplicate the TemperatureUnit→UnitOfTemperature mapping by reusing a shared constant (instead of defining a second map here) to keep behavior consistent across ESPHome platforms.

Copilot uses AI. Check for mistakes.
Comment on lines +154 to +156
self._attr_temperature_unit = _CLIMATE_TEMPERATURE_UNIT_MAP[
static_info.temperature_unit
]
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Add unit tests that validate the entity’s temperature unit is set from the ESPHome static info (e.g., Fahrenheit) and that service calls/state attributes behave correctly with that unit.

Copilot uses AI. Check for mistakes.
Comment on lines +68 to +70
self._attr_temperature_unit = _WATER_HEATER_TEMPERATURE_UNIT_MAP[
static_info.temperature_unit
]
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Add unit tests that validate the water heater’s temperature unit is set from the ESPHome static info (e.g., Fahrenheit) and that min/max/step and service calls are interpreted in that unit.

Copilot uses AI. Check for mistakes.
Comment on lines +132 to +136
_CLIMATE_TEMPERATURE_UNIT_MAP: dict[TemperatureUnit, UnitOfTemperature] = {
TemperatureUnit.CELSIUS: UnitOfTemperature.CELSIUS,
TemperatureUnit.FAHRENHEIT: UnitOfTemperature.FAHRENHEIT,
TemperatureUnit.KELVIN: UnitOfTemperature.KELVIN,
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Deduplicate the TemperatureUnit→UnitOfTemperature mapping by moving it to a shared constant (e.g., in the ESPHome integration module) so climate and water_heater can’t drift in behavior over time.

Copilot uses AI. Check for mistakes.
@bdraco
Copy link
Copy Markdown
Member

bdraco commented Apr 22, 2026

Would be good to do a separate PR to bump aioesphomeapi first

@jhenkens
Copy link
Copy Markdown
Contributor Author

Would be good to do a separate PR to bump aioesphomeapi first

#168749

Copilot AI review requested due to automatic review settings April 22, 2026 04:12
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

self._feature_flags = ClimateFeature(
static_info.supported_feature_flags_compat(self._api_version)
)
self._attr_temperature_unit = TEMPERATURE_UNIT_MAP[static_info.temperature_unit]
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Add test coverage that sets temperature_unit in ClimateInfo (e.g., Fahrenheit) and asserts the entity reports the correct temperature unit and that service calls pass the raw temperature values without unintended conversion.

Copilot uses AI. Check for mistakes.
"""Set attrs from static info."""
super()._on_static_info_update(static_info)
static_info = self._static_info
self._attr_temperature_unit = TEMPERATURE_UNIT_MAP[static_info.temperature_unit]
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Add test coverage that sets temperature_unit in WaterHeaterInfo (e.g., Fahrenheit) and asserts the entity exposes the correct temperature unit and that async_set_temperature forwards the intended value in that unit.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 22, 2026 04:25
Comment thread homeassistant/components/esphome/water_heater.py Outdated
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Co-authored-by: J. Nick Koston <nick+github@koston.org>
Copilot AI review requested due to automatic review settings April 22, 2026 05:39
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

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

"""Set attrs from static info."""
super()._on_static_info_update(static_info)
static_info = self._static_info
self._attr_temperature_unit = TEMPERATURE_UNIT_MAP.get(static_info.temperature_unit, UnitOfTemperature.CELSIUS)
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Import UnitOfTemperature (or avoid referencing it) so _on_static_info_update doesn’t raise NameError when setting _attr_temperature_unit.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 22, 2026 05:55
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@jhenkens
Copy link
Copy Markdown
Contributor Author

Retested this change with my custom build of ESPHome - easier now that aioesphomeapi is merged - and can confirm this still works as desired.

jhenkens added 2 commits May 2, 2026 09:57
…and-water-heater' into add-temperature-unit-to-climate-and-water-heater
Copilot AI review requested due to automatic review settings May 2, 2026 17:00
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

(
3,
UnitOfTemperature.CELSIUS,
), # unknown value maps to Celsius via aioesphomeapi
(
3,
UnitOfTemperature.CELSIUS,
), # unknown value maps to Celsius via aioesphomeapi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed integration: esphome new-feature Quality Scale: platinum small-pr PRs with less than 30 lines. Top 50 Integration is ranked within the top 50 by usage Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants