From 5c91a6cd48cfcb57c64333b6368e6406f8cd8d78 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 20 Aug 2019 12:43:50 -0700 Subject: [PATCH] Fix open-ui cli arg (#26091) * Fix open-ui cli command * Align add_job typing with async_add_job --- homeassistant/__main__.py | 26 ++++---------------------- homeassistant/core.py | 2 +- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index d21bfb5a71a..8ec2a8c2d3c 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -10,12 +10,7 @@ import threading from typing import List, Dict, Any, TYPE_CHECKING # noqa pylint: disable=unused-import from homeassistant import monkey_patch -from homeassistant.const import ( - __version__, - EVENT_HOMEASSISTANT_START, - REQUIRED_PYTHON_VER, - RESTART_EXIT_CODE, -) +from homeassistant.const import __version__, REQUIRED_PYTHON_VER, RESTART_EXIT_CODE if TYPE_CHECKING: from homeassistant import core @@ -309,23 +304,10 @@ async def setup_and_run_hass(config_dir: str, args: argparse.Namespace) -> int: log_no_color=args.log_no_color, ) - if args.open_ui: - # Imported here to avoid importing asyncio before monkey patch - from homeassistant.util.async_ import run_callback_threadsafe + if args.open_ui and hass.config.api is not None: + import webbrowser - def open_browser(_: Any) -> None: - """Open the web interface in a browser.""" - if hass.config.api is not None: - import webbrowser - - webbrowser.open(hass.config.api.base_url) - - run_callback_threadsafe( - hass.loop, - hass.bus.async_listen_once, - EVENT_HOMEASSISTANT_START, - open_browser, - ) + hass.add_job(webbrowser.open, hass.config.api.base_url) return await hass.async_run() diff --git a/homeassistant/core.py b/homeassistant/core.py index a205aa401a6..e8e33a0479e 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -276,7 +276,7 @@ class HomeAssistant: self.state = CoreState.running _async_create_timer(self) - def add_job(self, target: Callable[..., None], *args: Any) -> None: + def add_job(self, target: Callable[..., Any], *args: Any) -> None: """Add job to the executor pool. target: target to call.