如何在Smart Home示例中创建持久性虚拟设备?

时间:2018-03-11 13:36:22

标签: actions-on-google

我刚下载并运行了the sample from here。它正在工作,但每当我连接到网站(https://something.ngrok.io/)或甚至刷新它需要花费很多时间而Node.js控制台显示它正在获得大量“/ bower_components”,甚至认为我有使用相同的帐户登录(“rick / oldman”),之前添加的设备已经消失。

我想添加一个持久的简单虚拟灯,所以我看到了datastore.js,文档丢失了,或者我找不到它。我唯一能找到的就是评论。

/**
 * Structure of Data
 * {
 *   <uid>: {
 *     <device id>: {
 *       properties: {
 *         <property name>: <property value>,
 *         <property name>: <property value>
 *       },
 *       states: {
 *         <state name>: <state value>,
 *         <state name>: <state value>
 *       }
 *     },
 *     <device id>: {...}
 *   },
 *   <uid>: {
 *     <device id>: {...},
 *     <device id>: {...},
 *     <device id>: {...}
 *   },
 *   ...
 * }
 */

没有样本,所以我从日志中推断出来(在网站上创建了一个设备),并创建了一个这样的设备,但是这个设备没有出现。

const config = require('./config-provider');
const Data = {
  "f9b2dc04-2518-11e8-b467-0ed5f89f718b":{
    "light1":{
      "states":{
        "on": false,
        "online":true
      },
      "properties":{  
        "type":"action.devices.types.LIGHT",
        "traits":["action.devices.traits.OnOff"],
        "attributes":{  
            "temperatureMinK":2000,
            "temperatureMaxK":6500
        },
        "name":{  
            "defaultNames":[  
              "Fake Light"
            ],
            "name":"Fake Light 1",
            "nicknames":[  
              "fake lamp"
            ]
        },
        "willReportState":false,
        "roomHint":"",
        "deviceInfo":{  
            "manufacturer":"Fake Home Provider",
            "model":"fake1234",
            "swVersion":"1.0.0",
            "hwVersion":"1.0"
        },
        "customData":{  
            "smartHomeProviderId":"thisisfakesuperfake"
        }
      }
    }
  }
};

我不确定数据是否正确;我找不到任何样品。如何拥有持久性虚拟设备并阻止重新下载bower组件,我需要做什么?

1 个答案:

答案 0 :(得分:0)

引入此行为是为了更轻松地测试不同的配置。行为发生在示例代码中here

app.post('/smart-home-api/reset-devices', function (request, response)

根据人们使用示例的方式,这种行为可能有点奇怪,所以我添加了一个新的配置选项:Config.enableReset

默认情况下,这是真的。但是,通过将其设置为false,它应该在页面刷新后保留设备。

至于Bower,它不应该每次都下载文件,我认为这些日志只是注意到文件正在从服务器“获取”。我相信服务器会缓存响应,因此您可能会看到300范围内的状态代码而不是200.