Skip to content

Commit

Permalink
Adds support for Roku Search API
Browse files Browse the repository at this point in the history
  • Loading branch information
keatontaylor committed Jun 19, 2017
1 parent d127932 commit 33e1575
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion homeassistant/components/media_player/roku.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
from homeassistant.components.media_player import (
MEDIA_TYPE_VIDEO, SUPPORT_NEXT_TRACK, SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
SUPPORT_SELECT_SOURCE, SUPPORT_PLAY, MediaPlayerDevice, PLATFORM_SCHEMA)
SUPPORT_SELECT_SOURCE, SUPPORT_PLAY, MediaPlayerDevice, PLATFORM_SCHEMA,
MEDIA_PLAYER_SCHEMA, DOMAIN)
from homeassistant.const import (
CONF_HOST, STATE_IDLE, STATE_PLAYING, STATE_UNKNOWN, STATE_HOME)
from homeassistant.helpers.service import extract_entity_ids
import homeassistant.helpers.config_validation as cv
import homeassistant.loader as loader

Expand All @@ -31,6 +33,22 @@
SUPPORT_PLAY_MEDIA | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE |\
SUPPORT_SELECT_SOURCE | SUPPORT_PLAY

SERVICE_ROKU_SEARCH = 'roku_search'

ATTR_TITLE = 'title'
ATTR_SEASON = 'season'
ATTR_LAUNCH = 'launch'
ATTR_PROVIDERS = 'provider_id'
ATTR_VIDEO_TYPE = 'video_type'

ROKU_SEARCH_SCHEMA = MEDIA_PLAYER_SCHEMA.extend({
vol.Required(ATTR_TITLE): cv.string,
vol.Optional(ATTR_SEASON): cv.string,
vol.Optional(ATTR_LAUNCH): cv.string,
vol.Optional(ATTR_PROVIDERS): cv.string,
vol.Optional(ATTR_VIDEO_TYPE): cv.string
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_HOST): cv.string,
})
Expand Down Expand Up @@ -75,6 +93,30 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID)

def search_handler(call):
for roku in service_to_entities(call):
if call.service == SERVICE_ROKU_SEARCH:
title = call.data.get(ATTR_TITLE)
season = call.data.get(ATTR_SEASON)
launch = call.data.get(ATTR_LAUNCH)
provider_id = call.data.get(ATTR_PROVIDER_ID)
video_type = call.data.get(ATTR_VIDEO_TYPE)
roku.search(title, season, launch, provider_id, video_type)

def service_to_entities(call):
"""Return the known devices that a service call mentions."""
entity_ids = extract_entity_ids(hass, call)
if entity_ids:
entities = [entity for entity in rokus
if entity.entity_id in entity_ids]
else:
entities = rokus

return entities

hass.services.register(DOMAIN, SERVICE_ROKU_SEARCH, search_handler,
schema=ROKU_SEARCH_SCHEMA)

add_devices(rokus)


Expand Down Expand Up @@ -235,3 +277,10 @@ def select_source(self, source):
else:
channel = self.roku[source]
channel.launch()

def search(self, title, season=None, launch=None, provider_id=None, video_type=None):
"""Search on roku."""
if self.current_app is not None:
self.roku.search(title, season, launch, provider_id, video_type)


0 comments on commit 33e1575

Please sign in to comment.