[water_heater] Fix device_id missing from state responses#14212
[water_heater] Fix device_id missing from state responses#14212jesserockz merged 1 commit intodevfrom
Conversation
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#14212
components: [api]
refresh: 1h(Added by the PR bot) |
|
👋 Hi there! This PR modifies 1 file(s) with codeowners. @esphome/core - As codeowner(s) of the affected files, your review would be appreciated! 🙏 Note: Automatic review request may have failed, but you're still welcome to review. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #14212 +/- ##
=======================================
Coverage 74.27% 74.27%
=======================================
Files 55 55
Lines 11591 11591
Branches 1582 1582
=======================================
Hits 8609 8609
Misses 2578 2578
Partials 404 404 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Memory Impact AnalysisComponents:
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the water_heater component's state responses didn't include the device_id field, causing entities with device_id configured to appear as unknown in Home Assistant. The fix aligns the water_heater implementation with all other entity types by using fill_and_encode_entity_state() instead of directly calling encode_message_to_buffer().
Changes:
- Fixed water_heater state encoding to populate device_id field by using
fill_and_encode_entity_state() - Expanded device_id integration test coverage from 5 to 17 entity types to prevent similar bugs in other components
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| esphome/components/api/api_connection.cpp | Replaced manual key setting and encode_message_to_buffer() call with fill_and_encode_entity_state() to properly populate both key and device_id fields |
| tests/integration/test_device_id_in_state.py | Expanded test to verify device_id for 17 entity types (sensor, binary_sensor, switch, text_sensor, light, cover, fan, lock, number, select, text, valve, water_heater, alarm_control_panel, date, time, datetime) with improved error messages |
| tests/integration/fixtures/device_id_in_state.yaml | Added test entities for 12 additional entity types (cover, fan, lock, number, select, text, valve, water_heater, alarm_control_panel, date, time, datetime, event) |
Water heater was the only entity type that directly called encode_message_to_buffer() instead of fill_and_encode_entity_state(). This meant device_id was never set on WaterHeaterStateResponse, causing entities with device_id to show as unknown in Home Assistant. Expand the device_id integration test to cover all entity types: cover, fan, lock, number, select, text, valve, water_heater, alarm_control_panel, date, time, datetime, and event. Closes #14206
1ec6484 to
cdb2e32
Compare
|
thanks |
What does this implement/fix?
try_send_water_heater_state()was the only entity type that directly calledencode_message_to_buffer()instead offill_and_encode_entity_state(). This meantdevice_idwas never set onWaterHeaterStateResponse, causing entities withdevice_idconfigured to show asunknownin Home Assistant.The fix replaces the direct
encode_message_to_buffer()call withfill_and_encode_entity_state(), matching every other entity type (sensor, climate, switch, cover, fan, light, etc.).Also expands the
device_idintegration test from 5 entity types to 17, covering all stateful entity types that supportdevice_id.Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: