Upgrade samsungctl to 0.6.0 (#5126)
This commit is contained in:
parent
2970196f61
commit
c14a5fa7c1
2 changed files with 17 additions and 7 deletions
|
@ -17,7 +17,7 @@ from homeassistant.const import (
|
|||
CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN, CONF_PORT)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['samsungctl==0.5.1']
|
||||
REQUIREMENTS = ['samsungctl==0.6.0']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -81,8 +81,10 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||
|
||||
def __init__(self, host, port, name, timeout):
|
||||
"""Initialize the Samsung device."""
|
||||
from samsungctl import exceptions
|
||||
from samsungctl import Remote
|
||||
# Save a reference to the imported class
|
||||
# Save a reference to the imported classes
|
||||
self._exceptions_class = exceptions
|
||||
self._remote_class = Remote
|
||||
self._name = name
|
||||
# Assume that the TV is not muted
|
||||
|
@ -101,6 +103,11 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||
'timeout': timeout,
|
||||
}
|
||||
|
||||
if self._config['port'] == 8001:
|
||||
self._config['method'] = 'websocket'
|
||||
else:
|
||||
self._config['method'] = 'legacy'
|
||||
|
||||
def update(self):
|
||||
"""Retrieve the latest data."""
|
||||
# Send an empty key to see if we are still connected
|
||||
|
@ -119,14 +126,14 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||
try:
|
||||
self.get_remote().control(key)
|
||||
self._state = STATE_ON
|
||||
except (self._remote_class.UnhandledResponse,
|
||||
self._remote_class.AccessDenied, BrokenPipeError):
|
||||
except (self._exceptions_class.UnhandledResponse,
|
||||
self._exceptions_class.AccessDenied, BrokenPipeError):
|
||||
# We got a response so it's on.
|
||||
# BrokenPipe can occur when the commands is sent to fast
|
||||
self._state = STATE_ON
|
||||
self._remote = None
|
||||
return False
|
||||
except (self._remote_class.ConnectionClosed, OSError):
|
||||
except (self._exceptions_class.ConnectionClosed, OSError):
|
||||
self._state = STATE_OFF
|
||||
self._remote = None
|
||||
return False
|
||||
|
@ -155,7 +162,10 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||
|
||||
def turn_off(self):
|
||||
"""Turn off media player."""
|
||||
self.send_key('KEY_POWEROFF')
|
||||
if self._config['method'] == 'websocket':
|
||||
self.send_key('KEY_POWER')
|
||||
else:
|
||||
self.send_key('KEY_POWEROFF')
|
||||
# Force closing of remote session to provide instant UI feedback
|
||||
self.get_remote().close()
|
||||
|
||||
|
|
|
@ -525,7 +525,7 @@ radiotherm==1.2
|
|||
rxv==0.4.0
|
||||
|
||||
# homeassistant.components.media_player.samsungtv
|
||||
samsungctl==0.5.1
|
||||
samsungctl==0.6.0
|
||||
|
||||
# homeassistant.components.sensor.deutsche_bahn
|
||||
schiene==0.18
|
||||
|
|
Loading…
Add table
Reference in a new issue