diff --git a/custom_components/alexa_media/__init__.py b/custom_components/alexa_media/__init__.py index dadc1b2b..689b2a74 100644 --- a/custom_components/alexa_media/__init__.py +++ b/custom_components/alexa_media/__init__.py @@ -11,6 +11,7 @@ from datetime import datetime, timedelta from json import JSONDecodeError, loads import logging +import os import time from typing import Optional @@ -1288,6 +1289,7 @@ async def http2_error_handler(message): async def async_unload_entry(hass, entry) -> bool: """Unload a config entry.""" email = entry.data["email"] + login_obj = hass.data[DATA_ALEXAMEDIA]["accounts"][email]["login_obj"] _LOGGER.debug("Attempting to unload entry for %s", hide_email(email)) for component in ALEXA_COMPONENTS + DEPENDENT_ALEXA_COMPONENTS: _LOGGER.debug("Forwarding unload entry to %s", component) @@ -1329,6 +1331,15 @@ async def async_unload_entry(hass, entry) -> bool: _LOGGER.debug("Removing alexa_media data structure") if hass.data.get(DATA_ALEXAMEDIA): hass.data.pop(DATA_ALEXAMEDIA) + # Delete cookiefile + try: + await login_obj.delete_cookiefile() + _LOGGER.debug("Deleted cookiefile") + except Exception as ex: + _LOGGER.error( + "Failed to delete cookiefile: %s", + ex, + ) else: _LOGGER.debug( "Unable to remove alexa_media data structure: %s",