Added tracking state of ChromeCast
parent
87a66941d8
commit
08f4c70b4e
|
@ -25,13 +25,11 @@ LIGHT_TRANSITION_TIME = timedelta(minutes=15)
|
|||
|
||||
DOMAIN_DOWNLOADER = "downloader"
|
||||
DOMAIN_BROWSER = "browser"
|
||||
DOMAIN_CHROMECAST = "chromecast"
|
||||
DOMAIN_KEYBOARD = "keyboard"
|
||||
DOMAIN_LIGHT_CONTROL = "light_control"
|
||||
|
||||
SERVICE_DOWNLOAD_FILE = "download_file"
|
||||
SERVICE_BROWSE_URL = "browse_url"
|
||||
SERVICE_CHROMECAST_YOUTUBE_VIDEO = "play_youtube_video"
|
||||
SERVICE_TURN_LIGHT_ON = "turn_light_on"
|
||||
SERVICE_TURN_LIGHT_OFF = "turn_light_off"
|
||||
SERVICE_KEYBOARD_VOLUME_UP = "volume_up"
|
||||
|
@ -339,26 +337,6 @@ def setup_webbrowser(bus):
|
|||
return True
|
||||
|
||||
|
||||
def setup_chromecast(bus, host):
|
||||
""" Listen for chromecast events. """
|
||||
from homeassistant.packages import pychromecast
|
||||
|
||||
bus.register_service(DOMAIN_CHROMECAST, "start_fireplace",
|
||||
lambda event:
|
||||
pychromecast.play_youtube_video(host, "eyU3bRy2x44"))
|
||||
|
||||
bus.register_service(DOMAIN_CHROMECAST, "start_epic_sax",
|
||||
lambda event:
|
||||
pychromecast.play_youtube_video(host, "kxopViU98Xo"))
|
||||
|
||||
bus.register_service(DOMAIN_CHROMECAST, SERVICE_CHROMECAST_YOUTUBE_VIDEO,
|
||||
lambda event:
|
||||
pychromecast.play_youtube_video(host,
|
||||
event.data['video']))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def setup_media_buttons(bus):
|
||||
""" Listen for keyboard events. """
|
||||
try:
|
||||
|
|
|
@ -70,6 +70,12 @@ def from_config_file(config_path):
|
|||
config.get("common", "latitude"),
|
||||
config.get("common", "longitude"))))
|
||||
|
||||
if config.has_option("chromecast", "host"):
|
||||
statusses.append(("Chromecast",
|
||||
observers.setup_chromecast(
|
||||
bus, statemachine,
|
||||
config.get("chromecast", "host"))))
|
||||
|
||||
# --------------------------
|
||||
# Init actors
|
||||
# Light control
|
||||
|
@ -93,11 +99,6 @@ def from_config_file(config_path):
|
|||
|
||||
statusses.append(("Light Trigger", True))
|
||||
|
||||
if config.has_option("chromecast", "host"):
|
||||
statusses.append(("Chromecast",
|
||||
actors.setup_chromecast(
|
||||
bus, config.get("chromecast", "host"))))
|
||||
|
||||
if config.has_option("downloader", "download_dir"):
|
||||
result = actors.setup_file_downloader(
|
||||
bus, config.get("downloader", "download_dir"))
|
||||
|
|
|
@ -20,14 +20,20 @@ import requests
|
|||
import homeassistant as ha
|
||||
|
||||
DOMAIN_DEVICE_TRACKER = "device_tracker"
|
||||
DOMAIN_CHROMECAST = "chromecast"
|
||||
|
||||
SERVICE_DEVICE_TRACKER_RELOAD = "reload_devices_csv"
|
||||
SERVICE_CHROMECAST_YOUTUBE_VIDEO = "play_youtube_video"
|
||||
|
||||
STATE_CATEGORY_SUN = "weather.sun"
|
||||
STATE_ATTRIBUTE_NEXT_SUN_RISING = "next_rising"
|
||||
STATE_ATTRIBUTE_NEXT_SUN_SETTING = "next_setting"
|
||||
|
||||
STATE_CATEGORY_ALL_DEVICES = 'all_devices'
|
||||
STATE_CATEGORY_DEVICE_FORMAT = '{}'
|
||||
|
||||
STATE_CATEGORY_CHROMECAST = 'chromecast'
|
||||
|
||||
SUN_STATE_ABOVE_HORIZON = "above_horizon"
|
||||
SUN_STATE_BELOW_HORIZON = "below_horizon"
|
||||
|
||||
|
@ -95,6 +101,36 @@ def track_sun(bus, statemachine, latitude, longitude):
|
|||
return True
|
||||
|
||||
|
||||
def setup_chromecast(bus, statemachine, host):
|
||||
""" Listen for chromecast events. """
|
||||
from homeassistant.packages import pychromecast
|
||||
|
||||
bus.register_service(DOMAIN_CHROMECAST, "start_fireplace",
|
||||
lambda event:
|
||||
pychromecast.play_youtube_video(host, "eyU3bRy2x44"))
|
||||
|
||||
bus.register_service(DOMAIN_CHROMECAST, "start_epic_sax",
|
||||
lambda event:
|
||||
pychromecast.play_youtube_video(host, "kxopViU98Xo"))
|
||||
|
||||
bus.register_service(DOMAIN_CHROMECAST, SERVICE_CHROMECAST_YOUTUBE_VIDEO,
|
||||
lambda event:
|
||||
pychromecast.play_youtube_video(host,
|
||||
event.data['video']))
|
||||
|
||||
def update_chromecast_state(time): # pylint: disable=unused-argument
|
||||
""" Retrieve state of Chromecast and update statemachine. """
|
||||
status = pychromecast.get_app_status(host)
|
||||
|
||||
statemachine.set_state(STATE_CATEGORY_CHROMECAST, status.name,
|
||||
{"state": status.state,
|
||||
"options": status.options})
|
||||
|
||||
ha.track_time_change(bus, update_chromecast_state)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class DeviceTracker(object):
|
||||
""" Class that tracks which devices are home and which are not. """
|
||||
|
||||
|
|
Loading…
Reference in New Issue