i8beef / HomeAutio.Mqtt.GoogleHome

MIT License
215 stars 29 forks source link

ReportState as a requirement going forward #42

Closed i8beef closed 4 years ago

i8beef commented 5 years ago

Google has changed their requirements for SmartHome implementations, and ReportState is now a REQUIREMENT instead of optional. In addition, reportState for the entire device list MUST be sent AFTER a successful SYNC. Their recommendation seems to be to return a SYNC request, and then "wait up to a minute" to send a full ReportState... implying you cannot send it out of order with the Google Home SYNC response.

This needs to be implemented carefully, and possibly with retry logic (Polly?). Consider splitting off GoogleHomeGraphAPI processing to its own background service at this point to handle asynchronously from the main execution pipelines. Might also have to handle batching (i.e., don't send a ReportState when a FULL ReportState is already underway, locks around ReportState for a single device so you don't send out of order ReportStates for a single device?

diabl0w commented 5 years ago

Will this currently cause commands to not work at all?

i8beef commented 5 years ago

It shouldn't. The command pipelines all are separate. Google essentially has two APIs here, one you are expected to implement to accept commands and queries from them, and one you are expected to call to do things like report state. When they send a command, the app just sends that command out over MQTT. Whenever you get a new MQTT state topic back, if the device is marked "willReportState" it'll call Google's HomeGraph API to report that new state.

Where it gets stupid is that Google is sort of putting it on implementers to keep the Google systems synced. When Google calls us with a SYNC to get device information (not state) it has to sync that data over to its HomeGraph API. If you call a reportState before that happens, it fails. You also have no idea WHEN that will happen, and their recommendation is just "wait a minute". Which seems silly when they are (a) already making a call to you to get the device information, and (b) have a QUERY intent they could ALSO call at that time to get states so that they'd sync their own servers at the exact time that its possible for them to do so.

I and some others are attempting to get them to see the error of their ways, and so this is on hold until we get an official response from them.

In the mean time, reportState does work fine for state topics today. You just might see some warnings if you have a device that is willReportState=true, but haven't done a SYNC yet to get Google to know about it, so it starts throwing state updates at Google before it knows about the device. A "Google, sync my devices" should fix that right up though.

i8beef commented 4 years ago

Closing as ReportState has been implemented across all locations. Google still maintains the willReportState flags so I will continue to make it optional here as well.