特质action.devices.traits.Modes似乎不起作用

时间:2018-07-18 09:07:21

标签: actions-on-google google-home google-smart-home

我正在尝试使action.devices.traits.Modes特性发挥作用。根据{{​​1}}的请求,我返回以下响应:

action.devices.SYNC

我在https://developers.google.com/actions/smarthome/tools/validator/上验证了此回复,并得到了很好的反馈。

现在,当我在智能手机上输入控制台或助手时,出现以下短语之一,则不会调用履行服务:

{
   "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
                  }
               ]
            }
         }
      ]
   }
}

所有这些都只是依靠Google搜索。

特征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

我不知道发生了什么问题以及调试该怎么做。 AFAIK,智能家居服务或多或少是一个黑匣子,所以我不确定这里是怎么回事。

1 个答案:

答案 0 :(得分:2)

availableModes的{​​{3}}文档中所述:

  

当前,您必须在示例JSON中使用名称;自定义名称尚不受支持。

可以通过在the Modes trait上提交问题来逐个手动创建名称。

但是,在特定的速度情况下,您应该查看GitHub sample特性。它提供了相同的功能,您可以在其中定义多个速度模式,然后在它们之间进行切换。您可以更新设备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
        }
     }
  ]}
}