State is set to UNKNOWN rather than ON in order to make UI have an play/pause button (#17357)

This commit is contained in:
kennedyshead 2018-10-15 11:42:27 +02:00 committed by Paulus Schoutsen
parent ac79ff9e24
commit 1cbb5b8e51
2 changed files with 13 additions and 14 deletions

View File

@ -17,8 +17,7 @@ from homeassistant.components.media_player import (
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
@ -100,7 +99,7 @@ class SamsungTVDevice(MediaPlayerDevice):
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).
@ -149,11 +148,11 @@ class SamsungTVDevice(MediaPlayerDevice):
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

View File

@ -12,8 +12,8 @@ from homeassistant.components.media_player import SUPPORT_TURN_ON, \
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
@ -102,7 +102,7 @@ class TestSamsungTv(unittest.TestCase):
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."""
@ -116,7 +116,7 @@ class TestSamsungTv(unittest.TestCase):
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."""
@ -126,7 +126,7 @@ class TestSamsungTv(unittest.TestCase):
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."""
@ -137,7 +137,7 @@ class TestSamsungTv(unittest.TestCase):
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)]
@ -152,7 +152,7 @@ class TestSamsungTv(unittest.TestCase):
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."""
@ -177,8 +177,8 @@ class TestSamsungTv(unittest.TestCase):
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)