More error checking added on start
parent
9f24101348
commit
c3c1383ae6
|
@ -3,6 +3,7 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
|
import importlib
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from homeassistant import bootstrap
|
from homeassistant import bootstrap
|
||||||
|
@ -45,14 +46,43 @@ def main():
|
||||||
unittest.main(module='homeassistant.test')
|
unittest.main(module='homeassistant.test')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
config_path = os.path.join(args.config, 'home-assistant.conf')
|
# Validate that all core dependencies are installed
|
||||||
|
import_fail = False
|
||||||
|
|
||||||
|
for module in ['requests']:
|
||||||
|
try:
|
||||||
|
importlib.import_module(module)
|
||||||
|
except ImportError:
|
||||||
|
import_fail = True
|
||||||
|
print(
|
||||||
|
'Fatal Error: Unable to find dependency {}'.format(module))
|
||||||
|
|
||||||
|
if import_fail:
|
||||||
|
print(("Install dependencies by running: "
|
||||||
|
"pip3 install -r requirements.txt"))
|
||||||
|
exit()
|
||||||
|
|
||||||
|
# Test if configuration directory exists
|
||||||
|
config_dir = os.path.join(os.getcwd(), args.config)
|
||||||
|
|
||||||
|
if not os.path.isdir(config_dir):
|
||||||
|
print(('Fatal Error: Unable to find specified configuration '
|
||||||
|
'directory {} ').format(config_dir))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
config_path = os.path.join(config_dir, 'home-assistant.conf')
|
||||||
|
|
||||||
# Ensure a config file exists to make first time usage easier
|
# Ensure a config file exists to make first time usage easier
|
||||||
if not os.path.isfile(config_path):
|
if not os.path.isfile(config_path):
|
||||||
with open(config_path, 'w') as conf:
|
try:
|
||||||
conf.write("[http]\n")
|
with open(config_path, 'w') as conf:
|
||||||
conf.write("api_password=password\n\n")
|
conf.write("[http]\n")
|
||||||
conf.write("[demo]\n")
|
conf.write("api_password=password\n\n")
|
||||||
|
conf.write("[demo]\n")
|
||||||
|
except IOError:
|
||||||
|
print(('Fatal Error: No configuration file found and unable '
|
||||||
|
'to write a default one to {}').format(config_path))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
hass = bootstrap.from_config_file(config_path)
|
hass = bootstrap.from_config_file(config_path)
|
||||||
hass.start()
|
hass.start()
|
||||||
|
|
|
@ -91,7 +91,8 @@ def _get_component(module):
|
||||||
comp = importlib.import_module(module)
|
comp = importlib.import_module(module)
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
_LOGGER.exception("Error loading {}".format(module))
|
_LOGGER.exception(("Error loading {}. Make sure all "
|
||||||
|
"dependencies are installed").format(module))
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue