Added command line toggle to open UI on start

pull/24/head
Paulus Schoutsen 2015-01-17 21:13:02 -08:00
parent 1f32ce2ca4
commit 50eecd11c1
4 changed files with 25 additions and 5 deletions

View File

@ -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'.

View File

@ -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):

View File

@ -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()

View File

@ -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