Merge pull request #1398 from croneter/add-websocket-info

Add information to PKC settings for background sync and Alexa whether a connection has been successfully made
This commit is contained in:
croneter 2021-03-14 14:36:02 +01:00 committed by GitHub
commit 95758b5dc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 3 deletions

View file

@ -1063,6 +1063,11 @@ msgctxt "#39071"
msgid "Current plex.tv status:"
msgstr ""
# PKC Settings - Connection
msgctxt "#39072"
msgid "Background sync connection:"
msgstr ""
# PKC Settings, category name
msgctxt "#39073"
msgid "Appearance Tweaks"
@ -1124,6 +1129,26 @@ msgctxt "#39085"
msgid "Reload Kodi node files to apply all the settings below"
msgstr ""
# PKC Settings - Connection - Background sync connection status
msgctxt "#39089"
msgid "Alexa connection status:"
msgstr ""
# PKC Settings - Connection - Background sync connection status
msgctxt "#39090"
msgid "Suspended - not connected"
msgstr ""
# PKC Settings - Connection - Background sync connection status
msgctxt "#39091"
msgid "Timeout - not connected"
msgstr ""
# PKC Settings - Connection - Background sync connection status
msgctxt "#39092"
msgid "IOError - not connected"
msgstr ""
msgctxt "#39200"
msgid "Log-out Plex Home User "
msgstr ""

View file

@ -15,6 +15,7 @@ LOG = getLogger('PLEX.websocket_client')
class WebSocket(backgroundthread.KillableThread):
opcode_data = (websocket.ABNF.OPCODE_TEXT, websocket.ABNF.OPCODE_BINARY)
status_setting = None
def __init__(self):
self.ws = None
@ -77,6 +78,8 @@ class WebSocket(backgroundthread.KillableThread):
if self.should_suspend():
# Set in service.py
self.close_websocket()
# Status = 'Suspended - not connected'
utils.settings(self.status_setting, value=utils.lang(39090))
if self.wait_while_suspended():
# Abort was requested while waiting. We should exit
return
@ -100,10 +103,16 @@ class WebSocket(backgroundthread.KillableThread):
# Server is probably offline
LOG.debug("%s: IOError connecting", self.__class__.__name__)
self.ws = None
# Status = IOError - not connected
utils.settings(self.status_setting,
value=utils.lang(39092))
self._sleep_cycle()
except websocket.WebSocketTimeoutException:
LOG.debug("%s: WebSocketTimeoutException", self.__class__.__name__)
self.ws = None
# Status = 'Timeout - not connected'
utils.settings(self.status_setting,
value=utils.lang(39091))
self._sleep_cycle()
except websocket.WebsocketRedirect as e:
LOG.debug('301 redirect detected: %s', e)
@ -116,6 +125,9 @@ class WebSocket(backgroundthread.KillableThread):
except websocket.WebSocketException as e:
LOG.debug('%s: WebSocketException: %s', self.__class__.__name__, e)
self.ws = None
# Status = Error
utils.settings(self.status_setting,
value=utils.lang(257))
self._sleep_cycle()
except Exception as e:
LOG.error('%s: Unknown exception encountered when '
@ -124,9 +136,15 @@ class WebSocket(backgroundthread.KillableThread):
LOG.error("%s: Traceback:\n%s",
self.__class__.__name__, traceback.format_exc())
self.ws = None
# Status = Error
utils.settings(self.status_setting,
value=utils.lang(257))
self._sleep_cycle()
else:
self.sleeptime = 0.0
# Status = Connected
utils.settings(self.status_setting,
value=utils.lang(13296))
except Exception as e:
LOG.error("%s: Unknown exception encountered: %s",
self.__class__.__name__, e)
@ -134,12 +152,16 @@ class WebSocket(backgroundthread.KillableThread):
LOG.error("%s: Traceback:\n%s",
self.__class__.__name__, traceback.format_exc())
self.close_websocket()
# Status = Error
utils.settings(self.status_setting, value=utils.lang(257))
class PMS_Websocket(WebSocket):
"""
Websocket connection with the PMS for Plex Companion
"""
status_setting = 'pms_websocket_status'
def should_suspend(self):
"""
Returns True if the thread is suspended.
@ -208,6 +230,8 @@ class Alexa_Websocket(WebSocket):
"""
Websocket connection to talk to Amazon Alexa.
"""
status_setting = 'alexa_websocket_status'
def should_suspend(self):
"""
Overwrite method since we need to check for plex token

View file

@ -1,11 +1,14 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
<category label="30014"><!-- Connection -->
<setting label="[COLOR yellow]$ADDON[plugin.video.plexkodiconnect 39050][/COLOR]" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=chooseServer)" option="close" /><!-- Choose Plex Server from a list -->
<setting label="[COLOR yellow]$ADDON[plugin.video.plexkodiconnect 39068][/COLOR]" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=enterPMS)" option="close" /><!-- Manually enter Plex Media Server IP -->
<setting id="plex_servername" label="39067" type="text" default="" enable="false" /><!-- Your current PMS server: -->
<setting id="ipaddress" label="39069" type="text" default="" enable="false" /><!-- Current address: -->
<setting id="port" label="39070" type="text" default="" enable="false" /><!-- Current port: -->
<setting id="pms_websocket_status" label="39072" type="text" default="" enable="false" /><!-- Background sync connection: -->
<setting type="sep" text=""/>
<setting label="[COLOR yellow]$ADDON[plugin.video.plexkodiconnect 39050][/COLOR]" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=chooseServer)" option="close" /><!-- Choose Plex Server from a list -->
<setting label="[COLOR yellow]$ADDON[plugin.video.plexkodiconnect 39068][/COLOR]" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=enterPMS)" option="close" /><!-- Manually enter Plex Media Server IP -->
<setting type="sep" text=""/>
<setting id="plex_serverowned" label="30031" type="bool" default="true" /><!-- I own this PMS -->
<setting id="https" label="30243" type="bool" default="false" />
<setting id="sslcert" subsetting="true" label="30501" type="file" default="None" visible="eq(-1,true)" />
@ -36,6 +39,7 @@
<setting type="sep" text=""/>
<setting type="lsep" label="39700" />
<setting id="enable_alexa" label="39701" type="bool" default="true"/>
<setting id="alexa_websocket_status" label="39089" type="text" default="" enable="false" /><!-- Alexa connection status: -->
<!-- Different settings that are not visible - to avoid warnings in the log -->
<setting id="plex_restricteduser" type="bool" default="false" visible="false"/>
<setting id="plex_allows_mediaDeletion" type="bool" default="true" visible="false"/>