Skip to content

Commit

Permalink
State is set to UNKNOWN rather than ON in order to make UI have an pl…
Browse files Browse the repository at this point in the history
…ay/pause button (home-assistant#17357)
  • Loading branch information
kennedyshead authored and balloob committed Oct 15, 2018
1 parent ac79ff9 commit 1cbb5b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
9 changes: 4 additions & 5 deletions homeassistant/components/media_player/samsungtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP,
MediaPlayerDevice)
from homeassistant.const import (
CONF_HOST, CONF_MAC, CONF_NAME, CONF_PORT, CONF_TIMEOUT, STATE_OFF,
STATE_ON, STATE_UNKNOWN)
CONF_HOST, CONF_MAC, CONF_NAME, CONF_PORT, CONF_TIMEOUT, STATE_OFF)
import homeassistant.helpers.config_validation as cv
from homeassistant.util import dt as dt_util

Expand Down Expand Up @@ -100,7 +99,7 @@ def __init__(self, host, port, name, timeout, mac):
self._muted = False
# Assume that the TV is in Play mode
self._playing = True
self._state = STATE_UNKNOWN
self._state = None
self._remote = None
# Mark the end of a shutdown command (need to wait 15 seconds before
# sending the next command to avoid turning the TV back ON).
Expand Down Expand Up @@ -149,11 +148,11 @@ def send_key(self, key):
BrokenPipeError):
# BrokenPipe can occur when the commands is sent to fast
self._remote = None
self._state = STATE_ON
self._state = None
except (self._exceptions_class.UnhandledResponse,
self._exceptions_class.AccessDenied):
# We got a response so it's on.
self._state = STATE_ON
self._state = None
self._remote = None
_LOGGER.debug("Failed sending command %s", key, exc_info=True)
return
Expand Down
18 changes: 9 additions & 9 deletions tests/components/media_player/test_samsungtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
MEDIA_TYPE_CHANNEL, MEDIA_TYPE_URL
from homeassistant.components.media_player.samsungtv import setup_platform, \
CONF_TIMEOUT, SamsungTVDevice, SUPPORT_SAMSUNGTV
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, STATE_ON, \
CONF_MAC, STATE_OFF
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, CONF_MAC, \
STATE_OFF
from tests.common import MockDependency
from homeassistant.util import dt as dt_util
from datetime import timedelta
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_setup_none(self, samsung_mock, wol_mock, mocked_warn):
def test_update_on(self):
"""Testing update tv on."""
self.device.update()
self.assertEqual(STATE_ON, self.device._state)
self.assertEqual(None, self.device._state)

def test_update_off(self):
"""Testing update tv off."""
Expand All @@ -116,7 +116,7 @@ def test_update_off(self):
def test_send_key(self):
"""Test for send key."""
self.device.send_key('KEY_POWER')
self.assertEqual(STATE_ON, self.device._state)
self.assertEqual(None, self.device._state)

def test_send_key_broken_pipe(self):
"""Testing broken pipe Exception."""
Expand All @@ -126,7 +126,7 @@ def test_send_key_broken_pipe(self):
self.device.get_remote = mock.Mock(return_value=_remote)
self.device.send_key('HELLO')
self.assertIsNone(self.device._remote)
self.assertEqual(STATE_ON, self.device._state)
self.assertEqual(None, self.device._state)

def test_send_key_connection_closed_retry_succeed(self):
"""Test retry on connection closed."""
Expand All @@ -137,7 +137,7 @@ def test_send_key_connection_closed_retry_succeed(self):
self.device.get_remote = mock.Mock(return_value=_remote)
command = 'HELLO'
self.device.send_key(command)
self.assertEqual(STATE_ON, self.device._state)
self.assertEqual(None, self.device._state)
# verify that _remote.control() get called twice because of retry logic
expected = [mock.call(command),
mock.call(command)]
Expand All @@ -152,7 +152,7 @@ def test_send_key_unhandled_response(self):
self.device.get_remote = mock.Mock(return_value=_remote)
self.device.send_key('HELLO')
self.assertIsNone(self.device._remote)
self.assertEqual(STATE_ON, self.device._state)
self.assertEqual(None, self.device._state)

def test_send_key_os_error(self):
"""Testing broken pipe Exception."""
Expand All @@ -177,8 +177,8 @@ def test_name(self):

def test_state(self):
"""Test for state property."""
self.device._state = STATE_ON
self.assertEqual(STATE_ON, self.device.state)
self.device._state = None
self.assertEqual(None, self.device.state)
self.device._state = STATE_OFF
self.assertEqual(STATE_OFF, self.device.state)

Expand Down

0 comments on commit 1cbb5b8

Please sign in to comment.