Reorg: Merged observers, actors and HTTPInterface into components

This commit is contained in:
Paulus Schoutsen
2013-12-11 00:07:30 -08:00
parent c5f5dcbce2
commit dd271febae
19 changed files with 795 additions and 659 deletions

View File

@@ -6,9 +6,10 @@ import ConfigParser
import logging
import homeassistant as ha
import homeassistant.observers as observers
import homeassistant.actors as actors
import homeassistant.httpinterface as httpinterface
from homeassistant.components import (general, chromecast,
device_sun_light_trigger, device,
downloader, keyboard, light, sun,
browser, httpinterface)
# pylint: disable=too-many-branches
@@ -26,25 +27,22 @@ def from_config_file(config_path):
bus = ha.Bus()
statemachine = ha.StateMachine(bus)
# Init observers
# Device scanner
if config.has_option('tomato', 'host') and \
config.has_option('tomato', 'username') and \
config.has_option('tomato', 'password') and \
config.has_option('tomato', 'http_id'):
device_scanner = observers.TomatoDeviceScanner(
device_scanner = device.TomatoDeviceScanner(
config.get('tomato', 'host'),
config.get('tomato', 'username'),
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))
statusses.append(("Device Scanner - Tomato",
device_scanner.success_init))
if not device_scanner.success_init:
device_scanner = None
else:
@@ -52,7 +50,7 @@ def from_config_file(config_path):
# Device Tracker
if device_scanner:
observers.DeviceTracker(bus, statemachine, device_scanner)
device.DeviceTracker(bus, statemachine, device_scanner)
statusses.append(("Device Tracker", True))
@@ -61,25 +59,26 @@ def from_config_file(config_path):
config.has_option("common", "longitude"):
statusses.append(("Weather - Ephem",
observers.track_sun(
sun.setup(
bus, statemachine,
config.get("common", "latitude"),
config.get("common", "longitude"))))
# Chromecast
if config.has_option("chromecast", "host"):
statusses.append(("Chromecast",
observers.setup_chromecast(
bus, statemachine,
config.get("chromecast", "host"))))
chromecast_started = chromecast.setup(bus, statemachine,
config.get("chromecast", "host"))
statusses.append(("Chromecast", chromecast_started))
else:
chromecast_started = False
# --------------------------
# Init actors
# Light control
if config.has_section("hue"):
if config.has_option("hue", "host"):
light_control = actors.HueLightControl(config.get("hue", "host"))
light_control = light.HueLightControl(config.get("hue", "host"))
else:
light_control = actors.HueLightControl()
light_control = light.HueLightControl()
statusses.append(("Light Control - Hue", light_control.success_init))
@@ -88,18 +87,22 @@ def from_config_file(config_path):
# Light trigger
if light_control:
observers.setup_light_control(bus, statemachine, light_control)
light.setup(bus, statemachine, light_control)
statusses.append(("Light Trigger", actors.setup_device_light_triggers(
statusses.append(("Light Trigger", device_sun_light_trigger.setup(
bus, statemachine)))
if config.has_option("downloader", "download_dir"):
statusses.append(("Downloader", actors.setup_file_downloader(
statusses.append(("Downloader", downloader.setup(
bus, config.get("downloader", "download_dir"))))
statusses.append(("Webbrowser", actors.setup_webbrowser(bus)))
# Currently only works with Chromecast or Light_Control
if chromecast_started or light_control:
statusses.append(("General", general.setup(bus, statemachine)))
statusses.append(("Media Buttons", actors.setup_media_buttons(bus)))
statusses.append(("Browser", browser.setup(bus)))
statusses.append(("Media Buttons", keyboard.setup(bus)))
# Init HTTP interface
if config.has_option("httpinterface", "api_password"):