When fulfilling SYNC requests, QUERY requests and ReportState calls, I'm reporting all devices as "online": true
. I can see this value being correctly read by Google, in that the values appear set on the ReportState Dashboard test tool. Android works fine, showing the device online ("Linked to you") after a brief query ("Connecting..."). Converesly, when using the iOS mobile client, as the user goes into the page for a device, it queries only to then report the device as being offline. Both the dashboard and JSON responses to calls all show "online": true
. If the user tries interacting with the device, for example turning it on, it works.
{
"requestId": "ARequestId",
"payload": {
"devices": [{
"id": "ADeviceId",
"online": true,
"status": "SUCCESS"
}]
}
}
This could be a bug in the iOS client, but it seems much more likely it's a bug in my code or misunderstanding on my part as this is my first Smart Home Action.
I've tried including "online": true
all over the place, e.g. in SYNC, QUERY and ReportState calls. This has at least given the dashboard awareness of the initial online state, but not helped the iOS client.
In general, ReportState seems to work fine, in that my changes are reflected in the dashboard.
Note the contradiction between the test tool's state and the iOS client's indication.
I came back to this issue after around a year away from this project. It turns out that this is actually due to misreading the response structure of the QUERY Intent. The SYNC Intent expects an array of objects with "id" fields. The QUERY Intent expects a dictionary keyed by the id.
Bizarrely, even though this is back-end to back-end, and no error is thrown by the Google side, an Android client seems to handle this fine, but the iOS client doesn't.
Essentially, yes there is a bug there somewhere with iOS in as much as it ought to behave the same as Android, and similarly there ought to be a 400 error for the bad request format, but the error was essentially in my response structure.
A Correct SYNC Intent Response
[
{
"id": "DeviceId1",
"online": true,
"status": "SUCCESS"
},
{
"id": "DeviceId2",
"online": true,
"status": "SUCCESS"
}
]
My Erroneous QUERY Intent Response (Same as correct SYNC)
[
{
"id": "DeviceId1",
"online": true,
"status": "SUCCESS"
},
{
"id": "DeviceId2",
"online": true,
"status": "SUCCESS"
}
]
A Correct QUERY Intent Response (a keyed dictionary, rather than an array)
{
"DeviceId1" :
{
"online": true,
"status": "SUCCESS"
},
"DeviceId2" :
{
"online": true,
"status": "SUCCESS"
}
}
So even though the emergent behaviour was different in iOS and Android, it was me all along. It was a very easy to miss slip. Hope this helps someone, as the lack of errors coming back meant this one was infuriating.