Skip to content

Commit

Permalink
Implement optional timestamp
Browse files Browse the repository at this point in the history
Each server device now has an option to set a timestamp state each time a setvar request is handled.
  • Loading branch information
FlyingDiver committed May 17, 2020
1 parent 61e5d29 commit 424117a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion HTTPd2.indigoPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>2.0.3</string>
<string>2.1.0</string>
<key>ServerApiVersion</key>
<string>2.0</string>
<key>IwsApiVersion</key>
Expand Down
3 changes: 3 additions & 0 deletions HTTPd2.indigoPlugin/Contents/Server Plugin/Devices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<Field id="digestRequired" type="checkbox" defaultValue="false">
<Label>Require Digest Authentication:</Label>
</Field>
<Field id="updateTimestamp" type="checkbox" defaultValue="false">
<Label>Update a timestamp state:</Label>
</Field>
<Field id="certfileName" type="textfield" defaultValue="">
<Label>Certificate File:</Label>
</Field>
Expand Down
10 changes: 7 additions & 3 deletions HTTPd2.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,19 @@ def do_setvar(self, request):
value = query[key][0]
state_list.append({'key': unicode(key), 'value': value})
new_states[key] = value

if device.pluginProps.get("updateTimestamp", False):
state_list.append({'key': u'http2_timestamp', 'value': time.strftime("%x %X")})

self.logger.threaddebug(u"{}: MyRequestHandler: new_states = {}".format(device.name, new_states))

if saved_states != new_states:
newProps = device.pluginProps
newProps["saved_states"] = json.dumps(new_states)
device.replacePluginPropsOnServer(newProps)
device.stateListOrDisplayStateIdChanged()

self.server.set_state_list(state_list)
device.stateListOrDisplayStateIdChanged()
device.updateStatesOnServer(state_list)

def do_webhook(self, request):
Expand Down Expand Up @@ -449,8 +453,8 @@ def didDeviceCommPropertyChange(self, oldDevice, newDevice):
for prop in newDevice.pluginProps:
if prop in ['saved_states']: # list of properties to ignore
pass
elif newDevice.pluginProps[prop] != oldDevice.pluginProps[prop]:
self.logger.threaddebug(u"{}: didDeviceCommPropertyChange prop {}: {}->{}".format(newDevice.name, prop, oldDevice.pluginProps[prop], newDevice.pluginProps[prop]))
elif newDevice.pluginProps.get(prop, None) != oldDevice.pluginProps.get(prop, None):
self.logger.threaddebug(u"{}: didDeviceCommPropertyChange prop {}: {}->{}".format(newDevice.name, prop, oldDevice.pluginProps.get(prop, None), newDevice.pluginProps.get(prop, None)))
return True
self.logger.threaddebug(u"{}: didDeviceCommPropertyChange no changes".format(newDevice.name))

Expand Down

0 comments on commit 424117a

Please sign in to comment.