Set should_poll attribute to False for MySensors battery sensor#165282
Set should_poll attribute to False for MySensors battery sensor#165282EdLeckert wants to merge 3 commits intohome-assistant:devfrom
Conversation
should_poll defaults to True, and having force_update set to True causes integration to spam the battery state every 30 seconds with a typically identical value.
There was a problem hiding this comment.
Hi @EdLeckert
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Hey there @MartinHjelmare, @functionpointer, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR addresses excessive battery sensor state updates in the mysensors integration by disabling polling for the node-level battery sensor entity, preventing periodic (default 30s) state writes when the value hasn’t changed.
Changes:
- Mark
MyBatterySensoras non-polled by setting_attr_should_poll = False.
MartinHjelmare
left a comment
There was a problem hiding this comment.
Please add a test too. Just moving time forward should not trigger a state update.
Remove the should_poll attribute to improve sensor behavior.
This is my first core integration PR and I am not familiar with the test configuration. If you can tell me what you want added I can attach it to the PR. |
|
Here's the existing test for the battery sensor: core/tests/components/mysensors/test_sensor.py Lines 84 to 102 in 30aec4d Add a new test or extend that test, and test that moving time forward 30 seconds doesn't trigger a state reported event. We have a test helper for moving time forward. Lines 499 to 502 in 30aec4d We have the core/homeassistant/helpers/event.py Lines 411 to 416 in 30aec4d |
The attribute
should_polldefaults toTrue, and havingforce_updateset toTruecauses integration to spam the battery state every 30 seconds with a typically identical value.Proposed change
Adding
_attr_should_poll = Falseto
MyBatterySensorat line 260 ofsensor.pyfixes the issue.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: