From 59b410980ea715a962e5a24f36e41a77f0c50489 Mon Sep 17 00:00:00 2001 From: zhudhjen Date: Wed, 7 Aug 2024 12:31:26 -0700 Subject: [PATCH] Implement dashboard port from environment variable ESPHOME_DASHBOARD_PORT --- esphome/__main__.py | 2 +- esphome/dashboard/dashboard.py | 5 +++-- esphome/dashboard/settings.py | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/esphome/__main__.py b/esphome/__main__.py index 5c197ff486..9fbb81a532 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -889,7 +889,7 @@ def parse_args(argv): "--port", help="The HTTP port to open connections on. Defaults to 6052.", type=int, - default=6052, + default=0, ) parser_dashboard.add_argument( "--address", diff --git a/esphome/dashboard/dashboard.py b/esphome/dashboard/dashboard.py index 9de2d39ce2..ded34887f5 100644 --- a/esphome/dashboard/dashboard.py +++ b/esphome/dashboard/dashboard.py @@ -137,9 +137,10 @@ async def async_start(args) -> None: await dashboard.async_setup() sock: socket.socket | None = args.socket address: str | None = args.address - port: int | None = args.port - start_web_server(make_app(args.verbose), sock, address, port, settings.config_dir) + start_web_server( + make_app(args.verbose), sock, address, settings.port, settings.config_dir + ) if args.open_ui: import webbrowser diff --git a/esphome/dashboard/settings.py b/esphome/dashboard/settings.py index 1f05abab4c..4f2e522524 100644 --- a/esphome/dashboard/settings.py +++ b/esphome/dashboard/settings.py @@ -19,6 +19,7 @@ class DashboardSettings: "password_hash", "username", "using_password", + "port", "on_ha_addon", "cookie_secret", "absolute_config_dir", @@ -31,6 +32,7 @@ class DashboardSettings: self.password_hash: str = "" self.username: str = "" self.using_password: bool = False + self.port: int = 6052 self.on_ha_addon: bool = False self.cookie_secret: str | None = None self.absolute_config_dir: Path | None = None @@ -45,6 +47,7 @@ class DashboardSettings: self.using_password = bool(password) if self.using_password: self.password_hash = password_hash(password) + self.port = args.port or os.getenv("ESPHOME_DASHBOARD_PORT") or 6052 self.config_dir = args.configuration self.absolute_config_dir = Path(self.config_dir).resolve() self.verbose = args.verbose