Fix ZHA update entity not updating installed version #109260
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed change
This fixes an issue where the ZHA update entity can show "unknown" for the currently installed version when there's a firmware update available.
I've also modified a test case to not plug the zigpy cache with
current_file_version
, but rather let ZHA get it from the "query image" command (checking the HA device registry that's updated on "query img").That catches the issue fixed by this PR. The original test with plugging the attribute is also kept.
Background
Currently, the state for the update entity only gets set/calculated when the entity is initialized.
It looks like that if there's no installed firmware version in the HA device registry and also not in the zigpy attribute cache, this gets set to "unknown".
(Even though
ZCL_INIT_ATTRS
should have initialized thecurrent_file_version
attribute, but maybe network issued led to a case where it didn't at first or only did when the entity was already initialized?)If the HA "check for updates" button is then used, an image notify command is sent to all devices and the devices respond with a command querying for an update.
That causes the
OtaClientClusterHandler
to send aSIGNAL_UPDATE_DEVICE
.ZHADevice/async_update_sw_build_id()
picks that up and updates the firmware version in the HA device registry.Now, if zigpy sees that there's an update available, it calls
device_ota_update_available()
inZHAFirmwareUpdateEntity
.Here, this PR now also re-determines the currently installed version.
Screenshot of the issue (installed version: unknown, new version: correct):
Future
IMO, we could also consider zigpy (or ZHA?) directly updating the attribute cache for the
current_file_version
attribute when it gets aquery_next_image
command. (This would also be useful for quirks, as the current sw version is only inside the HA device registry.)The ZHA update entity could then listen to a signal from
attribute_updated
in the OTA cluster handler and refresh the installed version of the entity when new information about that is available.For now, this PR fixes the issue where "unknown" (or an outdated version) could be shown as the installed version IF there's an update available.
(
device_ota_update_available()
isn't called when there's no update available, thus the installed version not refreshed, even if it somehow changed (pairing to manufacturer hub to update, then re-pairing to HA without removing).This would be addressed by the bigger changes I mentioned above where the entity always gets refreshed on a query image command -> updating zigpy attribute -> sending signal from OTA cluster -> updating update entity)
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
..coveragerc
.To help with the load of incoming pull requests: