【问题标题】:How to create a config file for a homebridge accessory如何为 homebridge 配件创建配置文件
【发布时间】:2019-09-16 23:56:08
【问题描述】:

我已经安装了一个插件来通过我的 Homebridge 服务器控制我的三星电视 (https://github.com/xeenon/homebridge-samsung-tv),但是开发人员没有提供 config-sample.json,因此我尝试自己制作。我对编码完全陌生,所以请告诉我我做错了什么。

这是我目前该配件的配置文件的一部分(稍后我将添加 ip 地址和 mac 地址)。

{
"bridge": {
    "name": "Homebridge",
    "username": "",
    "port": 4318,
    "pin": "031-45-154"
},
"accessories": [{
    "accessory": "samsungTv",
    "name": "samsungTvAccessory",
    "ip_address": "",
    "macAddress": "",
    "polling": "true",
    "pollingInterval": "1"
}]
}

当我尝试启动 Homebridge 时出现错误

TypeError: Cannot read property 'forEach' of undefined
at new SamsungTvAccessory (usr/local/lib/node_modules/homebridge-samsung-tv-controller/index.js:76:10

如果我将配置文件更改为

{
"bridge": {
    "name": "Homebridge",
    "username": "",
    "port": 4318,
    "pin": "031-45-154"
},
"accessories": [{
    "accessory": "samsungTv",
    "name": "samsungTvAccessory",
    "ip_address": "",
    "macAddress": "",
    "polling": "true",
    "pollingInterval": "1",
    "enabledInputs": "true"
}]
}

我添加的地方

"enabledInputs": "true"

我得到了错误

TypeError: config.enabledInputs.forEach is not a function
at new SamsungTvAccessory (usr/local/lib/node_modules/homebridge-samsung-tv-controller/index.js:76:10

非常感谢任何帮助!

【问题讨论】:

    标签: json config homekit


    【解决方案1】:

    您尝试过有效的 JSON 吗?会告诉你周围缺少括号,也来自它看起来像的第一行源代码。它应该像这样工作

    objectVar = {
        "accessory": "samsungTv",
        "name": "samsungTvAccessory",
        "ip_adress": "",
        "macAddress": "",
        "polling": "true",
        "pollingInterval": "1"
    }
    

    或者像这样,如果你在某处使用字符串:"{\"accessory\":\"samsungTv\",\"name\":\"samsungTvAccessory\",\"ip_adress\":\"\ ",\"macAddress\":\"\",\"polling\":\"true\",\"pollingInterval\":\"1\"}"

    还有方法 JSON.stringify(objectVar [, null, indent]) 或 JSON.parse(string) 转换为字符串或返回。 Stringify 也有可选参数 - 第一个是替换函数,第二个缩进,如果您希望它的格式对人友好。

    【讨论】:

      猜你喜欢
      • 2011-01-09
      • 1970-01-01
      • 2018-05-26
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-31
      相关资源
      最近更新 更多