diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index fec4515756c..294fccbb1f5 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -190,6 +190,16 @@ def media_previous_track(hass, entity_id=None): hass.services.call(DOMAIN, SERVICE_MEDIA_PREVIOUS_TRACK, data) +def play_media(hass, media_type, media_id, entity_id=None): + """ Send the media player the command for playing media. """ + data = {"media_type": media_type, "media_id": media_id} + + if entity_id: + data[ATTR_ENTITY_ID] = entity_id + + hass.services.call(DOMAIN, SERVICE_PLAY_MEDIA, data) + + def setup(hass, config): """ Track states and offer events for media_players. """ component = EntityComponent( @@ -287,8 +297,8 @@ def setup(hass, config): def play_media_service(service): """ Plays specified media_id on the media player. """ - media_type = service.data['media_type'] - media_id = service.data['media_id'] + media_type = service.data.get('media_type') + media_id = service.data.get('media_id') if media_type is None: return diff --git a/homeassistant/components/media_player/cast.py b/homeassistant/components/media_player/cast.py index 61223446e5f..6f622c9e0cc 100644 --- a/homeassistant/components/media_player/cast.py +++ b/homeassistant/components/media_player/cast.py @@ -90,6 +90,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class CastDevice(MediaPlayerDevice): """ Represents a Cast device on the network. """ + # pylint: disable=abstract-method # pylint: disable=too-many-public-methods def __init__(self, host): diff --git a/homeassistant/helpers/state.py b/homeassistant/helpers/state.py index 909b86a67ed..6526fe2d90b 100644 --- a/homeassistant/helpers/state.py +++ b/homeassistant/helpers/state.py @@ -13,6 +13,8 @@ from homeassistant.const import ( SERVICE_MEDIA_PLAY, SERVICE_MEDIA_PAUSE, STATE_PLAYING, STATE_PAUSED, ATTR_ENTITY_ID) +from homeassistant.components.media_player import (SERVICE_PLAY_MEDIA) + _LOGGER = logging.getLogger(__name__) @@ -61,6 +63,10 @@ def reproduce_state(hass, states, blocking=False): service = SERVICE_MEDIA_PAUSE elif state.domain == 'media_player' and state.state == STATE_PLAYING: service = SERVICE_MEDIA_PLAY + elif state.domain == 'media_player' and state.attributes and \ + 'media_type' in state.attributes and \ + 'media_id' in state.attributes: + service = SERVICE_PLAY_MEDIA elif state.state == STATE_ON: service = SERVICE_TURN_ON elif state.state == STATE_OFF: diff --git a/tests/components/test_media_player.py b/tests/components/test_media_player.py index 28d39206c47..211626ea3fb 100644 --- a/tests/components/test_media_player.py +++ b/tests/components/test_media_player.py @@ -40,7 +40,7 @@ class TestMediaPlayer(unittest.TestCase): def test_services(self): """ - Test if the call service methods conver to correct service calls. + Test if the call service methods convert to correct service calls. """ services = { SERVICE_TURN_ON: media_player.turn_on,