Kullanıcılar bir cihazın mevcut durumunu sorgulamak için Google Assistant ile etkileşim kurduğunda sipariş karşılama, cihaz kimliklerinin listesini (SYNC
yanıtınızın belirttiği şekilde) içeren bir action.devices.QUERY
amacı alır.
Kullanıcılar, cihazınızı kontrol etmek için Assistant komutuna girdiğinde sipariş karşılama action.devices.EXECUTE
niyeti alır.
QUERY
amacı işleme
QUERY
yanıtınız, istenen cihazlar tarafından desteklenen her özellik için tam bir durum kümesi içerir.
{ "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "inputs": [{ "intent": "action.devices.QUERY", "payload": { "devices": [{ "id": "123", "customData": { "fooValue": 74, "barValue": true, "bazValue": "foo" } }, { "id": "456", "customData": { "fooValue": 12, "barValue": false, "bazValue": "bar" } }] } }] }
JSON
{ "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "payload": { "devices": { "123": { "on": true, "online": true }, "456": { "on": true, "online": true, "brightness": 80, "color": { "name": "cerulean", "spectrumRGB": 31655 } } } } }
Node.js
const {smarthome} = require('actions-on-google'); const app = smarthome(); // ... app.onQuery((body, headers) => { // TODO Get device state return { requestId: body.requestId, payload: { devices: { 123: { on: true, online: true }, 456: { on: true, online: true, brightness: 80, color: { name: "cerulean", spectrumRGB: 31655 } } } } }; });
Java
@NotNull @Override public QueryResponse onQuery(@NotNull QueryRequest queryRequest, @Nullable Map<?, ?> map) { QueryResponse.Payload payload = new QueryResponse.Payload(); payload.setDevices( new HashMap<String, Map<String, Object>>() { { put( "123", new HashMap<String, Object>() { { put("on", true); put("online", true); } }); put( "456", new HashMap<String, Object>() { { put("on", true); put("online", true); put("brightness", 80); put( "color", new HashMap<String, Object>() { { put("name", "cerulean"); put("spectrumRGB", 31655); } }); } }); } }); return new QueryResponse(queryRequest.getRequestId(), payload); }
Daha fazla bilgi için QUERY
intent referansı dokümanlarına bakın.
EXECUTE
amacı işleme
QUERY
'a benzer şekilde, tek bir amaç birden fazla cihaz kimliğini hedefleyebilir. Tek bir EXECUTE
amacı, bir cihaz grubuna verilen birden fazla farklı komutu da içerebilir. Örneğin, tetiklenen bir amaç bir grup ışıkta hem parlaklığı hem rengi ayarlayabilir veya her biri farklı bir renge sahip olabilir. EXECUTE
yanıtınız, yürütmeden sonra cihazın yeni durumunu döndürmelidir.
Kullanıcının cihazının durumu değiştiğinde
Report State kullanın. Örneğin, EXECUTE
işlemi veya yerel durum değişikliği nedeniyle (bir ışık anahtarını manuel olarak çevirme gibi).
Bu işlem, Google Home Graph hizmetinin bulut hizmetinizle senkronize olmasını sağlar.
{ "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "inputs": [{ "intent": "action.devices.EXECUTE", "payload": { "commands": [{ "devices": [{ "id": "123", "customData": { "fooValue": 74, "barValue": true, "bazValue": "sheepdip" } }, { "id": "456", "customData": { "fooValue": 36, "barValue": false, "bazValue": "moarsheep" } }], "execution": [{ "command": "action.devices.commands.OnOff", "params": { "on": true } }] }] } }] }
JSON
{ "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "payload": { "commands": [ { "ids": [ "123" ], "status": "SUCCESS", "states": { "on": true, "online": true } }, { "ids": [ "456" ], "status": "ERROR", "errorCode": "deviceTurnedOff" } ] } }
Node.js
const {smarthome} = require('actions-on-google'); const app = smarthome(); // ... app.onExecute((body, headers) => { // TODO Send command to device return { requestId: body.requestId, payload: { commands: [{ ids: ["123"], status: "SUCCESS", states: { on: true, online: true } }, { ids: ["456"], status: "ERROR", errorCode: "deviceTurnedOff" }] } }; });
Java
@NotNull @Override public ExecuteResponse onExecute( @NotNull ExecuteRequest executeRequest, @Nullable Map<?, ?> map) { ExecuteResponse.Payload payload = new ExecuteResponse.Payload(); payload.setCommands( new Commands[] { new Commands( new String[] {"123"}, "SUCCESS", new HashMap<String, Object>() { { put("on", true); put("online", true); } }, null, null), new Commands(new String[] {"456"}, "ERROR", null, "deviceTurnedOff", null) }); return new ExecuteResponse(executeRequest.getRequestId(), payload); }
Daha fazla bilgi için EXECUTE
niyeti başvuru dokümanlarına bakın.
Durum yanıtları
QUERY
ve EXECUTE
yanıtlarınız, isteğin sonucunu bildirmek için bir status
alanı içerir. Her durum yanıtı aşağıdaki değerlerden birini sağlayabilir:
SUCCESS
: İstek başarılı oldu.OFFLINE
: Hedef cihaz internete bağlı değil veya bu cihaza erişilemiyor.EXCEPTIONS
: İstekle ilgili bir sorun veya uyarı var.ERROR
: İstek, karşılık gelenerrorCode
ile başarısız oldu.
ERROR
ve EXCEPTIONS
ile ilgili daha fazla bilgi için Hataları ve istisnaları işleme ve Hatalar ve istisnalar bölümüne bakın.