From 7b5524cfdb9aa8d947dfaf53b6f072196265722f Mon Sep 17 00:00:00 2001 From: Daniel <49846893+danielbrunt57@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:06:18 -0700 Subject: [PATCH] fix: delete cookiefile when removing config entry (#2462) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- custom_components/alexa_media/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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",