Skip to content

Commit

Permalink
Added command line toggle to open UI on start
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Jan 18, 2015
1 parent 1f32ce2 commit 50eecd1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ def __init__(self):
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):
Expand Down
17 changes: 17 additions & 0 deletions homeassistant/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from homeassistant import bootstrap

from homeassistant.const import EVENT_HOMEASSISTANT_START


def validate_dependencies():
""" Validate all dependencies that HA uses. """
Expand Down Expand Up @@ -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()

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

Expand Down
5 changes: 1 addition & 4 deletions homeassistant/components/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 50eecd1

Please sign in to comment.