From 923acfebc6b6c3a1eca62bfa820953999cdbd3dc Mon Sep 17 00:00:00 2001 From: Erik Kastelec Date: Wed, 10 May 2023 08:44:34 +0200 Subject: [PATCH] Few changes related to memory leak #72 --- custom_components/wemportal/coordinator.py | 1 + custom_components/wemportal/wemportalapi.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/custom_components/wemportal/coordinator.py b/custom_components/wemportal/coordinator.py index 3bd6846..5da33fe 100644 --- a/custom_components/wemportal/coordinator.py +++ b/custom_components/wemportal/coordinator.py @@ -58,6 +58,7 @@ async def _async_update_data(self): self.config_entry.data.get(CONF_PASSWORD), self.config_entry.options, ) + del self.api self.api = new_api except Exception as exc2: raise UpdateFailed from exc2 diff --git a/custom_components/wemportal/wemportalapi.py b/custom_components/wemportal/wemportalapi.py index bac4952..3b844f1 100644 --- a/custom_components/wemportal/wemportalapi.py +++ b/custom_components/wemportal/wemportalapi.py @@ -182,6 +182,8 @@ def api_login(self): "AppVersion": "2.0.2", "ClientOS": "Android", } + if self.session is not None: + self.session.close() self.session = reqs.Session() self.session.cookies.clear() self.session.headers.update(self.headers)