PyChromecast properly integrated now.

This commit is contained in:
Paulus Schoutsen 2013-10-07 20:23:05 -07:00
parent 9cfcf43202
commit df53b05423
6 changed files with 27 additions and 14 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "homeassistant/packages/pychromecast"]
path = homeassistant/packages/pychromecast
url = https://github.com/balloob/pychromecast.git

View File

@ -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.

View File

@ -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']))

View File

@ -0,0 +1 @@
Subproject commit 6b8999574c8f70cb28686ef8d19f1e4bf0c8c056

View File

@ -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)