diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000000..7351defb7f5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "homeassistant/packages/pychromecast"] + path = homeassistant/packages/pychromecast + url = https://github.com/balloob/pychromecast.git diff --git a/README.md b/README.md index 5426dfeccd8..e05e8a11960 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Installation instructions ------------------------- * install python modules [python-dateutil](http://labix.org/python-dateutil), [PyEphem](http://rhodesmill.org/pyephem/), [Requests](http://python-requests.org) and [PHue](https://github.com/studioimaginaire/phue): `pip install python-dateutil pyephem requests phue` -* Clone the repository `git clone https://github.com/balloob/home-assistant.git`. +* Clone the repository and pull in the submodules `git clone --recursive https://github.com/balloob/home-assistant.git` * Copy home-assistant.conf.default to home-assistant.conf and adjust the config values to match your setup. * For Tomato you will have to not only setup your host, username and password but also a http_id. The http_id can be retrieved by going to the admin console of your router, view the source of any of the pages and search for `http_id`. * Setup PHue by running `python -m phue --host HUE_BRIDGE_IP_ADDRESS` from the commandline. diff --git a/homeassistant/actors.py b/homeassistant/actors.py index c973d436d4e..198a5d18757 100644 --- a/homeassistant/actors.py +++ b/homeassistant/actors.py @@ -16,6 +16,8 @@ import dateutil.parser from phue import Bridge import requests +from .packages.pychromecast import pychromecast + from . import track_state_change from .util import sanitize_filename from .observers import (STATE_CATEGORY_SUN, SUN_STATE_BELOW_HORIZON, SUN_STATE_ABOVE_HORIZON, @@ -28,7 +30,7 @@ HUE_MAX_TRANSITION_TIME = 9000 EVENT_DOWNLOAD_FILE = "download_file" EVENT_BROWSE_URL = "browse_url" - +EVENT_CHROMECAST_YOUTUBE_VIDEO = "chromecast.play_youtube_video" EVENT_TURN_LIGHT_ON = "turn_light_on" EVENT_TURN_LIGHT_OFF = "turn_light_off" @@ -244,3 +246,9 @@ def setup_file_downloader(eventbus, download_path): def setup_webbrowser(eventbus): """ Listen for browse_url events and opens the url in the default webbrowser. """ eventbus.listen(EVENT_BROWSE_URL, lambda event: webbrowser.open(event.data['url'])) + +def setup_chromecast(eventbus, host): + """ Listen for chromecast events. """ + eventbus.listen("start_fireplace", lambda event: pychromecast.play_youtube_video(host, "eyU3bRy2x44")) + eventbus.listen("start_epic_sax", lambda event: pychromecast.play_youtube_video(host, "kxopViU98Xo")) + eventbus.listen(EVENT_CHROMECAST_YOUTUBE_VIDEO, lambda event: pychromecast.play_youtube_video(host, event.data['video'])) diff --git a/homeassistant/packages/__init__.py b/homeassistant/packages/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/homeassistant/packages/pychromecast b/homeassistant/packages/pychromecast new file mode 160000 index 00000000000..6b8999574c8 --- /dev/null +++ b/homeassistant/packages/pychromecast @@ -0,0 +1 @@ +Subproject commit 6b8999574c8f70cb28686ef8d19f1e4bf0c8c056 diff --git a/start.py b/start.py index f85d80d2dc7..f300e5d819f 100644 --- a/start.py +++ b/start.py @@ -1,13 +1,13 @@ +#!/usr/bin/python2 +""" Starts home assistant with all possible functionality. """ + from ConfigParser import SafeConfigParser from homeassistant import StateMachine, EventBus, start_home_assistant - from homeassistant import observers from homeassistant import actors from homeassistant.httpinterface import HTTPInterface -from lib.pychromecast import play_youtube_video - # Read config config = SafeConfigParser() config.read("home-assistant.conf") @@ -17,21 +17,22 @@ eventbus = EventBus() statemachine = StateMachine(eventbus) # Init observers -tomato = observers.TomatoDeviceScanner(config.get('tomato','host'), config.get('tomato','username'), - config.get('tomato','password'), config.get('tomato','http_id')) +tomato = observers.TomatoDeviceScanner(config.get('tomato','host'), + config.get('tomato','username'), + config.get('tomato','password'), + config.get('tomato','http_id')) devicetracker = observers.DeviceTracker(eventbus, statemachine, tomato) -observers.track_sun(eventbus, statemachine, config.get("common","latitude"), config.get("common","longitude")) +observers.track_sun(eventbus, statemachine, + config.get("common","latitude"), + config.get("common","longitude")) # Init actors -actors.LightTrigger(eventbus, statemachine, devicetracker, actors.HueLightControl()) - -# If a chromecast is specified, add some chromecast specific event triggers -if config.has_option("chromecast", "host"): - eventbus.listen("start_fireplace", lambda event: play_youtube_video(config.get("chromecast","host"), "eyU3bRy2x44")) - eventbus.listen("start_epic_sax", lambda event: play_youtube_video(config.get("chromecast","host"), "kxopViU98Xo")) +actors.LightTrigger(eventbus, statemachine, + devicetracker, actors.HueLightControl()) +actors.setup_chromecast(eventbus, config.get("chromecast", "host")) actors.setup_file_downloader(eventbus, "downloads") actors.setup_webbrowser(eventbus)