Update google_assistant JavaScript to support local query. Remove onP… (#21491)

This commit is contained in:
Marcus 2022-02-14 23:22:48 -08:00 committed by GitHub
parent e7c74db9d3
commit 2ac836aa26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 20 deletions

View File

@ -113,12 +113,16 @@ If you want to support active reporting of state to Google's server (configurati
2. Click `Develop` on the top of the page, then click `Actions` located in the hamburger menu on the top left.
3. Upload [this Javascript file](/assets/integrations/google_assistant/app.js) for both Node and Chrome by clicking the `Upload Javascript files` button.
4. Add device scan configuration:
1. Click `+ New scan config`
2. Select `MDNS`
3. set mDNS service name to `_home-assistant._tcp.local`
5. `Save` your changes.
6. Either wait for 30 minutes, or restart your connected Google device.
7. Restart Home Assistant Core.
1. Click `+ New scan config`
2. Select `MDNS`
3. Set mDNS service name to `_home-assistant._tcp.local`
4. Click `Add field`, then under `Select a field` select `name`
5. Enter a new `value` field set to `.*\._home-assistant\._tcp\.local`
5. Check the box `Support local query` under `Add capabilities`.
6. `Save` your changes.
7. Either wait for 30 minutes, or restart your connected Google device.
8. Restart Home Assistant Core.
9. With a Google Assistant device, try saying "OK Google, sync my devices." This can be helpful to avoid issues, especially if you are enabling local fulfillment sometime after adding cloud Google Assistant support.
You can debug the setup by following [these instructions](https://developers.google.com/assistant/smarthome/develop/local#debugging_from_chrome)

View File

@ -128,7 +128,7 @@ const reachableDevicesHandler = async (request) => {
console.log("REACHABLE_DEVICES intent:", request);
const hassCustomData = findHassCustomDeviceDataByDeviceId(request.requestId, request.devices, request.inputs[0].payload.device.id);
try {
return forwardRequest(hassCustomData,
return forwardRequest(hassCustomData,
// Old code would sent it to the proxy ID: hassCustomData.proxyDeviceId
// But tutorial claims otherwise, but maybe it is not for hub devices??
// https://developers.google.com/assistant/smarthome/develop/local#implement_the_execute_handler
@ -155,19 +155,25 @@ const executeHandler = async (request) => {
throw err;
}
};
const app = new App("1.0.0");
const queryHandler = async (request) => {
console.log("QUERY intent:", request);
const device = request.inputs[0].payload.devices[0];
try {
return await forwardRequest(device.customData, device.id, request);
} catch (err) {
if (err instanceof UnknownInstance) {
err.throwHandlerError();
}
throw err;
}
};
const app = new App("1.1.0");
app
.onIdentify(identifyHandler)
.onReachableDevices(reachableDevicesHandler)
.onExecute(executeHandler)
// Undocumented in TypeScript
// Suggested by Googler, seems to work :shrug:
// https://github.com/actions-on-google/smart-home-local/issues/1#issuecomment-515706997
// @ts-ignore
.onProxySelected((req) => {
console.log("ProxySelected", req);
return createResponse(req, {});
})
.onQuery(queryHandler)
// @ts-ignore
.onIndicate((req) => console.log("Indicate", req))
// @ts-ignore
@ -175,8 +181,6 @@ app
// @ts-ignore
.onProvision((req) => console.log("Provision", req))
// @ts-ignore
.onQuery((req) => console.log("Query", req))
// @ts-ignore
.onRegister((req) => console.log("Register", req))
// @ts-ignore
.onUnprovision((req) => console.log("Unprovision", req))
@ -184,6 +188,6 @@ app
.onUpdate((req) => console.log("Update", req))
.listen()
.then(() => {
console.log("Ready!");
})
console.log("Ready!");
})
.catch((e) => console.error(e));