mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fixed roku exception when device is powered off or looses connection (#2173)
This commit is contained in:
parent
4b0df51b40
commit
e886303f08
@ -66,6 +66,9 @@ class RokuDevice(MediaPlayerDevice):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
|
import requests.exceptions
|
||||||
|
|
||||||
|
try:
|
||||||
self.roku_name = "roku_" + self.roku.device_info.sernum
|
self.roku_name = "roku_" + self.roku.device_info.sernum
|
||||||
self.ip_address = self.roku.host
|
self.ip_address = self.roku.host
|
||||||
self.channels = self.get_source_list()
|
self.channels = self.get_source_list()
|
||||||
@ -74,6 +77,8 @@ class RokuDevice(MediaPlayerDevice):
|
|||||||
self.current_app = self.roku.current_app
|
self.current_app = self.roku.current_app
|
||||||
else:
|
else:
|
||||||
self.current_app = None
|
self.current_app = None
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
self.current_app = None
|
||||||
|
|
||||||
def get_source_list(self):
|
def get_source_list(self):
|
||||||
"""Get the list of applications to be used as sources."""
|
"""Get the list of applications to be used as sources."""
|
||||||
@ -92,6 +97,9 @@ class RokuDevice(MediaPlayerDevice):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
|
if self.current_app is None:
|
||||||
|
return STATE_UNKNOWN
|
||||||
|
|
||||||
if self.current_app.name in ["Power Saver", "Default screensaver"]:
|
if self.current_app.name in ["Power Saver", "Default screensaver"]:
|
||||||
return STATE_IDLE
|
return STATE_IDLE
|
||||||
elif self.current_app.name == "Roku":
|
elif self.current_app.name == "Roku":
|
||||||
@ -137,16 +145,19 @@ class RokuDevice(MediaPlayerDevice):
|
|||||||
@property
|
@property
|
||||||
def app_name(self):
|
def app_name(self):
|
||||||
"""Name of the current running app."""
|
"""Name of the current running app."""
|
||||||
|
if self.current_app is not None:
|
||||||
return self.current_app.name
|
return self.current_app.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def app_id(self):
|
def app_id(self):
|
||||||
"""Return the ID of the current running app."""
|
"""Return the ID of the current running app."""
|
||||||
|
if self.current_app is not None:
|
||||||
return self.current_app.id
|
return self.current_app.id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source(self):
|
def source(self):
|
||||||
"""Return the current input source."""
|
"""Return the current input source."""
|
||||||
|
if self.current_app is not None:
|
||||||
return self.current_app.name
|
return self.current_app.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -156,30 +167,37 @@ class RokuDevice(MediaPlayerDevice):
|
|||||||
|
|
||||||
def media_play_pause(self):
|
def media_play_pause(self):
|
||||||
"""Send play/pause command."""
|
"""Send play/pause command."""
|
||||||
|
if self.current_app is not None:
|
||||||
self.roku.play()
|
self.roku.play()
|
||||||
|
|
||||||
def media_previous_track(self):
|
def media_previous_track(self):
|
||||||
"""Send previous track command."""
|
"""Send previous track command."""
|
||||||
|
if self.current_app is not None:
|
||||||
self.roku.reverse()
|
self.roku.reverse()
|
||||||
|
|
||||||
def media_next_track(self):
|
def media_next_track(self):
|
||||||
"""Send next track command."""
|
"""Send next track command."""
|
||||||
|
if self.current_app is not None:
|
||||||
self.roku.forward()
|
self.roku.forward()
|
||||||
|
|
||||||
def mute_volume(self, mute):
|
def mute_volume(self, mute):
|
||||||
"""Mute the volume."""
|
"""Mute the volume."""
|
||||||
|
if self.current_app is not None:
|
||||||
self.roku.volume_mute()
|
self.roku.volume_mute()
|
||||||
|
|
||||||
def volume_up(self):
|
def volume_up(self):
|
||||||
"""Volume up media player."""
|
"""Volume up media player."""
|
||||||
|
if self.current_app is not None:
|
||||||
self.roku.volume_up()
|
self.roku.volume_up()
|
||||||
|
|
||||||
def volume_down(self):
|
def volume_down(self):
|
||||||
"""Volume down media player."""
|
"""Volume down media player."""
|
||||||
|
if self.current_app is not None:
|
||||||
self.roku.volume_down()
|
self.roku.volume_down()
|
||||||
|
|
||||||
def select_source(self, source):
|
def select_source(self, source):
|
||||||
"""Select input source."""
|
"""Select input source."""
|
||||||
|
if self.current_app is not None:
|
||||||
if source == "Home":
|
if source == "Home":
|
||||||
self.roku.home()
|
self.roku.home()
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user