Fix Plex Companion failing leading to PMS connection loss

This commit is contained in:
Croneter 2018-05-30 08:20:30 +02:00
parent 06f9f6a7a5
commit 1f0977ec77

View file

@ -57,7 +57,6 @@ class WebSocket(Thread):
LOG.info("----===## Starting %s ##===----", self.__class__.__name__) LOG.info("----===## Starting %s ##===----", self.__class__.__name__)
counter = 0 counter = 0
handshake_counter = 0
stopped = self.stopped stopped = self.stopped
suspended = self.suspended suspended = self.suspended
while not stopped(): while not stopped():
@ -94,9 +93,10 @@ class WebSocket(Thread):
LOG.info("%s: Error connecting", self.__class__.__name__) LOG.info("%s: Error connecting", self.__class__.__name__)
self.ws = None self.ws = None
counter += 1 counter += 1
if counter > 3: if counter >= 10:
counter = 0 LOG.info('%s: Repeated IOError detected. Stopping now',
self.IOError_response() self.__class__.__name__)
break
sleep(1000) sleep(1000)
except websocket.WebSocketTimeoutException: except websocket.WebSocketTimeoutException:
LOG.info("%s: Timeout while connecting, trying again", LOG.info("%s: Timeout while connecting, trying again",
@ -106,10 +106,10 @@ class WebSocket(Thread):
except websocket.WebSocketException as e: except websocket.WebSocketException as e:
LOG.info('%s: WebSocketException: %s', LOG.info('%s: WebSocketException: %s',
self.__class__.__name__, e) self.__class__.__name__, e)
if ('Handshake Status 401' in e.args if ('Handshake Status 401' in e.args or
or 'Handshake Status 403' in e.args): 'Handshake Status 403' in e.args):
handshake_counter += 1 counter += 1
if handshake_counter >= 5: if counter >= 5:
LOG.info('%s: Error in handshake detected. ' LOG.info('%s: Error in handshake detected. '
'Stopping now', self.__class__.__name__) 'Stopping now', self.__class__.__name__)
break break
@ -125,7 +125,6 @@ class WebSocket(Thread):
sleep(1000) sleep(1000)
else: else:
counter = 0 counter = 0
handshake_counter = 0
except Exception as e: except Exception as e:
LOG.error("%s: Unknown exception encountered: %s", LOG.error("%s: Unknown exception encountered: %s",
self.__class__.__name__, e) self.__class__.__name__, e)
@ -202,11 +201,6 @@ class PMS_Websocket(WebSocket):
# Put PMS message on queue and let libsync take care of it # Put PMS message on queue and let libsync take care of it
state.WEBSOCKET_QUEUE.put(message) state.WEBSOCKET_QUEUE.put(message)
def IOError_response(self):
LOG.warn("Repeatedly could not connect to PMS, "
"declaring the connection dead")
window('plex_online', value='false')
class Alexa_Websocket(WebSocket): class Alexa_Websocket(WebSocket):
""" """
@ -252,9 +246,6 @@ class Alexa_Websocket(WebSocket):
return return
process_command(message.attrib['path'][1:], message.attrib) process_command(message.attrib['path'][1:], message.attrib)
def IOError_response(self):
pass
# Path in thread_methods # Path in thread_methods
def stop(self): def stop(self):
self.thread_stopped = True self.thread_stopped = True