home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.8k stars 30.05k forks source link

Cannot remove broken device / configuration entry #110449

Closed RoepLuke closed 7 months ago

RoepLuke commented 7 months ago

The problem

I was unable to enable/disable any sensors in the WearOS Companion App and therefore had to reinstall it. This went without a Problem. But that's unrelated, and enabling / disabling the sensors works again.

To make sure I had a clean starting ground, I tried to disable and remove the old configuration entry and gave the new one a different name. Disabling the old configuration entry is possible and (after a bit of trial and error) doesn't interfere with the new one. grafik

Removing the old, disabled configuration entry is currently not possible. grafik The attached errors appear in the Logs, and it is then in the state "not loaded" (or still disabled, if it was before). In this state, it can only be disabled or reloaded, which succeeds but effectively changes nothing.

The cloud hook mentioned in the Error message does no longer exist. It did at one point exist, but was (it seems) successfully deleted in one of the attempts to remove the configuration entry. But it seems to me that's not the problem, it is just expected to exist when removing a mobile_app configuration entry and then fails if it doesn't exist.

Something doesn't seem to work when trying to remove the configuration entry itself, or some part of it is broken.

[...]
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 149, in handle
result = await handler(request, **request.match_info)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 88, in delete
result = await hass.config_entries.async_remove(entry_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1282, in async_remove
del self._entries[entry.entry_id]
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1191, in __delitem__
self._unindex_entry(entry_id)
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1178, in _unindex_entry
self._domain_index[domain].remove(entry)
ValueError: list.remove(x): x not in list

I don't have a problem leaving the disabled configuration entry in my instance, but maybe it can be fixed or prevented for others.

Thank you very much!

What version of Home Assistant Core has the issue?

core-2024.2.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

mobile_app

Link to integration documentation on our website

https://www.home-assistant.io/integrations/mobile_app/

Diagnostics information

There is no such option for this integration.

Example YAML snippet

No response

Anything in the logs that might be useful for us?

####### Exactly when trying to remove the device the following is logged ##################

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 645, in async_remove
    await component.async_remove_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/mobile_app/__init__.py", line 154, in async_remove_entry
    await cloud.async_delete_cloudhook(hass, entry.data[CONF_WEBHOOK_ID])
  File "/usr/src/homeassistant/homeassistant/components/cloud/__init__.py", line 220, in async_delete_cloudhook
    await hass.data[DOMAIN].cloudhooks.async_delete(webhook_id)
  File "/usr/local/lib/python3.12/site-packages/hass_nabucasa/cloudhooks.py", line 72, in async_delete
    raise ValueError("Hook is not enabled for the cloud.")
ValueError: Hook is not enabled for the cloud.

###########################   And then follows this ##################################

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 91, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 94, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 149, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 88, in delete
    result = await hass.config_entries.async_remove(entry_id)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1282, in async_remove
    del self._entries[entry.entry_id]
        ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1191, in __delitem__
    self._unindex_entry(entry_id)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1178, in _unindex_entry
    self._domain_index[domain].remove(entry)
ValueError: list.remove(x): x not in list

Additional information

Any other device of any integration can be removed without any issues. Other Devices of the mobile_app integration work perfectly fine and can be removed without issues.

This is in contrast to #37956 where the whole HA Instance was broken.

home-assistant[bot] commented 7 months ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (mobile_app) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `mobile_app` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign mobile_app` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


mobile_app documentation mobile_app source (message by IssueLinks)

amaisano commented 7 months ago

Same problem. I used to be able to remove broken devices by just deleting them from the integration list, but starting this month, i get that little "Not Loaded" message and cannnot remove it. For me, it's a work Macbook that sometimes creates duplicate devices.

ventourist commented 7 months ago

Also here exactly same problem for a Samsung smartphone device in Mobile Apps integration, that I tried to remove. (in version HA core-2024.2.2)

carverofchoice commented 7 months ago

Same problem, I can't remove a Pixel 8 Pro. It just says "Not Loaded" and stays listed.

I wanted to delete it because it keeps switching the entity name back and forth between calling it pixel_8_pro and my_name_pixel_8_pro and every couple of days the sensors will all say they don't exist, and I have to switch it back to the other name then it will switch again and I have to back and change all the entities to the other name (ie: on dashboards and automations, etc). So I tried deleting it and then redoing it, but it won't delete, So I tried to disable it, but then won't let me use the new setup. It also locks up the new creation and I can only assign the old "not loaded" one to a profile, the new one won't even show up.

Definitely a huge bug here.

Reiner-W commented 7 months ago

Same problem at my fresh installation. After re-login with my Apple devices, I had to set new device names because the old ones already exists. After successfully logging on, I can't see any way how to remove these old device names. Is there any idea how to remove these orphaned devices? Maybe with changes in a config file or in the database ? Please help. Thanks.

dshokouhi commented 7 months ago

I am personally unable to reproduce this error

Reiner-W commented 7 months ago
Bildschirmfoto 2024-02-21 um 20 10 13

OK. How can the two devices _"to_be_deleted1" and _"to_be_deleted2" be deleted? Please advice. Thanks.

dshokouhi commented 7 months ago

Go to Settings > Devices & Services > Mobile App, do you see the entries there? thats where you should be deleting it from but I think that has issues for cloud users at least what the error suggests since its having issues removing the cloud hook.

RoepLuke commented 7 months ago

Today (after updating to the newest Version a few days ago) I tried again to delete the old mobile_app configuration entry (not the device) and now it worked. I still got a WebHook Error in the Logs but I think that's just because it was already deleted.

Traceback (most recent call last): 
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 645, in async_remove await component.async_remove_entry(hass, self) 
File "/usr/src/homeassistant/homeassistant/components/mobile_app/__init__.py", line 154, in async_remove_entry await cloud.async_delete_cloudhook(hass, entry.data[CONF_WEBHOOK_ID]) 
File "/usr/src/homeassistant/homeassistant/components/cloud/__init__.py", line 220, in async_delete_cloudhook await hass.data[DOMAIN].cloudhooks.async_delete(webhook_id) 
File "/usr/local/lib/python3.12/site-packages/hass_nabucasa/cloudhooks.py", line 72, in async_delete raise ValueError("Hook is not enabled for the cloud.") 
ValueError: Hook is not enabled for the cloud.

And I discovered the debug log function on the integration page. Anyone still having the problem might want to create and share this.

Reiner-W commented 7 months ago

Go to Settings > Devices & Services > Mobile App, do you see the entries there? thats where you should be deleting it from but I think that has issues for cloud users at least what the error suggests since its having issues removing the cloud hook.

Good Morning Daniel, thanks for your response. I was exactly at this setup page and saw two deactivated devices (iPad, MacBookPro), but not theses both "to_bedeleted" devices which I can see only by clicking on the Devices tab at the Mobile App.

So I have deleted the deactivated iPad and MacBookPro device in the Mobile App. After that, the both "to_bedeleted" disappeared as well. Problem is now solved.

Some time ago, I had renamed 2 devices from iPad and MacBookPro to "to_be_deleted_1" and "to_be_deleted2" to be able to logon again withe exactly these two device names. It seems that the renamed devices only displayed at "> Settings > Devices & Services > Devices tab" and "> Settings > Devices & Services > Mobile App > Devices tab", but not directly at "> Settings > Devices & Services > Mobile App_".

Anyhow, thanks again for your tip.