Reduce the number of instantiations for Addon()
This commit is contained in:
parent
16f3605dff
commit
71f4fa0f76
1 changed files with 16 additions and 11 deletions
|
@ -198,14 +198,19 @@ class PlexWebSocketApp(websocket.WebSocketApp,
|
||||||
log.exception('Exception of type %s occured: %s', type(err), err)
|
log.exception('Exception of type %s occured: %s', type(err), err)
|
||||||
finally:
|
finally:
|
||||||
self.close()
|
self.close()
|
||||||
|
if self._enabled:
|
||||||
# Status = Not connected
|
# Status = Not connected
|
||||||
|
message = utils.lang(15208)
|
||||||
|
else:
|
||||||
|
# Status = Disabled
|
||||||
|
message = utils.lang(24023)
|
||||||
utils.settings(self.name + SETTINGS_STRING,
|
utils.settings(self.name + SETTINGS_STRING,
|
||||||
value=utils.lang(15208))
|
value=message)
|
||||||
app.APP.deregister_thread(self)
|
app.APP.deregister_thread(self)
|
||||||
log.info("----===## %s stopped ##===----", self.name)
|
log.info("----===## %s stopped ##===----", self.name)
|
||||||
|
|
||||||
def _run(self):
|
def _run(self):
|
||||||
while not self.should_cancel():
|
while not self.should_cancel() and self._enabled:
|
||||||
# In the event the server goes offline
|
# In the event the server goes offline
|
||||||
while self.should_suspend():
|
while self.should_suspend():
|
||||||
# We will be caught in this loop if either another thread
|
# We will be caught in this loop if either another thread
|
||||||
|
@ -231,16 +236,13 @@ class PlexWebSocketApp(websocket.WebSocketApp,
|
||||||
class PMSWebsocketApp(PlexWebSocketApp):
|
class PMSWebsocketApp(PlexWebSocketApp):
|
||||||
name = 'pms_websocket'
|
name = 'pms_websocket'
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self._enabled = utils.settings('enableBackgroundSync') == 'true'
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def get_uri(self):
|
def get_uri(self):
|
||||||
return get_pms_uri()
|
return get_pms_uri()
|
||||||
|
|
||||||
def should_suspend(self):
|
|
||||||
"""
|
|
||||||
Returns True if the thread needs to suspend.
|
|
||||||
"""
|
|
||||||
return (self._suspended or
|
|
||||||
utils.settings('enableBackgroundSync') != 'true')
|
|
||||||
|
|
||||||
def set_suspension_settings_status(self):
|
def set_suspension_settings_status(self):
|
||||||
if utils.settings('enableBackgroundSync') != 'true':
|
if utils.settings('enableBackgroundSync') != 'true':
|
||||||
# Status = Disabled
|
# Status = Disabled
|
||||||
|
@ -255,6 +257,10 @@ class PMSWebsocketApp(PlexWebSocketApp):
|
||||||
class AlexaWebsocketApp(PlexWebSocketApp):
|
class AlexaWebsocketApp(PlexWebSocketApp):
|
||||||
name = 'alexa_websocket'
|
name = 'alexa_websocket'
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self._enabled = utils.settings('enable_alexa') == 'true'
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def get_uri(self):
|
def get_uri(self):
|
||||||
return get_alexa_uri()
|
return get_alexa_uri()
|
||||||
|
|
||||||
|
@ -263,7 +269,6 @@ class AlexaWebsocketApp(PlexWebSocketApp):
|
||||||
Returns True if the thread needs to suspend.
|
Returns True if the thread needs to suspend.
|
||||||
"""
|
"""
|
||||||
return self._suspended or \
|
return self._suspended or \
|
||||||
utils.settings('enable_alexa') != 'true' or \
|
|
||||||
app.ACCOUNT.restricted_user or \
|
app.ACCOUNT.restricted_user or \
|
||||||
not app.ACCOUNT.plex_token
|
not app.ACCOUNT.plex_token
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue