-
Notifications
You must be signed in to change notification settings - Fork 413
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
When unloading the integration, runtime errors occur #1888
Comments
I'm seeing the same after upgrade to 2024.5.2 today. Here are my logs 2024-05-06 18:30:05.727 ERROR (MainThread) [homeassistant.components.lock] Error while removing entity lock.kantoor_1_child_lock During handling of the above exception, another exception occurred: Traceback (most recent call last): The integration itself says: "Failed to unload" |
Hmmm, this seems to be related to the reload workaround using "Home Assistant Core Integration: Reload config entry -> entity-ID". When disabled there are no errors in the log anymore. |
That is a trigger, not a cause. The bug will still show up whenever the integration is stopped. |
I am seeing this too after upgrade to 2024.5.2 today. The integration itself says ‘Failed to unload’. Anyone has figured out any workaround ? |
This fixes it but I don't know if it's a correct and complete fix:
to
|
Hey mate, I tried this but then my integration won’t reload devices at all |
For me the reload is slower - sometimes quite a bit slower but it does reload the device seemingly correctly in the logs: And if I made local edits to the device yaml it is reflected post-reload. |
I just tried it again and it worked ok. I’ll try it for a few days and report back. Earlier when it wasn’t working was on a device that was unavailable in HA but was available in the Tuya app and it wouldn’t reload, just hung. |
I suspect without that change, there may be a conflict causing a failure, and the delay waiting for the device to finish unloading should avoid that |
I think with that fix it's going to actually wait on the device so if the device is hung the reload will hang too? |
Fix works for me also |
async_actually_start was originally written to execute in the event loop. Since HA was modified to automatically run non-decorated coroutines in the executor thread, this has been running in the wrong thread, making some of its calls non-thread safe. - Revert previous fix for #1871, #1872 (PR #1876), as it is not needed when actually_start is running in the event loop, and has a side effect of causing #1888 (a separate fix for that has been proposed on the issue, but this revert also avoids that issue). Issue #1917
2024-05-05 11:36:06.537 DEBUG (MainThread) [custom_components.tuya_local] Unloading entry for device: REDACTED
2024-05-05 11:36:06.538 DEBUG (MainThread) [custom_components.tuya_local.helpers.device_config] Loaded device config simple_dual_switch.yaml
2024-05-05 11:36:06.538 DEBUG (MainThread) [custom_components.tuya_local.device] Stopping monitor loop for Dual switch
2024-05-05 11:36:06.538 ERROR (MainThread) [homeassistant.components.switch] Error while removing entity switch.dual_switch_switch_2
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1353, in async_remove
await self.__async_remove_impl(force_remove)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1369, in __async_remove_impl
await self.async_will_remove_from_hass()
File "/config/custom_components/tuya_local/helpers/mixin.py", line 111, in async_will_remove_from_hass
await self._device.async_unregister_entity(self)
File "/config/custom_components/tuya_local/device.py", line 195, in async_unregister_entity
await self.async_stop()
File "/config/custom_components/tuya_local/device.py", line 170, in async_stop
await self._refresh_task
TypeError: object Future can't be used in 'await' expression
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 908, in async_reset
await entity.async_remove()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1358, in async_remove
self.__remove_future.set_result(None)
asyncio.exceptions.InvalidStateError: invalid state
2024-05-05 11:36:06.540 INFO (MainThread) [custom_components.tuya_local.device] Deleting device: REDACTED
2024-05-05 11:36:06.540 DEBUG (MainThread) [custom_components.tuya_local.device] Stopping monitor loop for Dual switch
2024-05-05 11:36:06.540 ERROR (MainThread) [homeassistant.config_entries] Error unloading entry Dual switch for tuya_local
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 724, in async_unload
result = await component.async_unload_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/tuya_local/init.py", line 517, in async_unload_entry
await async_delete_device(hass, config)
File "/config/custom_components/tuya_local/device.py", line 655, in async_delete_device
await hass.data[DOMAIN][device_id]["device"].async_stop()
File "/config/custom_components/tuya_local/device.py", line 170, in async_stop
await self._refresh_task
TypeError: object Future can't be used in 'await' expression
2024-05-05 11:36:06.921 WARNING (MainThread) [custom_components.tuya_local.device] Dual switch receive loop has terminated
The text was updated successfully, but these errors were encountered: