New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ZHA creating unnecessary "summ received" entity after upgrade #109268
Merged
dmulcahey
merged 4 commits into
home-assistant:dev
from
TheJulianJES:tjj/zha_force_init_of_new_current_summ_received_attr
Feb 6, 2024
Merged
Fix ZHA creating unnecessary "summ received" entity after upgrade #109268
dmulcahey
merged 4 commits into
home-assistant:dev
from
TheJulianJES:tjj/zha_force_init_of_new_current_summ_received_attr
Feb 6, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The attribute isn't initialized for these devices in the test (which our check now expects it to be), hence we need to remove them from this list.
…ntity The attribute needs to be initialized for it to be created which we do by plugging the attribute read. The test expects the initial state to be "unknown", but hence we plugged the attribute (to create the entity), the state is whatever we plug the attribute read as.
…ty if it doesn't exist
home-assistant
bot
added
bugfix
cla-signed
has-tests
integration: zha
small-pr
PRs with less than 30 lines.
labels
Feb 1, 2024
Hey there @dmulcahey, @Adminiuga, @puddly, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
TheJulianJES
changed the title
Fix ZHA creating unnecessary
Fix ZHA creating unnecessary "summ received" entity after upgrade
Feb 1, 2024
current_summ_received
after upgrade
TheJulianJES
requested review from
dmulcahey,
Adminiuga and
puddly
as code owners
February 5, 2024 23:54
TheJulianJES
commented
Feb 6, 2024
dmulcahey
approved these changes
Feb 6, 2024
20 tasks
frenck
pushed a commit
that referenced
this pull request
Feb 6, 2024
…09268) * Do not create `current_summ_received` entity until initialized once * Update zha_devices_list.py to not expect summation received entities The attribute isn't initialized for these devices in the test (which our check now expects it to be), hence we need to remove them from this list. * Update sensor tests to have initial state for current_summ_received entity The attribute needs to be initialized for it to be created which we do by plugging the attribute read. The test expects the initial state to be "unknown", but hence we plugged the attribute (to create the entity), the state is whatever we plug the attribute read as. * Update sensor tests to expect not updating current_summ_received entity if it doesn't exist
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
bugfix
by-code-owner
cherry-picked
cla-signed
has-tests
integration: zha
Quality Scale: No score
small-pr
PRs with less than 30 lines.
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
Do not create the ZHA
current_summ_received
entity until initialized once to avoid unnecessary/ghost entities.The
current_summ_received
attribute only started to be initialized in HA 2024.2.0.Due to ZHA attribute initialization happening in the background for existing devices (to read the attribute and see if it's supported/unsupported), this entity would always get created directly after the upgrade for all power-measuring devices.
If HA is then restarted, the entity would turn into a ghost entity, as ZHA then detected that it's unsupported.
To avoid creating a lot of unnecessary entities for existing devices, this PR waits until that specific attribute was properly initialized once for now before creating the entity.
We can't do this for all (sensor) entities, as we want some entities to be created, even if no report was sent yet. Our test cases also test for that behavior.
This is relevant for HA Core 2024.2.0 (betas), so also marked this for 2024.2.0 to avoid the issue of creating that entity unnecessarily.
For anyone affected on current betas, the ghost entity can be removed using the UI.
Tests
Due to this entity differing from our other "normal" (non-diagnostic) entities (which are always created, even if the attribute isn't initialized), I've had to adapt the tests for this new behavior.
More details are provided in a commit message where the tests are updated.
The entities are removed from the ZHA devices list, as the attributes are all
None
there by default, so this entity isn't created in that case.Type of change
Additional information
(and kind of: [Device Support Request] _TZE204_81yrt3lo TS0601 Zigbee power meter with clamp zigpy/zha-device-handlers#2549)
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: