Skip to content

Commit

Permalink
0.1.3
Browse files Browse the repository at this point in the history
Use timestamp and create MinutesSinceLastArrival/Departure
Fix Manual Menu /refreshData now includes GeoFences
  • Loading branch information
ghawken committed Jan 18, 2018
1 parent a33f99a commit 5f95d4c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion iFindFriendsMini.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>0.1.2</string>
<string>0.1.3</string>
<key>ServerApiVersion</key>
<string>1.0</string>
<key>IwsApiVersion</key>
Expand Down
25 changes: 24 additions & 1 deletion iFindFriendsMini.indigoPlugin/Contents/Server Plugin/Devices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,39 @@
<TriggerLabel>Devices near?</TriggerLabel>
<ControlPageLabel>Number of devices Within GeoFence</ControlPageLabel>
</State>
<State id="lastArrivaltime" readonly="YES">
<State id="lastArrivaltimestamp" readonly="YES">
<ValueType>Number</ValueType>
<TriggerLabel>Timestamp of last arrival</TriggerLabel>
<ControlPageLabel>Timestamp of last arrival</ControlPageLabel>
</State>

<State id="lastDeptimestamp" readonly="YES">
<ValueType>Number</ValueType>
<TriggerLabel>Timestamp of last Departure</TriggerLabel>
<ControlPageLabel>Timestamp of last Departure</ControlPageLabel>
</State>
<State id="lastArrivaltime" readonly="YES">
<ValueType>String</ValueType>
<TriggerLabel>Last date/time of arrival</TriggerLabel>
<ControlPageLabel>Last date/time of arrival</ControlPageLabel>
</State>

<State id="lastDeptime" readonly="YES">
<ValueType>String</ValueType>
<TriggerLabel>Last date/time of Departure</TriggerLabel>
<ControlPageLabel>Last date/time of Departure</ControlPageLabel>
</State>
<State id="minutessincelastArrival" readonly="YES">
<ValueType>Number</ValueType>
<TriggerLabel>Minutes since last arrival</TriggerLabel>
<ControlPageLabel>Minutes since last arrival</ControlPageLabel>
</State>
<State id="minutessincelastDep" readonly="YES">
<ValueType>Number</ValueType>
<TriggerLabel>Minutes since last Departure</TriggerLabel>
<ControlPageLabel>Minutes since last Departure</ControlPageLabel>
</State>

<State id="deviceIsOnline">
<ValueType>Boolean</ValueType>
<TriggerLabel>Device online?</TriggerLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<MenuItem id="titleSeparator1" type="separator" />
<MenuItem id="refreshData">
<Name>Refresh Data Now</Name>
<CallbackMethod>refreshData</CallbackMethod>
<CallbackMethod>actionrefreshdata</CallbackMethod>
</MenuItem>
<MenuItem id="titleSeparator2" type="separator" />
<MenuItem id="toggleDebug">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<Label>Date/Time format of lastUpdate field. In format strftime. See. strftime.org for more options
eg %c == Mon Jan 15 16:50:59 2018
eg. %b %d %Y %H:%M:%S == Feb 18 2009 00:03:38
eg. %a %d %b %-I:%M %p == Mon 15 Jan 4:57 PM
eg. %a %d %b %I:%M %p == Mon 15 Jan 4:57 PM
</Label>
</Field>

Expand Down
29 changes: 28 additions & 1 deletion iFindFriendsMini.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ def deviceStartComm(self, dev):
{'key': 'friendsInRange', 'value': 0},
{'key': 'lastArrivaltime', 'value': ''},
{'key': 'lastDeptime', 'value': ''},
{'key': 'lastArrivaltimestamp', 'value': ''},
{'key': 'lastDeptimestamp', 'value': ''},
{'key': 'minutessincelastArrival', 'value': 0},
{'key': 'minutessincelastDep', 'value': 0},
{'key': 'deviceIsOnline', 'value': 'Waiting'}]
if self.debugLevel >= 2:
self.debugLog(unicode(stateList))
Expand Down Expand Up @@ -265,6 +269,12 @@ def deviceStopComm(self, dev):

# =============================================================

def actionrefreshdata(self):
self.refreshData()
self.sleep(5)
self.checkGeofence()
return

def runConcurrentThread(self):
""" docstring placeholder """

Expand Down Expand Up @@ -554,15 +564,32 @@ def checkGeofence(self):
#More friends in range before, someone must have left
# Update leave time
geoDevices.updateStateOnServer('lastDeptime', value=update_time)
geoDevices.updateStateOnServer('lastDeptimestamp', value=t.time())
elif igeoFriendsRangeOld < igeoFriendsRange:
#Less People previously, someone must have arrived
# update arrival time
geoDevices.updateStateOnServer('lastArrivaltime', value=update_time)
geoDevices.updateStateOnServer('lastArrivaltimestamp', value=t.time())
# Change Sensor Icon
if igeoFriendsRange==0:
geoDevices.updateStateImageOnServer(indigo.kStateImageSel.SensorOff)
if igeoFriendsRange >0:
geoDevices.updateStateImageOnServer(indigo.kStateImageSel.SensorOn)
lastArrivaltimestamp = float(geoDevices.states['lastArrivaltimestamp'])

try:
lastDeptimestamp = float(geoDevices.states['lastDeptimestamp'])
if lastArrivaltimestamp > 0:
#indigo.server.log(unicode(lastArrivaltimestamp))
timesincearrival = int(t.time()-float(lastArrivaltimestamp))/60 #time in seconds /60
#indigo.server.log(unicode(timesincearrival))
geoDevices.updateStateOnServer('minutessincelastArrival', value=timesincearrival)
if lastDeptimestamp >0:
timesincedep = int(t.time()-float(lastDeptimestamp))/60
geoDevices.updateStateOnServer('minutessincelastDep', value=timesincedep)
except Exception as e:
indigo.server.log(u'Error with Departure/Arrival Time Calculation:'+unicode(e))
pass

except Exception as e:
indigo.server.log(u'Error within Check GeoFences: '+unicode(e))
Expand Down Expand Up @@ -756,7 +783,7 @@ def toggleDebugEnabled(self):
self.debug = False
self.debugLevel = 1
self.pluginPrefs['showDebugInfo'] = False
indigo.server.log(u"Debugging off.")
indigo.server.log(u"Debugging off. Debug level: {0}".format(self.debugLevel))

def myFriendDevices(self, filter=0, valuesDict=None, typeId="", targetId=0):

Expand Down

0 comments on commit 5f95d4c

Please sign in to comment.