Skip to content

Commit

Permalink
Adds user-configurable setting for device auto-disable feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveL17 committed Oct 2, 2019
1 parent a0b8ece commit 89aa2cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions GhostXML.indigoPlugin/Contents/Server Plugin/Devices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<Label>Timeout:</Label>
</Field>

<Field id="maxRetries" type="textfield" defaultValue="10" tooltip="Enter the maximum number of retries before the plugin automatically disables the device (integer).">
<Label>Max Retries:</Label>
</Field>

<!-- URL -->

<Field id="sourceXML" type="textfield" tooltip="Enter the path to your data source using the examples below as a guide. If you use substitutions, be sure to include the proper variable index in the form of [A], [B], etc.">
Expand Down
12 changes: 11 additions & 1 deletion GhostXML.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions _changelog.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 89aa2cc

Please sign in to comment.