Husqvarna automower api httpget parsing broken in 2.5.1.x

c8 pro..upgraded to 2.5.1.242 broken husqvarna automower integration.. not sure if it is a change in http response or oauth but even with re-authorizing in the interface and getting info/new token the application fails to get a list of children.. not sure how to further debug what changed.

restoring older back to 2.5.0.159 it works fine.

@gopher.ny

here it is working after reversion

Just noticed the same issue.

Hope someone can fix it soon.

Tagging @gopher.ny

@bobbyD

more info i tried the upgrade again with added debugging and there were no differnces in the url called.. it is an http get with a header with token and a null query..

i tried with the query removed thinking that was it.. same issue..

then i tried though maybe its not even calling the query if the query is null..

so i added garbage to the end of the token and i did get an unauthorized error so it is calling the end point..

i am out of ideas

here is the working log image
and the same call not working after upgrading again (part of the token commented out for security reasons)

working on older firmware

not working after upgrading

more info please look into it but the httpget is broken.. when using json or text

it worked with those parameters with async mode but otherwise was broke.. i had to modify the code to get back the raw entity.. and then go on and parse it and then it worked fine..

ie

If resp.data is still returning null even with */*, it means Hubitat is silently failing to extract the raw text stream from the HTTP socket before it closes. [1]

When resp.data fails on a 200 OK, the reliable workaround in the Hubitat ecosystem is to consume the raw string buffer directly from the underlying network entity via resp.entity.content.

The Direct Network Buffer Extraction Fix

This approach completely bypasses Hubitat's data layer and extracts the response string directly from the HTTP data stream.

here is the changed code

and i will put the github link up in a few

if(myfrc || !skipIt) {
updTsVal("getAutoUpdDt")

Map deviceListParams=[
		uri: getMowerApiEndpoint() +"/mowers",
		headers: [
			"Authorization": "Bearer ${(String)state.authToken}",
			"Authorization-Provider": "husqvarna",
			"X-Api-Key":getHusqvarnaApiKey()
		],
		query: null,
		timeout: 30
	]


	if(debugLevel(4)){
		msg+="http params -- ${deviceListParams} "
	}
	msg +="HTTPGET "
	if(msg){
       if(debugLevel(4)) log.debug "url header = $msgH, msg = $msg"
		LOG(msgH + msg, 3, sTRACE)
		msg=sBLANK
	}

	Boolean exitout
	exitout=false
	try {
		httpGet(deviceListParams){ resp ->
			LOG(msgH + "httpGet() ${resp.status} Response", 4, sTRACE)
			Map adata
          if(debugLevel(4))  log.debug "resp = $resp"
            
            if (resp.entity != null && resp.entity.content != null) {
          
			//if(resp){
                rdata = resp.entity.content.text
                // use raw method
                
				//rdata=resp.data.text // need to save first time since it is a ByteArrayInputStream
		   if (rdata) adata=(Map)new JsonSlurper().parseText(rdata)
			}
            
			if(resp && resp.status == 200 && adata){
               if(debugLevel(4)) log.debug "resp status = ${resp.status}"
               if(debugLevel(4)) log.debug "rdata = $rdata"
               if(debugLevel(4)) log.debug "adata = $adata"

				List<Map> ndata=((List<Map>)adata.data)?.findAll{ it.type == "mower" }

@gopher.ny

also just updated as noticed the following:

  • lgk modified 8/26 to fix the bug in hubitat with httpget parsing.
  • also noticed we are not handling any of the v2 api returns from the web socket interface..
  • added a bunch of code to handle all those include frequent lat, long and battery updates,
  • in addition the next start time was wrong in the web socket interface it needed to be multiplied by 1000 to get the correct start time.
  • upped the version number to reflect all theese changes.

*/

Noted, I'm on it.

@kahn-hubitat , the fix will revert the JSON detection behavior to its pre-2.5.1.142 state. You may want to add a fall back that handles both scenarios. Sorry about the trouble. This will go into beta first so we can confirm it doesn't break something else.

thanks let me know and i will test it..

however the hub i have this on is not in the beta program i will send you the id privately.. only my other c8 pro is in the beta.

version 12,
reversion fixed the parsing issue put up in git hub a new version with both the old and the new raw (global variable decides which to use)

also fixed long and latitude to use position: when avail. (from websocket) but not passed in the normal api still uses top one of positions (plural)..

that is why long and lat. were not getting updated

After updating to 2.5.1.143 my AutoMower is working as before again on my HE.

yes but if you want the long and lat. and battery level etc working better you need to get my version.. it was not updating those regularly from the websocket only the normal polling.