简体   繁体   中英

google smart home trait-Fanspeed- speed_synonym doesn't work

I tried to use example code from codelab and modified device type for pratice. When I tried to add a Fan device to google smart home app,I got an error response.

Ex: (ask:Set the fan to speed low) (response:OK,descreasing Fan speed to 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'. 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. 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. As such, the speed_name "Low" is meant to be universally used across every language you support. 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

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.

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'
  }]
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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