Bootstrap only loads modules into memory that it will init
parent
7a800a14be
commit
36e28dbc80
|
@ -31,6 +31,6 @@ download_dir=downloads
|
||||||
|
|
||||||
# A comma seperated list of states that have to be tracked
|
# A comma seperated list of states that have to be tracked
|
||||||
# As a single group
|
# As a single group
|
||||||
[groups]
|
[group]
|
||||||
living_room=light.Bowl,light.Ceiling,light.TV_back_light
|
living_room=light.Bowl,light.Ceiling,light.TV_back_light
|
||||||
bedroom=light.Bed_light
|
bedroom=light.Bed_light
|
||||||
|
|
|
@ -2,15 +2,12 @@
|
||||||
Provides methods to bootstrap a home assistant instance.
|
Provides methods to bootstrap a home assistant instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import importlib
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import homeassistant as ha
|
import homeassistant as ha
|
||||||
from homeassistant.components import (general, chromecast,
|
from homeassistant.components import general
|
||||||
device_sun_light_trigger, device_tracker,
|
|
||||||
downloader, keyboard, light, sun,
|
|
||||||
browser, httpinterface, group)
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
|
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
|
||||||
def from_config_file(config_path):
|
def from_config_file(config_path):
|
||||||
|
@ -33,6 +30,8 @@ def from_config_file(config_path):
|
||||||
get_opt = config.get
|
get_opt = config.get
|
||||||
has_section = config.has_section
|
has_section = config.has_section
|
||||||
add_status = lambda name, result: statusses.append((name, result))
|
add_status = lambda name, result: statusses.append((name, result))
|
||||||
|
load_module = lambda module: importlib.import_module(
|
||||||
|
'homeassistant.components.'+module)
|
||||||
|
|
||||||
def get_opt_safe(section, option, default=None):
|
def get_opt_safe(section, option, default=None):
|
||||||
""" Failure proof option retriever. """
|
""" Failure proof option retriever. """
|
||||||
|
@ -49,6 +48,8 @@ def from_config_file(config_path):
|
||||||
opt_fields = "host, username, password"
|
opt_fields = "host, username, password"
|
||||||
|
|
||||||
if has_section('device_tracker.tomato'):
|
if has_section('device_tracker.tomato'):
|
||||||
|
device_tracker = load_module('device_tracker')
|
||||||
|
|
||||||
dev_scan_name = "Tomato"
|
dev_scan_name = "Tomato"
|
||||||
opt_fields += ", http_id"
|
opt_fields += ", http_id"
|
||||||
|
|
||||||
|
@ -59,6 +60,8 @@ def from_config_file(config_path):
|
||||||
get_opt('device_tracker.tomato', 'http_id'))
|
get_opt('device_tracker.tomato', 'http_id'))
|
||||||
|
|
||||||
elif has_section('device_tracker.netgear'):
|
elif has_section('device_tracker.netgear'):
|
||||||
|
device_tracker = load_module('device_tracker')
|
||||||
|
|
||||||
dev_scan_name = "Netgear"
|
dev_scan_name = "Netgear"
|
||||||
|
|
||||||
dev_scan = device_tracker.NetgearDeviceScanner(
|
dev_scan = device_tracker.NetgearDeviceScanner(
|
||||||
|
@ -91,14 +94,20 @@ def from_config_file(config_path):
|
||||||
if has_opt("common", "latitude") and \
|
if has_opt("common", "latitude") and \
|
||||||
has_opt("common", "longitude"):
|
has_opt("common", "longitude"):
|
||||||
|
|
||||||
|
sun = load_module('sun')
|
||||||
|
|
||||||
add_status("Weather - Ephem",
|
add_status("Weather - Ephem",
|
||||||
sun.setup(
|
sun.setup(
|
||||||
bus, statemachine,
|
bus, statemachine,
|
||||||
get_opt("common", "latitude"),
|
get_opt("common", "latitude"),
|
||||||
get_opt("common", "longitude")))
|
get_opt("common", "longitude")))
|
||||||
|
else:
|
||||||
|
sun = None
|
||||||
|
|
||||||
# Chromecast
|
# Chromecast
|
||||||
if has_opt("chromecast", "host"):
|
if has_opt("chromecast", "host"):
|
||||||
|
chromecast = load_module('chromecast')
|
||||||
|
|
||||||
chromecast_started = chromecast.setup(bus, statemachine,
|
chromecast_started = chromecast.setup(bus, statemachine,
|
||||||
get_opt("chromecast", "host"))
|
get_opt("chromecast", "host"))
|
||||||
|
|
||||||
|
@ -108,28 +117,34 @@ def from_config_file(config_path):
|
||||||
|
|
||||||
# Light control
|
# Light control
|
||||||
if has_section("light.hue"):
|
if has_section("light.hue"):
|
||||||
|
light = load_module('light')
|
||||||
|
|
||||||
light_control = light.HueLightControl(get_opt_safe("hue", "host"))
|
light_control = light.HueLightControl(get_opt_safe("hue", "host"))
|
||||||
|
|
||||||
add_status("Light Control - Hue", light_control.success_init)
|
add_status("Light - Hue", light_control.success_init)
|
||||||
|
|
||||||
light.setup(bus, statemachine, light_control)
|
light.setup(bus, statemachine, light_control)
|
||||||
else:
|
else:
|
||||||
light_control = None
|
light_control = None
|
||||||
|
|
||||||
if has_opt("downloader", "download_dir"):
|
if has_opt("downloader", "download_dir"):
|
||||||
|
downloader = load_module('downloader')
|
||||||
|
|
||||||
add_status("Downloader", downloader.setup(
|
add_status("Downloader", downloader.setup(
|
||||||
bus, get_opt("downloader", "download_dir")))
|
bus, get_opt("downloader", "download_dir")))
|
||||||
|
|
||||||
# Currently only works with Chromecast or Light_Control
|
add_status("General", general.setup(bus, statemachine))
|
||||||
if chromecast_started or light_control:
|
|
||||||
add_status("General", general.setup(bus, statemachine))
|
|
||||||
|
|
||||||
add_status("Browser", browser.setup(bus))
|
if has_section('browser'):
|
||||||
|
add_status("Browser", load_module('browser').setup(bus))
|
||||||
|
|
||||||
add_status("Media Buttons", keyboard.setup(bus))
|
if has_section('keyboard'):
|
||||||
|
add_status("Keyboard", load_module('keyboard').setup(bus))
|
||||||
|
|
||||||
# Init HTTP interface
|
# Init HTTP interface
|
||||||
if has_opt("httpinterface", "api_password"):
|
if has_opt("httpinterface", "api_password"):
|
||||||
|
httpinterface = load_module('httpinterface')
|
||||||
|
|
||||||
httpinterface.HTTPInterface(
|
httpinterface.HTTPInterface(
|
||||||
bus, statemachine,
|
bus, statemachine,
|
||||||
get_opt("httpinterface", "api_password"))
|
get_opt("httpinterface", "api_password"))
|
||||||
|
@ -137,17 +152,21 @@ def from_config_file(config_path):
|
||||||
add_status("HTTPInterface", True)
|
add_status("HTTPInterface", True)
|
||||||
|
|
||||||
# Init groups
|
# Init groups
|
||||||
if has_section("groups"):
|
if has_section("group"):
|
||||||
for name, entity_ids in config.items("groups"):
|
group = load_module('group')
|
||||||
|
|
||||||
|
for name, entity_ids in config.items("group"):
|
||||||
add_status("Group - {}".format(name),
|
add_status("Group - {}".format(name),
|
||||||
group.setup(bus, statemachine, name,
|
group.setup(bus, statemachine, name,
|
||||||
entity_ids.split(",")))
|
entity_ids.split(",")))
|
||||||
|
|
||||||
# Light trigger
|
# Light trigger
|
||||||
if light_control:
|
if light_control and sun:
|
||||||
|
device_sun_light_trigger = load_module('device_sun_light_trigger')
|
||||||
|
|
||||||
light_group = get_opt_safe("device_sun_light_trigger", "light_group")
|
light_group = get_opt_safe("device_sun_light_trigger", "light_group")
|
||||||
|
|
||||||
add_status("Light Trigger",
|
add_status("Device Sun Light Trigger",
|
||||||
device_sun_light_trigger.setup(bus, statemachine,
|
device_sun_light_trigger.setup(bus, statemachine,
|
||||||
light_group))
|
light_group))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue