So I have an API endpoint I had working on ST that I was trying to convert over; it is a virtual presence sensor that is triggered by GeoHopper who can post JSON to a webhook. I use it for multiple users and create virtual drivers for each user. Can anyone tell me why I have to do this on HE? I hope it's a bug.
curl -s -k -d '{"location":"Virtual AC Presence", "event":"LocationExit"}' http://192.168.1.16/apps/api/42/location/Brian?access_token=xxx-xxx-xxx-xxx
So I have a mapping for /location/:user that calls this function, which worked in ST:
private void update (devices) {
def data = request.JSON
def location = data.location
def event = data.event
def user = params.user
def deviceName = location + "-" + user
def device = devices.find { it.displayName == deviceName }
This doesn't work any longer and I now have to do this to get the same data. request
no longer has any data other than this: [requestSource:local, HOST:192.168.1.16]
, so I basically have to look in params
to find the posted data, then it's not formatted correctly so I have to dance all over it. Is this a bug, or am I doing something wrong?
def jsonSlurper = new JsonSlurper()
def plexJSON = params.findAll { key,value -> key =~ /location/ }
def firstKey = plexJSON.keySet().stream().findFirst().get();
def json = jsonSlurper.parseText(firstKey)
log.debug "json: ${json.location}"
log.debug "json event ${json.event}"
def location = json.location
def event = json.event
def user = params.user
def deviceName = location + "-" + user
def device = devices.find { it.displayName == deviceName }
Code is here if you're interested: hubitat/Geohopper-Presence at master · bdwilson/hubitat · GitHub