如何在智能家居示例中制作持久化虚拟设备?

How to make a persistent virtual device in the Smart Home sample?

我刚下载 运行 the sample from here. It is working but whenever I connect to the web site (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 组件?

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

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

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

默认为真。但是,通过将其设置为 false,它应该在页面刷新时保留设备。

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