From 50eecd11c1cccbcb8a04bacf94f1fac61e250934 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 17 Jan 2015 21:13:02 -0800 Subject: [PATCH] Added command line toggle to open UI on start --- README.md | 2 +- homeassistant/__init__.py | 6 ++++++ homeassistant/__main__.py | 17 +++++++++++++++++ homeassistant/components/http/__init__.py | 5 +---- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3740181f362..518ea881f31 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ git clone --recursive https://github.com/balloob/home-assistant.git cd home-assistant pip3 install -r requirements.txt -python3 -m homeassistant +python3 -m homeassistant --open-ui ``` This will start the Home Assistant server and create an initial configuration file in `config/home-assistant.conf` that is setup for demo mode. It will launch its web interface on [http://127.0.0.1:8123](http://127.0.0.1:8123). The default password is 'password'. diff --git a/homeassistant/__init__.py b/homeassistant/__init__.py index 9cf8144b45a..155b58c7b4c 100644 --- a/homeassistant/__init__.py +++ b/homeassistant/__init__.py @@ -51,8 +51,14 @@ class HomeAssistant(object): self.bus = EventBus(pool) self.services = ServiceRegistry(self.bus, pool) self.states = StateMachine(self.bus) + + # List of loaded components self.components = [] + # Remote.API object pointing at local API + self.local_api = None + + # Directory that holds the configuration self.config_dir = os.path.join(os.getcwd(), 'config') def get_config_path(self, path): diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index edda63b72c0..808545fe791 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -17,6 +17,8 @@ except ImportError: from homeassistant import bootstrap +from homeassistant.const import EVENT_HOMEASSISTANT_START + def validate_dependencies(): """ Validate all dependencies that HA uses. """ @@ -72,6 +74,10 @@ def main(): metavar='path_to_config_dir', default="config", help="Directory that contains the Home Assistant configuration") + parser.add_argument( + '--open-ui', + action='store_true', + help='Open the webinterface in a browser') args = parser.parse_args() @@ -82,6 +88,17 @@ def main(): config_path = ensure_config_path(config_dir) hass = bootstrap.from_config_file(config_path) + + if args.open_ui: + # pylint: disable=unused-argument + def open_browser(event): + """ Open the webinterface in a browser. """ + if hass.local_api is not None: + import webbrowser + webbrowser.open(hass.local_api.base_url) + + hass.bus.listen_once(EVENT_HOMEASSISTANT_START, open_browser) + hass.start() hass.block_till_stopped() diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index a50ed7c9845..8b3f4635ab7 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -141,10 +141,7 @@ def setup(hass, config): lambda event: threading.Thread(target=server.start, daemon=True).start()) - # If no local api set, set one with known information - if isinstance(hass, rem.HomeAssistant) and hass.local_api is None: - hass.local_api = \ - rem.API(util.get_local_ip(), api_password, server_port) + hass.local_api = rem.API(util.get_local_ip(), api_password, server_port) return True