Skip to content
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

async_write_ha_state errors in latest HA beta (2024.5.0b4) #37

Closed
aherbjornsen opened this issue May 1, 2024 · 7 comments
Closed

async_write_ha_state errors in latest HA beta (2024.5.0b4) #37

aherbjornsen opened this issue May 1, 2024 · 7 comments

Comments

@aherbjornsen
Copy link

Version of the custom_component

1.5

Homeassistant version

2024.5.0b4

Describe the bug

Integration throws warnings and runtime errors related to 'async_write_ha_state' in latest HA beta release.

Debug log


2024-05-01 13:06:40.481 WARNING (SyncWorker_34) [homeassistant.helpers.frame] Detected that custom integration 'priceanalyzer' calls async_write_ha_state from a thread at custom_components/priceanalyzer/sensor.py, line 403: self.async_write_ha_state(), please report it to the author of the 'priceanalyzer' custom integration
2024-05-01 13:06:40.544 ERROR (SyncWorker_0) [homeassistant.util.logging] Exception in update_sensor when dispatching 'pricanalyzer_checked_stuff': ()
Traceback (most recent call last):
  File "/config/custom_components/priceanalyzer/sensor.py", line 332, in update_sensor
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1008, in async_write_ha_state
    self.hass.verify_event_loop_thread("async_write_ha_state")
  File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread
    frame.report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration
    raise RuntimeError(
RuntimeError: Detected that custom integration 'priceanalyzer' calls async_write_ha_state from a thread at custom_components/priceanalyzer/sensor.py, line 332: self.async_write_ha_state(). Please report it to the author of the 'priceanalyzer' custom integration.


@erlendsellie
Copy link
Owner

Thanks for the heads up!
Can you try with the latest beta and see if it works now?
I don't have much time and energy to maintain this repo at the moment, but this seemed kinda urgent

@erlendsellie erlendsellie reopened this May 1, 2024
@aherbjornsen
Copy link
Author

Thanks for the fast response.

I installed 1.5.3 beta, and the errors reported have disappeared

But the integration does not seem to load and I see this during startup:


2024-05-01 21:24:05.370 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry priceanalyzerOslo for priceanalyzer
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 575, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/priceanalyzer/__init__.py", line 270, in async_setup_entry
    res = await _dry_setup(hass, entry)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/priceanalyzer/__init__.py", line 235, in _dry_setup
    data = Data(
           ^^^^^
  File "/config/custom_components/priceanalyzer/data.py", line 172, in __init__
    self._multiply_template = cv.template(self._multiply_template)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 664, in template
    raise vol.Invalid("template value should be a string")
voluptuous.error.Invalid: template value should be a string

@erlendsellie
Copy link
Owner

I think this is a bug related to updating to above 1.5 (the betas).
Could you try to click "Configure" for the integration, and save it (no changes necessary) from /config/integrations/integration/priceanalyzer ?
The new multiply-template seems to cause some issues, and the "default when nothing is provided" fails.

@aherbjornsen
Copy link
Author

Yes, that worked.
Now the integration is back up again and seems to be working fine.
Thanks again!

@jreidel
Copy link

jreidel commented May 9, 2024

Similar problem with 2024.5.2, but latest beta + reconfigure (and restart HA) solved the problem.

@aherbjornsen
Copy link
Author

FWIW I still see asyncio related warning from priceanalyzer, using HA 2024.7.2:

2024-07-24 08:37:49.304 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/usr/local/lib/python3.12/site-packages/pytz/zoneinfo/Europe/Stockholm', 'rb') inside the event loop by custom integration 'priceanalyzer' at custom_components/priceanalyzer/init.py, line 207: tz=timezone("Europe/Stockholm"), (offender: /usr/local/lib/python3.12/site-packages/pytz/init.py, line 108: return open(filename, 'rb')), please create a bug report at https://github.com/erlendsellie/priceanalyzer/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open

@erlendsellie
Copy link
Owner

Fixed :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants