From 6afb846d04f8d7a43d495d8415ed4f8dc8ba3bbe Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Wed, 7 Oct 2015 00:56:14 -0400 Subject: [PATCH] avoid key errors --- homeassistant/components/media_player/__init__.py | 4 ++-- homeassistant/helpers/state.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index fec4515756c..1b65ce57912 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -287,8 +287,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/helpers/state.py b/homeassistant/helpers/state.py index db33eda960d..bf3c5f05d7a 100644 --- a/homeassistant/helpers/state.py +++ b/homeassistant/helpers/state.py @@ -63,7 +63,8 @@ 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 state.attributes['media_type'] and state.attributes['media_id']: + 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