Eight Sleep Mattress - Port from ST

Morning...

I got the driver and the app ported over, but albeit not successfully yet.

When I enter my username and pw this is the log that appears and I cannot proceed further.

Any idea?

I used your code (but I took out all the tile stuff in the DTH) and everything loaded! I get the same error. It looks like the initial connect to the website works (e.g. Status: 200). My wild guess would be the token isn’t populating correctly.

Great! Now we need to simply wait for someone to come and rescue us!

It looks like it’s only returning from the closure on line 536 and continuing to the end of the apiPost method. I tested this by adding a debug message at the end of the method:

def apiPOST(path, body = [:]) {
	try {
		log.debug("Beginning API POST: ${path}, ${body}")
		httpPost(uri: apiURL(path), body: new groovy.json.JsonBuilder(body).toString(), headers: apiRequestHeaders() ) {response ->
			logResponse(response)
            return response
		}
	} catch (groovyx.net.http.HttpResponseException e) {
		logResponse(e.response)
		return e.response
	}
    log.debug "apiPost returning outside response"
}

At that point it’s returning null. I’m not a groovy expert so I’m not sure how it worked in ST, but a possibility is to modify it to return the value at the end of the method:

def apiPOST(path, body = [:]) {
    def returnData
	try {
		log.debug("Beginning API POST: ${path}, ${body}")
	    httpPost(uri: apiURL(path), body: new groovy.json.JsonBuilder(body).toString(), headers: apiRequestHeaders() ) {response ->
			logResponse(response)
			returnData = response
		}
	} catch (groovyx.net.http.HttpResponseException e) {
		logResponse(e.response)
		return e.response
	}
    return returnData
}

Using this modification apiPost returned the response object correctly on line 462. I don’t have an Eight Sleep account so I’m not able to test further. Possibly someone else might have more information on returning from closures and what the difference is with ST’s implementation.

Getting Closer.... I am now authenticated. I get to this screen.

When I select from Choose your Eight Sleep Devices, I get:

That’s good progress! There are two other methods that have the same approach of returning inside the response closure: apiGET on line 501, apiPUT on line 544. Maybe try changing these as well and see if these are causing that error.

Amended as you suggested but with the same results :frowning:

def apiGET(path) {
    	try {   			
            httpGet(uri: apiURL(path), headers: apiRequestHeaders()) {response ->
    			logResponse(response)
    			returnData = response
    		}
    	} catch (groovyx.net.http.HttpResponseException e) {
    		logResponse(e.response)
    		return e.response
    	}
        return returnData
    }


def apiPUT(path, body = [:]) {
	try {
		log.debug("Beginning API POST: ${path}, ${body}")
		httpPut(uri: apiURL(path), body: new groovy.json.JsonBuilder(body).toString(), headers: apiRequestHeaders() ) {response ->
			logResponse(response)
			returnData =  response
		}
	} catch (groovyx.net.http.HttpResponseException e) {
		logResponse(e.response)
		return e.response
	}
    returnData
}

… and found apiPOST @ line 531 that exhibited the same symptoms

def apiPOST(path, body = [:]) {
   def returnData
       try {
               log.debug("Beginning API POST: ${path}, ${body}")
           httpPost(uri: apiURL(path), body: new groovy.json.JsonBuilder(body).toString(), headers: apiRequestHeaders() ) {response ->
                       logResponse(response)
                       returnData = response
               }
       } catch (groovyx.net.http.HttpResponseException e) {
               logResponse(e.response)
               return e.response
       }
   return returnData
}

Ah, it looks like both apiGET and apiPUT are missing the def returnData on the first line of the methods. If adding the variable definition doesn’t get you any further, posting the log might help find the next hold up.

Here are some log files.

Everything up to 16:32:14 is loading the app with the edited code and entering my credentials. When I select the "Choose your Eight Sleep devices:" I get the Error 500 with no log entries. When I selected the "Notifications:' I received the error at 16:32:48.

Thank you for helping with this!!

That last error is related to ST push notifications and contact book which isn’t available in Hubitat yet. You can try commenting the input statement out, but there are other places in the code where these are still referenced that need to be taken out. I’ll see if I can look at it more this weekend.

Okay. I’ll start working down that path as well. I don’t think there’s any need for notifications at this point. I’m more concerned about not being able to choose the device. I’m not very good at this, but it seems to me that it’s trying to find a device based on how ST would access it.

Thank you for any and all help!

Any updates?

BTW anyone is free to edit the GitHub

I forked your GitHub repo and removed all the references to ST push notifications/contact book. SMS notifications should still work with Hubitat. I didn't see any syntax errors but can't fully test it out. Let me know if you find any issues!

This is the error I receive when I try to login using the app.

[app:263](http://192.168.7.201/logs#app263)2018-03-11 09:57:48.337:errorCannot get property 'status' on null object on line 450

[app:263](http://192.168.7.201/logs#app263)2018-03-11 09:57:48.332:infoBody: [session:[expirationDate:2018-03-25T13:57:48.233Z, userId:2ddb0e487c814bd38ae64f95129d1774, token:30811fa2400242fc8d42abee1b11d8ce-be66b64778b149b465421da3c6fb52b4]]

[app:263](http://192.168.7.201/logs#app263)2018-03-11 09:57:48.331:infoStatus: 200

[app:263](http://192.168.7.201/logs#app263)2018-03-11 09:57:47.648:debugBeginning API POST: /login,

Whoops, I assumed you updated your github with the original API method changes. I only checked for syntax since I don’t have an eight sleep account to fully test. I committed those original changes now so it’s ready to test out again.

Same error message, I fully copied/pasted your github raw app code.

Any thoughts? PS - github says the app was updated 4 days ago.

2018-03-12 17:04:10.930:errorCannot get property 'status' on null object on line 450

[app:274](http://192.168.7.201/logs#app274)2018-03-12 17:04:10.924:infoBody: [session:[expirationDate:2018-03-26T21:04:10.820Z, userId:2ddb0e487c814bd38ae64f95129d1774, token:b37d904acdbb4f268884af1f87376f10-b4da931d393d85f764b83d16588b02ca]]

[app:274](http://192.168.7.201/logs#app274)2018-03-12 17:04:10.922:infoStatus: 200

[app:274](http://192.168.7.201/logs#app274)2018-03-12 17:04:10.195:debugBeginning API POST: /login,

@homeauto2112 Did you get your mattress working?

Anyone?

For some odd reason I cannot login because of the error at line ‘450’

We are so close!!

I’m not sure what happened to my github client, I remember making the changes but I can’t find the code saved anywhere. Pretty sure I’m not going crazy :grin: They were pretty simple changes so I fixed the closure issues on the few API methods and commited the change.