Unable to delete a device
Description
I'm unable to delete a Tuya Local device:
https://github.com/user-attachments/assets/f8643bfb-260f-4265-84e1-4c05accb174a
If the problem cannot be fixed, do you have any tip on how I can force-delete this device?
Steps to reproduce
N/A
Expected behaviour
Other devices I can delete just fine, I was expecting to be able to delete this one too.
Additional context
Logger: homeassistant.config_entries
Source: config_entries.py:850
First occurred: 4:48:20 PM (1 occurrences)
Last logged: 4:48:20 PM
Error unloading entry Portão do terreiro for cover
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 850, in async_unload
result = await component.async_unload_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/cover/__init__.py", line 259, in async_unload_entry
return await hass.data[DATA_COMPONENT].async_unload_entry(entry)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in async_unload_entry
raise ValueError("Config entry was never loaded!")
ValueError: Config entry was never loaded!
Debug logs:
2024-11-30 16:48:20.077 DEBUG (MainThread) [custom_components.tuya_local] Unloading entry for device: 11716514c82b960dc435
2024-11-30 16:48:20.078 DEBUG (SyncWorker_47) [custom_components.tuya_local.helpers.device_config] Loaded device config garage_door_opener.yaml
2024-11-30 16:48:20.079 ERROR (MainThread) [homeassistant.config_entries] Error unloading entry Portão do terreiro for cover
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 850, in async_unload
result = await component.async_unload_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/cover/__init__.py", line 259, in async_unload_entry
return await hass.data[DATA_COMPONENT].async_unload_entry(entry)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in async_unload_entry
raise ValueError("Config entry was never loaded!")
ValueError: Config entry was never loaded!
2024-11-30 16:48:20.080 INFO (MainThread) [custom_components.tuya_local.device] Deleting device: 11716514c82b960dc435
2024-11-30 16:48:20.080 DEBUG (MainThread) [custom_components.tuya_local.device] Stopping monitor loop for Portão do terreiro
Diagnostics:
config_entry-tuya_local-dce9241ea93d89d91b21320960ddae1e.json
Confirmation
-
[X] I am sure this is a bug or improvement, that is well enough described that it can be implemented.
-
[X] If this is for a specific device, the device config is mentioned above, or diagnostics are included.
-
[X] Log messages or diagnostics relevant to the issue are included.
-
[X] This is not requesting addition of a new device.
This doesn't seem to be due to the integration, but something else that is going on in Home Assistant.
There are no entities associated with this device according to the diagnostics, so I guess something has gone wrong earlier and now the HA registry is in an inconsistent state. But without knowing what went wrong, and capturing the log of that, I can't really see anything that can be done.
What probably happened is that some previous delete attempt actually deleted all the entities, and now this error is happening. I'll investigate more.
Oh, just realized that the entity got re-created on Home Assistant restart. I can now try to delete it again:
https://github.com/user-attachments/assets/f56c303a-a01e-4adf-8eb6-5d16dfd25c79
Worked!
I guess indeed nothing can be done about this. I'll close, but if it ever happens again, I'll try to get logs since the beginning.
@make-all, I was able to find the exact and reproduceable situation where this happens:
- Have a device working normally in Tuya Local
- Unplug it from power
- Attempt to Reload the device entry in Tuya Local
- Wait for the entities to become Unavailable
- Attempt to delete the device
This error will happen.
I was unable to reproduce the problem following the steps above. It looks like restarting HA works for getting out of this state, which seems to have some convoluted abnormal preconditions for getting into in the first place, so I will deprioritise this again now.
@make-all, I was trying to reproduce it again with latest version and found a situation where I could not reproduce it. The situation was: if I unplug power from it but wait for it to become unavailable in Tuya Local naturally, then this issue does not happen.
Thus, here is my reviewed procedure:
- Have a device working normally in Tuya Local
- Unplug it from power
- Attempt to Reload the device entry in Tuya Local (right away, you must not wait for it to become unavailable naturally)
- Wait for the entities to become Unavailable
- Attempt to delete the device
The device does not get deleted.
Notes:
- I added right away, you must not wait for it to become unavailable naturally to 3.
- For this test, I was using a protocol 3.5 device, I suggest you try with one with the same protocol version.
This may be complete science fiction, but I believe the problem is when the integration tries to control/connect to a device while it still thinks its online (when in fact it's offline). This renders the integration into a stuck state, where only restarting Home Assistant helps. And I believe the same root cause is one of the things affecting https://github.com/make-all/tuya-local/issues/1804.