Hi @bptworld - I was looking at your Hubitat github repo.. I was going to fork it and make a few small changes to the life360 driver -- then submit a PR if you were interested. Anyway, I noticed everything is in .zip files.
How do you view changes to the source code this way? Do these bundle/package managers only accept .zip?
Anyway, I figured if I fork it then it'd be easier to see what changes I made.. mostly for myself so I can get any future updates too.
Here's what I was changing:
I know the driver polls every X (30) seconds and because of this every 30 seconds there's a bunch of updates made to the device, including the lastUpdated time, map, etc. But, what I'm really interested in is getting notified when actual changes occur -- either the device moved or the battery level changed.
I also wanted to add accuracy
to the driver - which can be used on a map to show a radius around the PIN.. it indicates the user could actually be anywhere inside that circle. accuracy
is passed from the device in Life360 - at least I saw it coming from both my kids devices (iOS and Android). The smaller the circle, the more accurate the location is.
Here's most of the changes I've been testing with on my hub.. it's working well so far. Obviously there might be some cases I'm not considering but I wanted to at least put it out there in case it benefits anyone else too.
if(logEnable) log.trace "In generatePresenceEvent..."
// JP: only interested in sending updates device when location or battery changes
// -- current values --
def latitude = member.location.latitude.toFloat() // current latitude
def longitude = member.location.longitude.toFloat() // current longitude
def accuracy = member.location.accuracy.toFloat() // current accuracy
def battery = Math.round(member.location.battery.toDouble()) // current battery level
// -- previous values (could be null) --
def prevLatitude = device.currentValue('latitude')
def prevLongitude = device.currentValue('longitude')
def prevAccuracy = device.currentValue('accuracy')
def prevBattery = device.currentValue('battery')
if (prevLatitude != null && prevLatitude.toFloat() == latitude && prevLongitude != null && prevLongitude.toFloat() == longitude
&& prevAccuracy != null && prevAccuracy.toFloat() == accuracy
&& prevBattery != null && Math.round(prevBattery.toDouble()) == battery) {
if(logEnable) log.trace "No change: lat:$latitude, long:$longitude, accuracy:$accuracy, battery:$battery"
return
}
log.debug "changed: lat:$latitude (was:$prevLatitude), long:$longitude (was:$prevLongitude), accuracy:$accuracy (was:$prevAccuracy), battery:$battery (was:$prevBattery)"
EDITED to handle null values better