Merge remote-tracking branch 'up/master' into luci-checker

This commit is contained in:
Markus Stenberg committed 2014-04-24 16:31:03 +03:00
commit fc6c2fbc18
19 files changed
+786 -755

No files matched your search

+47 -37
View File
@@ -1,31 +1,38 @@
"""
Provides methods to bootstrap a home assistant instance.
Each method will return a tuple (bus, statemachine).
After bootstrapping you can add your own components or
start by calling homeassistant.start_home_assistant(bus)
"""
import importlib
import configparser
import logging
import homeassistant as ha
import homeassistant
import homeassistant.components as components
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
def from_config_file(config_path):
def from_config_file(config_path, enable_logging=True):
""" Starts home assistant with all possible functionality
based on a config file. """
based on a config file.
Will return a tuple (bus, statemachine). """
# Setup the logging for home assistant.
logging.basicConfig(level=logging.INFO)
if enable_logging:
# Setup the logging for home assistant.
logging.basicConfig(level=logging.INFO)
# Log errors to a file
err_handler = logging.FileHandler("home-assistant.log",
mode='w', delay=True)
err_handler.setLevel(logging.ERROR)
err_handler.setFormatter(
logging.Formatter('%(asctime)s %(name)s: %(message)s',
datefmt='%H:%M %d-%m-%y'))
logging.getLogger('').addHandler(err_handler)
# Log errors to a file
err_handler = logging.FileHandler("home-assistant.log",
mode='w', delay=True)
err_handler.setLevel(logging.ERROR)
err_handler.setFormatter(
logging.Formatter('%(asctime)s %(name)s: %(message)s',
datefmt='%H:%M %d-%m-%y'))
logging.getLogger('').addHandler(err_handler)
# Start the actual bootstrapping
logger = logging.getLogger(__name__)
@@ -37,8 +44,7 @@ def from_config_file(config_path):
config.read(config_path)
# Init core
bus = ha.Bus()
statemachine = ha.StateMachine(bus)
hass = homeassistant.HomeAssistant()
has_opt = config.has_option
get_opt = config.get
@@ -54,6 +60,13 @@ def from_config_file(config_path):
except (configparser.NoSectionError, configparser.NoOptionError):
return default
def get_hosts(section):
""" Helper method to retrieve hosts from config. """
if has_opt(section, "hosts"):
return get_opt(section, "hosts").split(",")
else:
return None
# Device scanner
dev_scan = None
@@ -110,7 +123,7 @@ def from_config_file(config_path):
# Device Tracker
if dev_scan:
device_tracker.DeviceTracker(bus, statemachine, dev_scan)
device_tracker.DeviceTracker(hass, dev_scan)
add_status("Device Tracker", True)
@@ -120,11 +133,10 @@ def from_config_file(config_path):
sun = load_module('sun')
add_status("Weather - Ephem",
sun.setup(
bus, statemachine,
get_opt("common", "latitude"),
get_opt("common", "longitude")))
add_status("Sun",
sun.setup(hass,
get_opt("common", "latitude"),
get_opt("common", "longitude")))
else:
sun = None
@@ -132,17 +144,17 @@ def from_config_file(config_path):
if has_section("chromecast"):
chromecast = load_module('chromecast')
chromecast_started = chromecast.setup(bus, statemachine)
hosts = get_hosts("chromecast")
add_status("Chromecast", chromecast_started)
else:
chromecast_started = False
add_status("Chromecast", chromecast.setup(hass, hosts))
# WeMo
if has_section("wemo"):
wemo = load_module('wemo')
add_status("WeMo", wemo.setup(bus, statemachine))
hosts = get_hosts("wemo")
add_status("WeMo", wemo.setup(hass, hosts))
# Light control
if has_section("light.hue"):
@@ -153,7 +165,7 @@ def from_config_file(config_path):
add_status("Light - Hue", light_control.success_init)
if light_control.success_init:
light.setup(bus, statemachine, light_control)
light.setup(hass, light_control)
else:
light_control = None
@@ -164,23 +176,22 @@ def from_config_file(config_path):
downloader = load_module('downloader')
add_status("Downloader", downloader.setup(
bus, get_opt("downloader", "download_dir")))
hass, get_opt("downloader", "download_dir")))
add_status("Core components", components.setup(bus, statemachine))
add_status("Core components", components.setup(hass))
if has_section('browser'):
add_status("Browser", load_module('browser').setup(bus))
add_status("Browser", load_module('browser').setup(hass))
if has_section('keyboard'):
add_status("Keyboard", load_module('keyboard').setup(bus))
add_status("Keyboard", load_module('keyboard').setup(hass))
# Init HTTP interface
if has_opt("httpinterface", "api_password"):
httpinterface = load_module('httpinterface')
httpinterface.HTTPInterface(
bus, statemachine,
get_opt("httpinterface", "api_password"))
hass, get_opt("httpinterface", "api_password"))
add_status("HTTPInterface", True)
@@ -190,8 +201,7 @@ def from_config_file(config_path):
for name, entity_ids in config.items("group"):
add_status("Group - {}".format(name),
group.setup(bus, statemachine, name,
entity_ids.split(",")))
group.setup(hass, name, entity_ids.split(",")))
# Light trigger
if light_control and sun:
@@ -202,7 +212,7 @@ def from_config_file(config_path):
"light_profile")
add_status("Device Sun Light Trigger",
device_sun_light_trigger.setup(bus, statemachine,
device_sun_light_trigger.setup(hass,
light_group, light_profile))
for component, success_init in statusses:
@@ -210,4 +220,4 @@ def from_config_file(config_path):
logger.info("{}: {}".format(component, status))
ha.start_home_assistant(bus)
return hass