Skip to content

Commit

Permalink
fix: async close (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw authored Sep 9, 2024
1 parent 69423d2 commit ac7b281
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
9 changes: 2 additions & 7 deletions aiocloudweather/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 3 additions & 2 deletions aiocloudweather/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ 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,
) -> None:
"""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:
Expand Down

0 comments on commit ac7b281

Please sign in to comment.