From 89aa2cc21a97f26e25b43c3fb0760671625f2eb7 Mon Sep 17 00:00:00 2001 From: DaveL17 Date: Tue, 1 Oct 2019 20:08:17 -0500 Subject: [PATCH] Adds user-configurable setting for device auto-disable feature. --- .../Contents/Server Plugin/Devices.xml | 4 ++++ .../Contents/Server Plugin/plugin.py | 12 +++++++++++- _changelog.txt | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/GhostXML.indigoPlugin/Contents/Server Plugin/Devices.xml b/GhostXML.indigoPlugin/Contents/Server Plugin/Devices.xml index c822843..99fa1c7 100644 --- a/GhostXML.indigoPlugin/Contents/Server Plugin/Devices.xml +++ b/GhostXML.indigoPlugin/Contents/Server Plugin/Devices.xml @@ -44,6 +44,10 @@ + + + + diff --git a/GhostXML.indigoPlugin/Contents/Server Plugin/plugin.py b/GhostXML.indigoPlugin/Contents/Server Plugin/plugin.py index f1dce2d..174982a 100644 --- a/GhostXML.indigoPlugin/Contents/Server Plugin/plugin.py +++ b/GhostXML.indigoPlugin/Contents/Server Plugin/plugin.py @@ -16,6 +16,8 @@ # TODO: when a user retrieves an XML payload but has selected JSON, do they get an error to the log? # TODO: does the plugin work properly with URLs that include parameters? (https://foo.com/bar/1234?user=***&pwd=***) +# TODO: Move bad connection messages to the plugin private log and change the Indigo log message to be "Unable to connect - will keep trying" or something like that. + # ================================Stock Imports================================ # import datetime import xml.etree.ElementTree as Etree @@ -275,7 +277,8 @@ def runConcurrentThread(self): dev = self.managedDevices[devId].device # If a device has failed 10 times, disable it and notify the user. - if self.managedDevices[devId].bad_calls >= 10: + retries = int(dev.pluginProps.get('maxRetries', 10)) + if self.managedDevices[devId].bad_calls >= retries: indigo.device.enable(devId, value=False) self.logger.critical(u"[{0}] Disabling {1} because it has failed 10 times.".format(dev.id, dev.name)) @@ -334,6 +337,13 @@ def validateDeviceConfigUi(self, valuesDict, typeID, devId): use_digest = valuesDict['useDigest'] var_list = [var.id for var in indigo.variables] + try: + _ = int(valuesDict['maxRetries']) + except ValueError: + error_msg_dict['maxRetries'] = u"You must enter an integer." + error_msg_dict['showAlertText'] = u"Max Retries Error.\n\nThe value must be an integer." + return False, valuesDict, error_msg_dict + # Test the source URL/Path for proper prefix. if not url.startswith(url_list): error_msg_dict['sourceXML'] = u"You must supply a valid URL/Path." diff --git a/_changelog.txt b/_changelog.txt index 82cf546..aaad275 100644 --- a/_changelog.txt +++ b/_changelog.txt @@ -1,7 +1,7 @@ GhostXML Change Log v0.4.31 -- +- Adds user-configurable setting for device auto-disable feature. v0.4.30 - Adds sendDevicePing() trap. @@ -16,7 +16,7 @@ v0.4.27 - Standardizes SupportURL behavior across all plugin functions. v0.4.26 -- Ensures plugins is compatible with the Indigo server version. +- Ensures plugin is compatible with the Indigo server version. v0.4.25 - Fixes plugin configuration validation bug.