对应Google Action设备类型

## 对应Google Action设备类型 #### 电器开关 对于多路电器开关,必须把每个开关对应成一个设备 同步到Google Action,比如一个两路开关,一路控制电灯,一路控制电视,那么将同步两个设备到google action,一个是电灯设备,一个是电视设备,这两个设备都具有OnOff特性。 #### 场景 [Google Action 场景虚拟设备](https://developers.google.com/assistant/smarthome/traits/scene) 状态属性: online, 场景的online状态,即代表该场景的active和deactive。 COMMAND: action.devices.commands.ActivateScene 场景也有房间归属 ``` 'use strict'; const {smarthome} = require('actions-on-google'); const functions = require('firebase-functions'); const app = smarthome(); app.onSync((body, headers) => { return { requestId: body.requestId, payload: { agentUserId: '1836.15267389', devices: [{ id: '123', type: 'action.devices.types.SCENE', traits: [ 'action.devices.traits.Scene' ], name: { defaultNames: [], name: 'Party Mode', nicknames: [] }, willReportState: true, // should be false, as there's no state attributes: { sceneReversible: true }, // Note -- probably no device info for virtual devices. customData: { fooValue: 74, barValue: true, bazValue: 'lambtwirl' } }] } }; }); // ... exports.smarthome = functions.https.onRequest(app); ``` #### 温湿度传感器设备 [Google Action 传感器设备](https://developers.google.com/assistant/smarthome/guides/sensor#response-nodejs) ``` action.devices.types.SENSOR { "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "payload": { "agentUserId": "1836.15267389", "devices": [ { "id": "123", "type": "action.devices.types.SENSOR", "traits": [ "action.devices.traits.HumiditySetting", "action.devices.traits.OnOff", "action.devices.traits.SensorState", "action.devices.traits.TemperatureControl" ], "name": { "defaultNames": [ "Sirius Cybernetics Corporation Sensor" ], "name": "Sensor", "nicknames": [ "Master Control Sensor" ] }, "willReportState": true, "attributes": { "sensorStatesSupported": [ { "name": "AirQuality", "descriptiveCapabilities": { "availableStates": [ "healthy", "moderate", "unhealthy", "very unhealthy" ] } } ], "queryOnlyHumiditySetting": true, "queryOnlyTemperatureControl": true, "temperatureUnitForUX": "C" }, "deviceInfo": { "manufacturer": "Sirius Cybernetics Corporation", "model": "442", "hwVersion": "3.2", "swVersion": "11.4" } } ] } } ``` #### 烟雾检测器 [Google Action烟雾检测器设备类型](https://developers.google.com/assistant/smarthome/guides/smokedetector) 同步设备接口实现例子: ``` 'use strict'; const {smarthome} = require('actions-on-google'); const functions = require('firebase-functions'); const app = smarthome(); app.onSync((body, headers) => { return { requestId: body.requestId, payload: { agentUserId: '123456789', devices: [{ id: '123', type: 'action.devices.types.SMOKE_DETECTOR', traits: [ 'action.devices.traits.SensorState' ], name: { defaultNames: ['Smoke Detector'], name: 'SmokeLevel', nicknames: ['Kitchen Smoke Detector'] }, willReportState: true, attributes: { sensorStatesSupported: [{ name: 'SmokeLevel', descriptiveCapabilities: { availableStates: [ 'smoke detected', 'high', 'no smoke detected' ] }, numericCapabilities: { rawValueUnit: 'PARTS_PER_MILLION' } }] }, deviceInfo: { manufacturer: 'Sirius Cybernetics Corporation', model: '442', hwVersion: '3.2', swVersion: '11.4' } }] } }; }); // ... exports.smarthome = functions.https.onRequest(app); ``` #### command 格式 body: { devices: [device_id, device_id, ...], execution: [{ command: 'action.devices.commands.ArmDisarm/...', challenge: {pin: '123455'}, params: {根据不同command,而不同} }] }