From 1674c8309a6c9463015ca942476892e0933d6c00 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Thu, 24 Sep 2015 00:06:05 -0400 Subject: [PATCH] Support playing, pausing states for media players when reproducing state This allows the state helper to call the correct service call for media_players when attempting to resolve state. --- homeassistant/helpers/state.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/homeassistant/helpers/state.py b/homeassistant/helpers/state.py index d4a18806a17..b1ea902ae61 100644 --- a/homeassistant/helpers/state.py +++ b/homeassistant/helpers/state.py @@ -9,7 +9,8 @@ import logging from homeassistant.core import State import homeassistant.util.dt as dt_util from homeassistant.const import ( - STATE_ON, STATE_OFF, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID) + STATE_ON, STATE_OFF, SERVICE_TURN_ON, SERVICE_TURN_OFF, + STATE_PLAYING, STATE_PAUSED, ATTR_ENTITY_ID) _LOGGER = logging.getLogger(__name__) @@ -55,14 +56,19 @@ def reproduce_state(hass, states, blocking=False): state.entity_id) continue - if state.state == STATE_ON: - service = SERVICE_TURN_ON - elif state.state == STATE_OFF: - service = SERVICE_TURN_OFF - else: - _LOGGER.warning("reproduce_state: Unable to reproduce state %s", - state) - continue + if state.domain == 'media_player' and state == STATE_PAUSED: + service = 'media_pause' + elif state.domain == 'media_player' and state == STATE_PLAYING: + service = 'media_play' + elif + if state.state == STATE_ON: + service = SERVICE_TURN_ON + elif state.state == STATE_OFF: + service = SERVICE_TURN_OFF + else: + _LOGGER.warning("reproduce_state: Unable to reproduce state %s", + state) + continue service_data = dict(state.attributes) service_data[ATTR_ENTITY_ID] = state.entity_id