Set unavailable when unreachable (#19012)

* Turn GPMDP Off When Unavailable

* Update requirements_all.txt

* Specified Exception Type

* Update gpmdp.py
This commit is contained in:
MaxG88 2018-12-14 07:14:32 -05:00 committed by Paulus Schoutsen
parent b97f0c0261
commit f95bd9c78f
2 changed files with 28 additions and 18 deletions

View File

@ -20,7 +20,7 @@ from homeassistant.const import (
import homeassistant.helpers.config_validation as cv
from homeassistant.util.json import load_json, save_json
REQUIREMENTS = ['websocket-client==0.37.0']
REQUIREMENTS = ['websocket-client==0.54.0']
_CONFIGURING = {}
_LOGGER = logging.getLogger(__name__)
@ -155,6 +155,7 @@ class GPMDP(MediaPlayerDevice):
self._duration = None
self._volume = None
self._request_id = 0
self._available = True
def get_ws(self):
"""Check if the websocket is setup and connected."""
@ -200,6 +201,8 @@ class GPMDP(MediaPlayerDevice):
def update(self):
"""Get the latest details from the player."""
time.sleep(1)
try:
self._available = True
playstate = self.send_gpmdp_msg('playback', 'getPlaybackState')
if playstate is None:
return
@ -216,6 +219,13 @@ class GPMDP(MediaPlayerDevice):
volume_data = self.send_gpmdp_msg('volume', 'getVolume')
if volume_data is not None:
self._volume = volume_data['value'] / 100
except OSError:
self._available = False
@property
def available(self):
"""Return if media player is available."""
return self._available
@property
def media_content_type(self):

View File

@ -1627,7 +1627,7 @@ watchdog==0.8.3
waterfurnace==1.0.0
# homeassistant.components.media_player.gpmdp
websocket-client==0.37.0
websocket-client==0.54.0
# homeassistant.components.media_player.webostv
websockets==6.0