mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Increased environment validation upon start
This commit is contained in:
parent
dbefeb3f6b
commit
99c87ff862
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -7,3 +7,6 @@
|
|||||||
[submodule "homeassistant/external/netdisco"]
|
[submodule "homeassistant/external/netdisco"]
|
||||||
path = homeassistant/external/netdisco
|
path = homeassistant/external/netdisco
|
||||||
url = https://github.com/balloob/netdisco.git
|
url = https://github.com/balloob/netdisco.git
|
||||||
|
[submodule "homeassistant/external/noop"]
|
||||||
|
path = homeassistant/external/noop
|
||||||
|
url = https://github.com/balloob/noop.git
|
||||||
|
@ -1,24 +1,19 @@
|
|||||||
""" Starts home assistant. """
|
""" Starts home assistant. """
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
try:
|
|
||||||
from homeassistant import bootstrap
|
|
||||||
|
|
||||||
except ImportError:
|
def validate_python():
|
||||||
# This is to add support to load Home Assistant using
|
""" Validate we're running the right Python version. """
|
||||||
# `python3 homeassistant` instead of `python3 -m homeassistant`
|
major, minor = sys.version_info[:2]
|
||||||
|
|
||||||
# Insert the parent directory of this file into the module search path
|
if major < 3 or (major == 3 and minor < 4):
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
print("Home Assistant requires atleast Python 3.4")
|
||||||
|
sys.exit()
|
||||||
from homeassistant import bootstrap
|
|
||||||
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
|
||||||
from homeassistant.components import http, demo
|
|
||||||
|
|
||||||
|
|
||||||
def validate_dependencies():
|
def validate_dependencies():
|
||||||
@ -39,6 +34,34 @@ def validate_dependencies():
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_path_and_load_bootstrap():
|
||||||
|
""" Ensure sys load path is correct and load Home Assistant bootstrap. """
|
||||||
|
try:
|
||||||
|
from homeassistant import bootstrap
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
# This is to add support to load Home Assistant using
|
||||||
|
# `python3 homeassistant` instead of `python3 -m homeassistant`
|
||||||
|
|
||||||
|
# Insert the parent directory of this file into the module search path
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||||
|
|
||||||
|
from homeassistant import bootstrap
|
||||||
|
|
||||||
|
return bootstrap
|
||||||
|
|
||||||
|
|
||||||
|
def validate_git_submodules():
|
||||||
|
""" Validate the git submodules are cloned. """
|
||||||
|
try:
|
||||||
|
# pylint: disable=no-name-in-module, unused-variable
|
||||||
|
from homeassistant.external.noop import WORKING # noqa
|
||||||
|
except ImportError:
|
||||||
|
print("Repository submodules have not been initialized")
|
||||||
|
print("Please run: git submodule update --init --recursive")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
def ensure_config_path(config_dir):
|
def ensure_config_path(config_dir):
|
||||||
""" Gets the path to the configuration file.
|
""" Gets the path to the configuration file.
|
||||||
Creates one if it not exists. """
|
Creates one if it not exists. """
|
||||||
@ -65,9 +88,8 @@ def ensure_config_path(config_dir):
|
|||||||
return config_path
|
return config_path
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def get_arguments():
|
||||||
""" Starts Home Assistant. Will create demo config if no config found. """
|
""" Get parsed passed in arguments. """
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--config',
|
'-c', '--config',
|
||||||
@ -83,15 +105,26 @@ def main():
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help='Open the webinterface in a browser')
|
help='Open the webinterface in a browser')
|
||||||
|
|
||||||
args = parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
""" Starts Home Assistant. """
|
||||||
|
validate_python()
|
||||||
validate_dependencies()
|
validate_dependencies()
|
||||||
|
|
||||||
config_dir = os.path.join(os.getcwd(), args.config)
|
bootstrap = ensure_path_and_load_bootstrap()
|
||||||
|
|
||||||
|
validate_git_submodules()
|
||||||
|
|
||||||
|
args = get_arguments()
|
||||||
|
|
||||||
|
config_dir = os.path.join(os.getcwd(), args.config)
|
||||||
config_path = ensure_config_path(config_dir)
|
config_path = ensure_config_path(config_dir)
|
||||||
|
|
||||||
if args.demo_mode:
|
if args.demo_mode:
|
||||||
|
from homeassistant.components import http, demo
|
||||||
|
|
||||||
# Demo mode only requires http and demo components.
|
# Demo mode only requires http and demo components.
|
||||||
hass = bootstrap.from_config_dict({
|
hass = bootstrap.from_config_dict({
|
||||||
http.DOMAIN: {},
|
http.DOMAIN: {},
|
||||||
@ -101,6 +134,8 @@ def main():
|
|||||||
hass = bootstrap.from_config_file(config_path)
|
hass = bootstrap.from_config_file(config_path)
|
||||||
|
|
||||||
if args.open_ui:
|
if args.open_ui:
|
||||||
|
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||||
|
|
||||||
def open_browser(event):
|
def open_browser(event):
|
||||||
""" Open the webinterface in a browser. """
|
""" Open the webinterface in a browser. """
|
||||||
if hass.local_api is not None:
|
if hass.local_api is not None:
|
||||||
|
1
homeassistant/external/noop
vendored
Submodule
1
homeassistant/external/noop
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 45fae73c1f44342010fa07f3ed8909bf2819a508
|
Loading…
x
Reference in New Issue
Block a user