Add Matter Thermostat presets feature#160885
Add Matter Thermostat presets feature#160885lboue wants to merge 85 commits intohome-assistant:devfrom
Conversation
… its JSON fixture
- Refactor MatterClimate to utilize dynamic preset types - Add support for eve_thermo_v5 in integration fixture and snapshots - Simplify preset handling with async_set_preset_mode - Update test fixtures and add comprehensive tests
|
Hey there @home-assistant/matter, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
…bsolete Matterbridge thermostat JSON file
… preset handles and improving error handling for preset mode setting.
| # Optimistically update the endpoint's ActivePresetHandle attribute | ||
| # to prevent _update_from_device() from reverting to stale device state | ||
| active_preset_path = create_attribute_path_from_attribute( | ||
| endpoint_id=self._endpoint.endpoint_id, | ||
| attribute=clusters.Thermostat.Attributes.ActivePresetHandle, | ||
| ) | ||
| self._endpoint.set_attribute_value(active_preset_path, active_preset_handle) | ||
| self._update_from_device() | ||
| self.async_write_ha_state() |
There was a problem hiding this comment.
The async_set_preset_mode method calls async_write_ha_state() after optimistic updates, but async_set_hvac_mode (lines 307-325) does not. This inconsistency suggests that either async_set_preset_mode has an unnecessary explicit state write (since device attribute updates will trigger _on_matter_event which already calls async_write_ha_state()), or async_set_hvac_mode is missing one. Review the existing pattern: if write_attribute and send_device_command automatically trigger state updates through subscriptions, the explicit async_write_ha_state() call may be redundant. If it's needed for immediate UI feedback before device confirmation, consider documenting why and applying it consistently to both methods.
There was a problem hiding this comment.
Please address this comment. Why do we need to write state optimistically?
There was a problem hiding this comment.
When SetActivePresetRequest is sent to the device, the ActivePresetHandle attribute is updated on the device side immediately. However, Home Assistant only learns about attribute changes via Matter subscriptions, which are subject to a negotiated minIntervalFloor set by the device. This means the subscription report carrying the updated ActivePresetHandle value may arrive several seconds later, even though the device has already applied the change.
Without the optimistic update, HA would keep displaying the previous preset mode in the UI until the subscription report arrives, creating a confusing inconsistency right after the user triggers the action.
To avoid this, async_set_preset_mode() immediately:
- Updates
_attr_preset_modeto the new value and callsasync_write_ha_state()so the UI reflects the change instantly. - Calls
set_attribute_value()on the local endpoint cache forActivePresetHandle, so that any intermediate call to_update_from_device()(e.g. triggered by another subscription report on a different attribute) does not revert the preset back to the old value before the device's own subscription report arrives.
This is consistent with how async_set_hvac_mode() handles the SystemMode attribute in the same file.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
I noticed that there's a bug in the SDK related to Thermostats: This will be included in future versions, but it will take some time for this patch to be incorporated into future firmware updates. |
…mate to address SDK bug and reporting delays
Proposed change
This pull request introduces support for thermostat preset modes in the Home Assistant Matter integration. Users can now easily switch between predefined climate presets (e.g., Home, Away, Sleep, Eco) on Matter-compatible thermostats through the Home Assistant UI and service calls.
SetActivePresetRequestcommands with optimistic updates and validation (handles Matter errors).Details
The presets available on this thermostat are:
Type of change
Additional information
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: