简体   繁体   English

google smart home trait-Fanspeed-speed_synonym 不起作用

[英]google smart home trait-Fanspeed- speed_synonym doesn't work

I tried to use example code from codelab and modified device type for pratice.我尝试使用 codelab 中的示例代码和修改后的设备类型进行练习。 When I tried to add a Fan device to google smart home app,I got an error response.当我尝试将风扇设备添加到 google 智能家居应用程序时,我收到了错误响应。

Ex: (ask:Set the fan to speed low) (response:OK,descreasing Fan speed to speedslow .)例如:(问:设置风扇速度低)(回应:OK,descreasing风扇转速speedslow)

app.onSync(async (body, headers) => {
  console.log('onSync');
  return {
    requestId: body.requestId,
    payload: {
      agentUserId: agentId,
      devices: [{
        id: 'fan',
        type: 'action.devices.types.FAN',
        traits: [
          'action.devices.traits.OnOff',
          'action.devices.traits.FanSpeed',
          //'action.devices.traits.Mode',
        ],
        name: {
          name: 'Fan',
        },
        deviceInfo: {
          manufacturer: 'AAA',
          model: 'BBB-Fan1',
          hwVersion: '1.0',
          swVersion: '1.0.1',
        },
        willReportState: true,
        attributes: {
            availableFanSpeeds: {
                speeds: [{
                    speed_name: 'Low',
                    speed_values: [{
                        speed_synonym: ['speedslow','speedlow','speedsmall','slow','low','small','minimum'],
                        lang: 'en'
                    }]
                },{
                    speed_name: 'Medium',
                    speed_values: [{
                        speed_synonym: ['medium','speed medium'],
                        lang: 'en'
                    }]
                },{
                    speed_name: 'High',
                    speed_values: [{
                        speed_synonym: ['speed fast','speed high','speed big','fast','high','big','maximum'],
                        lang: 'en'
                    }]
                }],
            ordered: true
          },
          reversible: true,

Q1: The 'speedslow' is my speed_synonym below the speed_name 'Low'. Q1: 'speedslow' 是我在 speed_name 'Low' 下面的 speed_synonym。 I think that it need to response the answer like 'OK,descreasing Fan speed to Low'.Right?我认为它需要响应“好的,将风扇速度降低到低”之类的答案。对吗?

Q2: In traits page ,it has not support Chinese language. Q2:在traits页面中,它不支持中文。 I found that I could use some Chinese words to control device behavior like 'Open the Fan' in Chinese language through google assistant app.我发现我可以使用一些中文词来控制设备行为,例如通过谷歌助手应用程序以中文显示“打开风扇”。 But I also found that I couldn't use some Chinese words like 'Set fan speed to low' to change my device state.So it seems Chinese language doesn't support right?但是我也发现我不能用一些中文词,比如“设置风扇速度为低”来改变我的设备状态。所以好像不支持中文吧?

With regards to your questions, I don't believe you're getting an error response.关于您的问题,我认为您不会收到错误响应。 The way that availableFanSpeeds works is by creating a key for each mode, and a set of synonyms per language that fit in that mode. availableFanSpeeds工作方式是为每种模式创建一个key ,并为适合该模式的每种语言创建一组synonyms As such, the speed_name "Low" is meant to be universally used across every language you support.因此, speed_name "Low" 旨在在您支持的每种语言中普遍使用。 This means that the platform can't necessarily use the key "Low" everywhere.这意味着平台不一定在任何地方都使用“低”键。

In French, then it would say:在法语中,它会说:

OK, diminution de la vitesse du ventilateur à low好的,diminution de la vitesse du ventilateur à low

Which would sound odd to a French user.这对法国用户来说听起来很奇怪。 As such, the "synonyms" field is used, which is designed to be an array of words that mean the same thing in each language.因此,使用了“同义词”字段,该字段被设计为在每种语言中表示相同事物的单词数组。 Using the first element of the synonyms array can be used to create a better localized output.使用同义词数组的第一个元素可用于创建更好的本地化输出。

The documentation does not show support for Chinese, but even if it did you would need to create a second array that shows the synonyms for a specific fan speed in that language.该文档不显示对中文的支持,但即使支持,您也需要创建第二个数组来显示该语言中特定风扇速度的同义词。 The platform does not translate these keys for you, they should be provided for each language.平台不会为您翻译这些密钥,应为每种语言提供它们。 This allows you to provide values that may be common words like "low" but also any device-specific names like "Not Fast™ mode" which may not be translatable.这允许您提供可能是诸如“low”之类的常见词以及任何特定于设备的名称(例如可能无法翻译的“Not Fast™ mode”)的值。

You would have to modify your array to add a new language code.您必须修改数组以添加新的语言代码。 Below I add synonyms for French.下面我添加法语的同义词。

speeds: [{
  speed_name: 'Low',
  speed_values: [{
    speed_synonym: ['speedslow','speedlow','speedsmall','slow','low','small','minimum'],
    lang: 'en'
  }, {
    speed_synonym: ['faible', 'petite', 'petit'],
    lang: 'fr'
  }]
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM