mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Add timeout and fix oscillations on Samsung TV component (#17102)
* Add timeout and fix oscillations * Adjust code to py3.5.3 * Clean code
This commit is contained in:
parent
b92b24e8a4
commit
02bf07d9df
@ -125,10 +125,14 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||||||
def update(self):
|
def update(self):
|
||||||
"""Update state of device."""
|
"""Update state of device."""
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
_ping_cmd = ['ping', '-n 1', '-w', '1000', self._config['host']]
|
timeout_arg = '-w {}000'.format(self._config['timeout'])
|
||||||
|
_ping_cmd = [
|
||||||
|
'ping', '-n 3', timeout_arg, self._config['host']]
|
||||||
else:
|
else:
|
||||||
_ping_cmd = ['ping', '-n', '-q', '-c1', '-W1',
|
timeout_arg = '-W{}'.format(self._config['timeout'])
|
||||||
self._config['host']]
|
_ping_cmd = [
|
||||||
|
'ping', '-n', '-q',
|
||||||
|
'-c3', timeout_arg, self._config['host']]
|
||||||
|
|
||||||
ping = subprocess.Popen(
|
ping = subprocess.Popen(
|
||||||
_ping_cmd,
|
_ping_cmd,
|
||||||
|
@ -128,6 +128,23 @@ class TestSamsungTv(unittest.TestCase):
|
|||||||
self.device.update()
|
self.device.update()
|
||||||
self.assertEqual(STATE_OFF, self.device._state)
|
self.assertEqual(STATE_OFF, self.device._state)
|
||||||
|
|
||||||
|
@mock.patch(
|
||||||
|
'homeassistant.components.media_player.samsungtv.subprocess.Popen'
|
||||||
|
)
|
||||||
|
def test_timeout(self, mocked_popen):
|
||||||
|
"""Test timeout use."""
|
||||||
|
ping = mock.Mock()
|
||||||
|
mocked_popen.return_value = ping
|
||||||
|
ping.returncode = 0
|
||||||
|
self.device.update()
|
||||||
|
expected_timeout = self.device._config['timeout']
|
||||||
|
timeout_arg = '-W{}'.format(expected_timeout)
|
||||||
|
ping_command = [
|
||||||
|
'ping', '-n', '-q', '-c3', timeout_arg, 'fake']
|
||||||
|
expected_call = call(ping_command, stderr=-3, stdout=-1)
|
||||||
|
self.assertEqual(mocked_popen.call_args, expected_call)
|
||||||
|
self.assertEqual(STATE_ON, self.device._state)
|
||||||
|
|
||||||
def test_send_key(self):
|
def test_send_key(self):
|
||||||
"""Test for send key."""
|
"""Test for send key."""
|
||||||
self.device.send_key('KEY_POWER')
|
self.device.send_key('KEY_POWER')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user