From 0bd95e2d892a4fc5fab59f69820cc0f66029ca94 Mon Sep 17 00:00:00 2001 From: Lennart Weller Date: Sun, 9 Jun 2024 20:31:22 +0200 Subject: [PATCH] feat: Allow updating proxy settings after installation for options flow (#6) feat: Allow updating proxy settings at runtime for options flow --- .devcontainer/devcontainer.json | 18 ++++++++++-------- aiocloudweather/server.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3a144bb..ef0b1aa 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,15 +1,17 @@ - { "name": "aiocloudweather", "image": "mcr.microsoft.com/devcontainers/python:1-3.12-bookworm", "postCreateCommand": "pip3 install -e .", - "runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"], + "runArgs": [ + "-e", + "GIT_EDITOR=code --wait", + "--privileged" + ], "customizations": { "extensions": [ "ms-python.python", - "github.vscode-pull-request-github", - "ryanluker.vscode-coverage-gutters", - "ms-python.vscode-pylance" + "ms-python.vscode-pylance", + "ms-python.black-formatter" ], "settings": { "terminal.integrated.profiles.linux": { @@ -30,8 +32,8 @@ "python.formatting.provider": "black", "python.formatting.blackPath": "/usr/local/py-utils/bin/black", "python.linting.pylintArgs": [ - "--disable=C0114,C0115,C0116" + "--disable=C0114,C0115,C0116" ] -} + } } -} +} \ No newline at end of file diff --git a/aiocloudweather/server.py b/aiocloudweather/server.py index 07ffbdb..c9315cd 100644 --- a/aiocloudweather/server.py +++ b/aiocloudweather/server.py @@ -54,6 +54,16 @@ def __init__( # storage self.stations: list[str] = [] + 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 = CloudWeatherProxy(proxy_sinks, dns_servers or ["9.9.9.9"]) + async def _new_dataset_cb(self, dataset: WeatherStation) -> None: """Internal new sensor callback