diff --git a/aiocloudweather/proxy.py b/aiocloudweather/proxy.py index 79de681..8cf29d5 100644 --- a/aiocloudweather/proxy.py +++ b/aiocloudweather/proxy.py @@ -21,15 +21,10 @@ def __init__(self, proxied_sinks: list[DataSink], dns_servers: list[str]): self.proxied_sinks = proxied_sinks self.session = ClientSession(connector=TCPConnector(resolver=resolver)) - def __del__(self): - """Close the session when the object is deleted.""" - if not self.session.closed: - self.session.close() - - def close(self): + async def close(self): """Close the session.""" if not self.session.closed: - self.session.close() + await self.session.close() async def forward_wunderground(self, request: web.Request) -> web.Response: """Forward Wunderground data to their API.""" diff --git a/aiocloudweather/server.py b/aiocloudweather/server.py index 8f04720..5656fb0 100644 --- a/aiocloudweather/server.py +++ b/aiocloudweather/server.py @@ -54,7 +54,7 @@ def __init__( # storage self.stations: list[str] = [] - def update_config( + async def update_config( self, proxy_sinks: list[DataSink] | None = None, dns_servers: list[str] | None = None, @@ -62,7 +62,8 @@ def update_config( """Update the proxy configuration.""" self.proxy_enabled = proxy_sinks and len(proxy_sinks) > 0 if self.proxy_enabled: - self.proxy.close() + if self.proxy: + await self.proxy.close() self.proxy = CloudWeatherProxy(proxy_sinks, dns_servers or ["9.9.9.9"]) async def _new_dataset_cb(self, dataset: WeatherStation) -> None: