Making the config bootstrap more verbose about what started

This commit is contained in:
Paulus Schoutsen 2013-10-21 22:06:22 -07:00
parent 0d156ecbf0
commit 05472481c5
3 changed files with 76 additions and 16 deletions

View file

@ -3,16 +3,20 @@ Provides methods to bootstrap a home assistant instance.
"""
import ConfigParser
import logging
import homeassistant as ha
import homeassistant.observers as observers
import homeassistant.actors as actors
import homeassistant.httpinterface as httpinterface
# pylint: disable=too-many-branches
def from_config_file(config_path):
""" Starts home assistant with all possible functionality
based on a config file. """
statusses = []
# Read config
config = ConfigParser.SafeConfigParser()
config.read(config_path)
@ -34,6 +38,14 @@ def from_config_file(config_path):
config.get('tomato','password'),
config.get('tomato','http_id'))
if device_scanner.success_init:
statusses.append(("Device Scanner - Tomato", True))
else:
statusses.append(("Device Scanner - Tomato", False))
device_scanner = None
else:
device_scanner = None
@ -42,6 +54,9 @@ def from_config_file(config_path):
if device_scanner:
device_tracker = observers.DeviceTracker(eventbus, statemachine,
device_scanner)
statusses.append(("Device Tracker", True))
else:
device_tracker = None
@ -50,19 +65,21 @@ def from_config_file(config_path):
if config.has_option("common", "latitude") and \
config.has_option("common", "longitude"):
observers.track_sun(eventbus, statemachine,
config.get("common","latitude"),
config.get("common","longitude"))
statusses.append(("Weather - Ephem",
observers.track_sun(eventbus, statemachine,
config.get("common","latitude"),
config.get("common","longitude"))))
# Init actors
# Light control
if config.has_section("hue"):
if config.has_option("hue", "host"):
hue_host = config.get("hue", "host")
else:
hue_host = None
if config.has_section("hue") and config.has_option("hue", "host"):
light_control = actors.HueLightControl(config.get("hue", "host"))
light_control = actors.HueLightControl(hue_host)
statusses.append(("Light Control - Hue", light_control.success_init))
else:
light_control = None
# Light trigger
@ -70,22 +87,38 @@ def from_config_file(config_path):
actors.LightTrigger(eventbus, statemachine,
device_tracker, light_control)
statusses.append(("Light Trigger", True))
if config.has_option("chromecast", "host"):
actors.setup_chromecast(eventbus, config.get("chromecast", "host"))
statusses.append(("Chromecast", actors.setup_chromecast(eventbus,
config.get("chromecast", "host"))))
if config.has_option("downloader", "download_dir"):
actors.setup_file_downloader(eventbus,
result = actors.setup_file_downloader(eventbus,
config.get("downloader", "download_dir"))
actors.setup_webbrowser(eventbus)
actors.setup_media_buttons(eventbus)
statusses.append(("Downloader", result))
statusses.append(("Webbrowser", actors.setup_webbrowser(eventbus)))
statusses.append(("Media Buttons", actors.setup_media_buttons(eventbus)))
# Init HTTP interface
if config.has_option("httpinterface", "api_password"):
httpinterface.HTTPInterface(eventbus, statemachine,
config.get("httpinterface","api_password"))
statusses.append(("HTTPInterface", True))
logger = logging.getLogger(__name__)
for component, success_init in statusses:
status = "initialized" if success_init else "Failed to initialize"
logger.info("{}: {}".format(component, status))
ha.start_home_assistant(eventbus)