I try to implement StateReporting with the HomeGraphService api for my google action.
For this I followed the google state-report documentation.
The issue is that the reportStateAndNotification function seems to do nothing. It just returns an empty list of com.google.api.services.homegraph.v1.HomeGraphService$Devices$ReportStateAndNotification. Also the state does not change in the HomeGraphViewer.
When I use the access token from credentials.accessToken with curl everything works fine. Any help would be much appreciated.
val stream = Base64.getDecoder().decode(homeGraphServiceKey)
val credentials = GoogleCredentials.fromStream(stream.inputStream())
.createScoped("https://www.googleapis.com/auth/homegraph")
credentials.refreshIfExpired()
val token = credentials.accessToken
val service = HomeGraphService.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
GsonFactory.getDefaultInstance(),
HttpCredentialsAdapter(credentials)
)
.setApplicationName("ff")
.build()
val states = mutableMapOf<String, MutableMap<String, Any>>()
val state = mutableMapOf<String, Any>()
state["on"] = true
states["hue:cE1"] = state
val request =
ReportStateAndNotificationRequest().setRequestId(
kotlin.random.Random.nextLong().toString()
)
.setAgentUserId("7b1d52e3-e68f-46cd-a8b9-6ce1fdfe5b62").setPayload(
StateAndNotificationPayload().setDevices(
ReportStateAndNotificationDevice().setStates(
states.toMap()
)
)
)
val response = service?.devices()?.reportStateAndNotification(request)
curl:
{
"requestId": "123ABC",
"agentUserId": "7b1d52e3-e68f-46cd-a8b9-6ce1fdfe5b62",
"payload": {
"devices": {
"states": {
"hue:cE1": {
"on": true
}
}
}
}
}
curl -X POST -H "Authorization: Bearer token” -H "Content-Type: application/json" -d @request "https://homegraph.googleapis.com/v1/devices:reportStateAndNotification"