जब उपयोगकर्ता किसी डिवाइस की मौजूदा स्थिति के बारे में क्वेरी करने के लिए, Google Assistant से इंटरैक्ट करते हैं, तो आपके ऑर्डर को
action.devices.QUERY
इंटेंट मिल जाता है. इस इंटेंट में, डिवाइस आईडी की सूची (जैसा कि SYNC
के जवाब में दिया गया है) शामिल होती है.
जब उपयोगकर्ता आपके डिवाइस को कंट्रोल करने के लिए, Assistant को निर्देश भेजते हैं, तो उन्हें ग्राहक को आइटम भेजने के लिए
action.devices.EXECUTE
इंटेंट मिलता है.
QUERY
इंटेंट मैनेज करें
इस QUERY
जवाब में, अनुरोध किए गए डिवाइसों के साथ काम करने वाले हर एक फ़ीचर के लिए, राज्यों का पूरा सेट शामिल होता है.
{ "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 } } } } }; });
जावा
@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); }
ज़्यादा जानकारी के लिए, QUERY
इंटेंट
दस्तावेज़ देखें.
EXECUTE
इंटेंट मैनेज करें
QUERY
की तरह, एक इंटेंट ही कई डिवाइस आईडी को टारगेट कर सकता है. एक
EXECUTE
इंटेंट में, डिवाइसों के ग्रुप को दिए गए कई अलग-अलग निर्देश भी शामिल हो सकते हैं. उदाहरण के लिए, ट्रिगर किए गए इंटेंट की मदद से लाइटों के ग्रुप पर चमक और रंग, दोनों सेट किए जा सकते हैं. इसके अलावा, एक से ज़्यादा लाइटों को अलग-अलग रंग में सेट किया जा सकता है. EXECUTE
जांच के बाद, आपके डिवाइस की स्थिति नए जैसी हो जाएगी.
उपयोगकर्ता के डिवाइस की स्थिति में बदलाव होने पर Report State
का इस्तेमाल करें. उदाहरण के लिए, EXECUTE
इंटेंट या स्थानीय स्थिति में बदलाव की वजह से (जैसे, लाइट स्विच को मैन्युअल तरीके से बदलना).
इससे Google Home Graph, क्लाउड सेवा के साथ सिंक रहता है.
{ "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" }] } }; });
जावा
@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); }
ज़्यादा जानकारी के लिए, EXECUTE
इंटेंट से जुड़े दस्तावेज़ देखें.
स्थिति के बारे में जवाब
अनुरोध की समीक्षा करने के लिए, QUERY
और EXECUTE
जवाब में status
फ़ील्ड शामिल होता है. स्थिति से जुड़े हर जवाब से नीचे दी गई कोई एक वैल्यू मिल सकती है:
SUCCESS
अनुरोध पूरा हो गया.OFFLINE
टारगेट डिवाइस ऑफ़लाइन है या फिर पहुंच से बाहर है.EXCEPTIONS
अनुरोध से जुड़ी कोई समस्या या चेतावनी है.ERROR
errorCode
से जुड़े अनुरोध को पूरा नहीं किया जा सका.
ERROR
और EXCEPTIONS
के लिए, गड़बड़ियों और अपवादों को मैनेज करें और ज़्यादा जानकारी के लिए
गड़बड़ियां और अपवाद देखें.