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

Unable to delete a device #2578

Open
4 tasks done
felipecrs opened this issue Nov 30, 2024 · 7 comments
Open
4 tasks done

Unable to delete a device #2578

felipecrs opened this issue Nov 30, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@felipecrs
Copy link
Contributor

Description

I'm unable to delete a Tuya Local device:

chrome_xpjDAOtZGG.mp4

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

  • I am sure this is a bug or improvement, that is well enough described that it can be implemented.

  • If this is for a specific device, the device config is mentioned above, or diagnostics are included.

  • Log messages or diagnostics relevant to the issue are included.

  • This is not requesting addition of a new device.

@felipecrs felipecrs added the bug Something isn't working label Nov 30, 2024
@make-all make-all moved this to 🔖 Ready in Tuya Local Dec 1, 2024
@make-all
Copy link
Owner

make-all commented Dec 1, 2024

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.

@make-all make-all moved this from 🔖 Ready to 🏗 Stalled in Tuya Local Dec 1, 2024
@felipecrs
Copy link
Contributor Author

What probably happened is that some previous delete attempt actually deleted all the entities, and now this error is happening. I'll investigate more.

@felipecrs
Copy link
Contributor Author

Oh, just realized that the entity got re-created on Home Assistant restart. I can now try to delete it again:

chrome_Jc8GUqfcdN.mp4

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.

@felipecrs felipecrs closed this as not planned Won't fix, can't repro, duplicate, stale Dec 1, 2024
@github-project-automation github-project-automation bot moved this from 🏗 Stalled to ✅ Done in Tuya Local Dec 1, 2024
@felipecrs
Copy link
Contributor Author

@make-all, I was able to find the exact and reproduceable situation where this happens:

  1. Have a device working normally in Tuya Local
  2. Unplug it from power
  3. Attempt to Reload the device entry in Tuya Local
  4. Wait for the entities to become Unavailable
  5. Attempt to delete the device

This error will happen.

@felipecrs felipecrs reopened this Dec 1, 2024
@github-project-automation github-project-automation bot moved this from ✅ Done to 📋 Backlog in Tuya Local Dec 1, 2024
@make-all make-all moved this from 📋 Backlog to 🔖 Ready in Tuya Local Dec 13, 2024
@make-all
Copy link
Owner

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 make-all moved this from 🔖 Ready to 🏗 Stalled in Tuya Local Dec 15, 2024
@felipecrs
Copy link
Contributor Author

felipecrs commented Dec 15, 2024

@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:

  1. Have a device working normally in Tuya Local
  2. Unplug it from power
  3. Attempt to Reload the device entry in Tuya Local (right away, you must not wait for it to become unavailable naturally)
  4. Wait for the entities to become Unavailable
  5. 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.

@felipecrs
Copy link
Contributor Author

felipecrs commented Dec 15, 2024

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 #1804.

@make-all make-all mentioned this issue Dec 22, 2024
4 tasks
@make-all make-all moved this from 🏗 Stalled to Connection handling in Tuya Local Dec 29, 2024
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
Status: Connection handling
Development

No branches or pull requests

2 participants