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
Frequent errors in Riemann Sum Integration #71684
Comments
integration documentation |
Hey there @dgomes, mind taking a look at this issue as it has been labeled with an integration ( |
After digging through the sources of trigger templates a bit more, this seems to have to do with the attributes restore logic that is used when reloading the template sensors configuration. Upon restore the status first becomes 'unknown' without any attributes. Those only pop in later. This would explain why these errors pop up 5 times only. Those must be the times when I reloaded my config changes to some other template sensors. |
Hi @RoboMagus I think you traced the problem correctly I would nonetheless prefer a solution involving a guard instead of suppressing the exception. Would you like to have a go and open a PR with the fix ? |
@dgomes, Edit: |
The problem
I've setup a trigger based template sensor for power measurements (see yaml below), which is fed into an integration sensor.
Multiple times a day I see an error pop up where the handling of
new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
throws an AttributeError:'NoneType' object has no attribute 'attributes'
What version of Home Assistant Core has the issue?
Core 2022.5.3
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Container
Integration causing the issue
Integration
Link to integration documentation on our website
https://www.home-assistant.io/integrations/integration/
Diagnostics information
Logger: homeassistant.helpers.event
Source: components/integration/sensor.py:199
First occurred: May 10, 2022, 10:42:52 (5 occurrences)
Last logged: 13:07:28
Example YAML snippet
Anything in the logs that might be useful for us?
Error while processing state change for sensor.mhi_ac_ctrl_estimated_power Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 271, in _async_state_change_dispatcher hass.async_run_hass_job(job, event) File "/usr/src/homeassistant/homeassistant/core.py", line 523, in async_run_hass_job cast(Callable[..., _R], hassjob.target)(*args) File "/usr/src/homeassistant/homeassistant/components/integration/sensor.py", line 199, in calc_integration unit = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) AttributeError: 'NoneType' object has no attribute 'attributes'
Additional information
It seems like the error does not throw every time, as this will be executed way more often than is shown in the error occurences count.
My best guess is that the error is introduced by this change.
Something funky is going on with the attributes of the trigger based template sensor and the way attributes are queried by the integration component does propperly handle when those aren't present.
To propperly handle any funkyness it seems the following should be sufficient:
The text was updated successfully, but these errors were encountered: