代码之家  ›  专栏  ›  技术社区  ›  Andrew Eers

特质动作。装置。特质。模式似乎不起作用。

  •  -1
  • Andrew Eers  · 技术社区  · 6 年前

    我正试图得到 action.devices.traits.Modes 特质工作打开 action.devices.SYNC 请求,我返回以下响应:

    {
       "payload":{
          "devices":[
             {
                "id":"12345",
                "type":"action.devices.types.SWITCH",
                "traits":[
                   "action.devices.traits.OnOff",
                   "action.devices.traits.StartStop",
                   "action.devices.traits.Modes"
                ],
                "name":{
                   "defaultNames":null,
                   "name":"David",
                   "nicknames":null
                },
                "willReportState":false,
                "roomHint":"living room",
                "attributes":{
                   "pausable":true,
                   "availableModes":[
                      {
                         "name":"speed",
                         "name_values":[
                            {
                               "name_synonym":[
                                  "speed"
                               ],
                               "lang":"en"
                            }
                         ],
                         "settings":[
                            {
                               "setting_name":"slow",
                               "setting_values":[
                                  {
                                     "setting_synonym":[
                                        "slow"
                                     ],
                                     "lang":"en"
                                  }
                               ]
                            },
                            {
                               "setting_name":"normal",
                               "setting_values":[
                                  {
                                     "setting_synonym":[
                                        "normal"
                                     ],
                                     "lang":"en"
                                  }
                               ]
                            },
                            {
                               "setting_name":"fast",
                               "setting_values":[
                                  {
                                     "setting_synonym":[
                                        "fast"
                                     ],
                                     "lang":"en"
                                  }
                               ]
                            }
                         ],
                         "ordered":true
                      }
                   ]
                }
             }
          ]
       }
    }
    

    我在上验证了这个响应 https://developers.google.com/actions/smarthome/tools/validator/ ,得到的反馈说没事。

    现在,当我在智能手机的控制台或助手中键入以下短语之一时,将不会调用履行服务:

    What mode is David in?
    What speed is David in?
    What is the David's speed?
    Set the speed of David to normal.
    Set David's speed to normal.
    Set David to normal speed.
    ...
    

    所有这些都只是回到谷歌搜索。

    特征 action.devices.traits.OnOff action.devices.traits.StartStop 不过效果不错。以下短语按预期工作:

    Turn David on
    Resume David.
    ...
    

    我不知道出了什么问题,也不知道该怎么调试不过,智能家居服务或多或少是个黑匣子,所以我不知道这里发生了什么/出了什么问题。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Nick Felker    6 年前

    如文件所述 the Modes trait 对于 availableModes 以下内容:

    目前,您必须使用示例json中的名称;尚不支持自定义名称。

    通过在 GitHub sample 是的。

    但是,在您的特定速度情况下,您应该查看 FanSpeed 特质。它提供相同的功能,您可以在其中定义多个速度模式,然后在它们之间切换。您可以更新设备JSON,使其更像这样:

    {
     "payload":{
       "devices":[
         {
            "id":"12345",
            "type":"action.devices.types.SWITCH",
            "traits":[
               "action.devices.traits.OnOff",
               "action.devices.traits.StartStop",
               "action.devices.traits.FanSpeed"
            ],
            "name":{
               "defaultNames":null,
               "name":"David",
               "nicknames":null
            },
            "willReportState":false,
            "roomHint":"living room",
            "attributes":{
               "pausable":true,
               "availableFanSpeeds": {
                 "speeds": [{
                   "speed_name": "Low",
                   "speed_values": [{
                     "speed_synonym": ["low", "slow"],
                     "lang": "en"
                   },
                   {
                     "speed_synonym": ["low", "slow"],
                     "lang": "de"
                   }]
                 },
                 {
                   "speed_name": "High",
                   "speed_values": [{
                     "speed_synonym": ["high"],
                     "lang": "en"
                   },
                   {
                     "speed_synonym": ["high"],
                     "lang": "de"
                   }]
               }],
               "ordered": true
             },
             "reversible": true
            }
         }
      ]}
    }