Handle when installed app has already been removed (#21595)

This commit is contained in:
Andrew Sayre 2019-03-02 21:57:57 -06:00 committed by GitHub
parent 18372ad81b
commit 1e60993aa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,10 +48,20 @@ async def async_migrate_entry(hass: HomeAssistantType, entry: ConfigEntry):
""" """
from pysmartthings import SmartThings from pysmartthings import SmartThings
# Delete the installed app # Remove the installed_app, which if already removed raises a 403 error.
api = SmartThings(async_get_clientsession(hass), api = SmartThings(async_get_clientsession(hass),
entry.data[CONF_ACCESS_TOKEN]) entry.data[CONF_ACCESS_TOKEN])
await api.delete_installed_app(entry.data[CONF_INSTALLED_APP_ID]) installed_app_id = entry.data[CONF_INSTALLED_APP_ID]
try:
await api.delete_installed_app(installed_app_id)
except ClientResponseError as ex:
if ex.status == 403:
_LOGGER.exception("Installed app %s has already been removed",
installed_app_id)
else:
raise
_LOGGER.debug("Removed installed app %s", installed_app_id)
# Delete the entry # Delete the entry
hass.async_create_task( hass.async_create_task(
hass.config_entries.async_remove(entry.entry_id)) hass.config_entries.async_remove(entry.entry_id))