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

RuntimeError: 'hon' calls async_write_ha_state #269

Open
gio-dzilla opened this issue Dec 19, 2024 · 13 comments
Open

RuntimeError: 'hon' calls async_write_ha_state #269

gio-dzilla opened this issue Dec 19, 2024 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@gio-dzilla
Copy link

Describe the bug

RuntimeError: Detected that custom integration 'hon' calls async_write_ha_state from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt.

Environment (please complete the following information):

  • Core 2024.12.4
  • Supervisor 2024.12.0
  • hOn Integration Version 0.14.0
  • pyhOn Version [e.g. 0.13.1, can be found in device log]

Home Assistant Logs

RuntimeError: Detected that custom integration 'hon' calls async_write_ha_state from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#async_write_ha_state at custom_components/hon/sensor.py, line 877: self.async_write_ha_state(). Please report it to the author of the 'hon' custom integration
Exception ignored in: <class 'RuntimeError'>
Traceback (most recent call last):
File "/usr/local/lib/python3.13/site-packages/awscrt/mqtt5.py", line 1471, in _on_publish
self._on_publish_cb(PublishReceivedData(publish_packet=publish_packet))
File "/usr/local/lib/python3.13/site-packages/pyhon/connection/mqtt.py", line 105, in _on_publish_received
self._hon.notify()
File "/usr/local/lib/python3.13/site-packages/pyhon/hon.py", line 130, in notify
self._notify_function(None)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 514, in async_set_updated_data
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 177, in async_update_listeners
update_callback()
File "/config/custom_components/hon/sensor.py", line 877, in _handle_coordinator_update
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1022, in async_write_ha_state
report_non_thread_safe_operation("async_write_ha_state")
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 368, in report_non_thread_safe_operation
report(
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 164, in report
report_usage(
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 242, in report_usage
_report_integration_frame(
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 340, in _report_integration_frame
raise RuntimeError( from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#async_write_ha_state at custom_components/hon/sensor.py, line 877: self.async_write_ha_state(). Please report it to the author of the 'hon' custom integration

dw_10067.zip

Data Archive
For further analysis, please add your appliance data archive here (if available)
Navigate to Settings -> Device & Services -> Haier hOn -> your device and press the Create Data Archive button.
Then open notifications to download the data zip archive.
To attach the file:

  • GitHub Web: Use the "Attach files by dragging & dropping, selecting or pasting them." function
  • GitHub Mobile: Upload the zip archive as image
@gio-dzilla gio-dzilla added the bug Something isn't working label Dec 19, 2024
@galvani
Copy link

galvani commented Dec 26, 2024

same here, and the status of appliance is not being update, only on reload

2024-12-26 09:47:03.917 WARNING (MainThread) [homeassistant.helpers.frame] Detected code that calls async_forward_entry_setup for integration hon with title: [email protected] and entry_id: 01JG1xxxxxxxxxxxxxxx, during setup without awaiting async_forward_entry_setup, which can cause the setup lock to be released before the setup is done. This will stop working in Home Assistant 2025.1, please report this issue
homeassistant  | Stack (most recent call last):
homeassistant  |   File "<frozen runpy>", line 198, in _run_module_as_main
homeassistant  |   File "<frozen runpy>", line 88, in _run_code
homeassistant  |   File "/usr/src/homeassistant/homeassistant/__main__.py", line 227, in <module>
homeassistant  |     sys.exit(main())
homeassistant  |   File "/usr/src/homeassistant/homeassistant/__main__.py", line 213, in main
homeassistant  |     exit_code = runner.run(runtime_conf)
homeassistant  |   File "/usr/src/homeassistant/homeassistant/runner.py", line 154, in run
homeassistant  |     return loop.run_until_complete(setup_and_run_hass(runtime_config))
homeassistant  |   File "/usr/local/lib/python3.13/asyncio/base_events.py", line 708, in run_until_complete
homeassistant  |     self.run_forever()
homeassistant  |   File "/usr/local/lib/python3.13/asyncio/base_events.py", line 679, in run_forever
homeassistant  |     self._run_once()
homeassistant  |   File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2027, in _run_once
homeassistant  |     handle._run()
homeassistant  |   File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run
homeassistant  |     self._context.run(self._callback, *self._args)
homeassistant  |   File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2353, in async_forward_entry_setup
homeassistant  |     _report_non_awaited_platform_forwards(entry, "async_forward_entry_setup")
homeassistant  |   File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1199, in _report_non_awaited_platform_forwards
homeassistant  |     report_usage(
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 234, in report_usage
homeassistant  |     _LOGGER.warning(msg, stack_info=True)

@gio-dzilla
Copy link
Author

Same. I have an automation that reloads the integration every X minutes. I am not sure though how good it is for the system.

@galvani
Copy link

galvani commented Dec 28, 2024

Same. I have an automation that reloads the integration every X minutes. I am not sure though how good it is for the system.

Could you share the automation, I don't know how to reload whole integration and reloading just entity does not work well. e.g. phase which fails with:

2024-12-27 22:30:00.180 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.hd_495ambb_1_s_phase fails
homeassistant  | Traceback (most recent call last):
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 960, in async_update_ha_state
homeassistant  |     await self.async_device_update()
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1318, in async_device_update
homeassistant  |     await self.async_update()
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 596, in async_update
homeassistant  |     await self.coordinator.async_request_refresh()
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 274, in async_request_refresh
homeassistant  |     await self._debounced_refresh.async_call()
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 114, in async_call
homeassistant  |     await task
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 355, in async_refresh
homeassistant  |     await self._async_refresh(log_failures=True)
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 379, in _async_refresh
homeassistant  |     self.data = await self._async_update_data()
homeassistant  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 279, in _async_update_data
homeassistant  |     raise NotImplementedError("Update method not implemented")
homeassistant  | NotImplementedError: Update method not implemented

yet another issue is:

homeassistant  | 2024-12-27 22:30:10.181 ERROR (MainThread) [custom_components.hon] Unexpected exception from <bound method DataUpdateCoordinator.async_refresh of <homeassistant.helpers.update_coordinator.DataUpdateCoordinator object at 0x7f6c251810>>
homeassistant  | Traceback (most recent call last):
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 137, in _handle_timer_finish
homeassistant  |     await task
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 355, in async_refresh
homeassistant  |     await self._async_refresh(log_failures=True)
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 379, in _async_refresh
homeassistant  |     self.data = await self._async_update_data()
homeassistant  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 279, in _async_update_data
homeassistant  |     raise NotImplementedError("Update method not implemented")
homeassistant  | NotImplementedError: Update method not implemented

@galvani
Copy link

galvani commented Dec 29, 2024

@gio-dzilla I managed with help of AI to enable updating. I have created a pull request
#274

you can overwrite the custom_components/hon with this branch: https://github.com/galvani/hon/tree/fix/fix-updating-entity

@gio-dzilla
Copy link
Author

gio-dzilla commented Dec 29, 2024

@gio-dzilla I managed with help of AI to enable updating. I have created a pull request #274

you can overwrite the custom_components/hon with this branch: https://github.com/galvani/hon/tree/fix/fix-updating-entity

Amazing! You are a star! Thanks for working on this.

@KameDomotics
Copy link

@gio-dzilla I managed with help of AI to enable updating. I have created a pull request

#274

you can overwrite the custom_components/hon with this branch: https://github.com/galvani/hon/tree/fix/fix-updating-entity

I can't open this link, "try again error"

@galvani
Copy link

galvani commented Dec 31, 2024

works just fine at my end, it's github

@gio-dzilla
Copy link
Author

@gio-dzilla I managed with help of AI to enable updating. I have created a pull request
#274
you can overwrite the custom_components/hon with this branch: https://github.com/galvani/hon/tree/fix/fix-updating-entity

I can't open this link, "try again error"

Works fine for me too

@KameDomotics
Copy link

works just fine at my end, it's github

I currently don't have any hOn integrations installed (because they all had problems). If I wanted to install one directly with your fix, which repository should I download it from?

@KameDomotics
Copy link

works just fine at my end, it's github

Adding your repo, I can't even download the custom component

image

@galvani
Copy link

galvani commented Jan 1, 2025

I did not create the package, you should have just overwritten the files in your installation. now I did. event the hacs method should wiork:
image

@KameDomotics
Copy link

Unfortunately it doesn't work, it's the usual problems and limitations imposed by Haier some time ago.
I haven't used it for months due to the constant problems and unreliability, I will continue not to use it.

(failed to set up error)

@gio-dzilla
Copy link
Author

Unfortunately it doesn't work, it's the usual problems and limitations imposed by Haier some time ago. I haven't used it for months due to the constant problems and unreliability, I will continue not to use it.

(failed to set up error)

It’s working for me. It doesn’t resolve the other issues with the integration, but at least now the info are updated regularly and reliably I just downloaded the file that @galvani edited and upload it to the custom_component/hon folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants