Merge pull request #1397 from croneter/py3-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:09:38 +01:00 committed by GitHub
commit 35824fe4d0
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:" msgid "Current plex.tv status:"
msgstr "" msgstr ""
# PKC Settings - Connection
msgctxt "#39072"
msgid "Background sync connection:"
msgstr ""
# PKC Settings, category name # PKC Settings, category name
msgctxt "#39073" msgctxt "#39073"
msgid "Appearance Tweaks" msgid "Appearance Tweaks"
@ -1124,6 +1129,26 @@ msgctxt "#39085"
msgid "Reload Kodi node files to apply all the settings below" msgid "Reload Kodi node files to apply all the settings below"
msgstr "" 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" msgctxt "#39200"
msgid "Log-out Plex Home User " msgid "Log-out Plex Home User "
msgstr "" msgstr ""

View file

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

View file

@ -1,12 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings> <settings>
<category label="30014"><!-- Connection --> <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="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="ipaddress" label="39069" type="text" default="" enable="false" /><!-- Current address: -->
<setting id="port" label="39070" type="text" default="" enable="false" /><!-- Current port: --> <setting id="port" label="39070" type="text" default="" enable="false" /><!-- Current port: -->
<setting id="plex_serverowned" label="30031" type="bool" default="true" /><!-- I own this PMS --> <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="https" label="30243" type="bool" default="false" />
<setting id="sslcert" subsetting="true" label="30501" type="file" default="None" visible="eq(-1,true)" /> <setting id="sslcert" subsetting="true" label="30501" type="file" default="None" visible="eq(-1,true)" />
<setting id="sslverify" label="30500" type="bool" default="false" visible="String.StartsWith(System.BuildVersion,17.)" /><!-- Verify SSL Certificate (more secure) - Only visible for Kodi 17 Krypton eq(-1,true) + --> <setting id="sslverify" label="30500" type="bool" default="false" visible="String.StartsWith(System.BuildVersion,17.)" /><!-- Verify SSL Certificate (more secure) - Only visible for Kodi 17 Krypton eq(-1,true) + -->
@ -36,6 +39,7 @@
<setting type="sep" text=""/> <setting type="sep" text=""/>
<setting type="lsep" label="39700" /> <setting type="lsep" label="39700" />
<setting id="enable_alexa" label="39701" type="bool" default="true"/> <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 --> <!-- 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_restricteduser" type="bool" default="false" visible="false"/>
<setting id="plex_allows_mediaDeletion" type="bool" default="true" visible="false"/> <setting id="plex_allows_mediaDeletion" type="bool" default="true" visible="false"/>