智能家居的测试套件没有通过一个动作,但它通过另一个具有完全相同代码的动作

Test suite for smart home doesn't pass with one action, but it does with another one with the exact same code

我们为 Google Assistant 开发了智能家居操作,我们的 "staging action" 通过了智能家居测试套件。现在我们想要获得 "production action" 认证,测试套件没有通过,没有一个命令有效。设备状态正确更改,但测试套件返回以下错误:AssertionError:预期状态包括:{"on":true},实际状态:{}:预期假为真

我们之前遇到过 "staging action" 的问题,并将其确定为 HomeGraph 同步问题。我们修复了它,然后它就起作用了。 "production action's" 代码与 "staging action's" 完全相同,设置也相同。所以我们不知道我们可以做些什么来让测试套件通过。有人知道问题出在哪里吗?

以下是我们代码的摘录:

const { smarthome } = require('actions-on-google');

// creating app in constructor
this._app = smarthome({ jwt, debug: this._options.debug || false });


// code-snipped sending state to HomeGraph after creating the state object from our device states
console.info('Report state:');
console.info(inspect(state, {depth: null, showHidden: false}));

this._app.reportState(state)
.then(res => console.info('report state succeeded', res))
.catch(err => console.error('report state failed', err));

这是对应的日志:

Report state:
{
  requestId: 'c82c0c20-a10d-4ded-a456-319109188501',
  agentUserId: '730f1842168ade4dcf9be3e40ea279e7ac4e6f21c002c09909f9d9a0341d2214',
  payload: {
    devices: {
      states: {
        '500dc011398fd3c191efdfa8e13a1062f7ef4d1c': { on: true, online: true }
      }
    }
  }
}
report state succeeded {
  "requestId": "c82c0c20-a10d-4ded-a456-319109188501"
}

如果出现错误,我们预计会是这样的:

但它成功了。

已编辑:

我们通过在将 HomeGraph 发送到 HomeGraph 后直接读取状态来调整我们的代码,以查看 HomeGraph 是否从我们那里得到任何东西:

    const auth = new google.auth.GoogleAuth({
      credentials: jwt,
      scopes: ['https://www.googleapis.com/auth/homegraph']
    });

    this._hg = google.homegraph({
      version: 'v1',
      auth: auth,
    });

    this._app = smarthome({ jwt, debug: this._options.debug || false });


this._app.reportState(state).then(async res => {

      const request = {
        requestBody: {
          agentUserId: state.agentUserId,
          inputs: [{
            payload: {
              devices: Object.keys(state.payload.devices.states).map(id => ({id}))
            }
          }]
        }
      };

      console.info(require('util').inspect(request, {depth: null}));

      const readStates = await this._hg.devices.query(request);
      console.info('########## STATES in HOMEGRAPH #######################');
      console.info(readStates.data);
      return res;
    })
.catch(err => console.error('report state failed', err));

状态为空。

我们还实现了一个简单的 node.js 应用程序来通过 HomeGraph API 读取所有设备状态。所有设备状态随时为空。

主要问题是:为什么调用 this._app.reportState(state) 永远不会 运行 进入 catch 处理程序?我们将状态发送到 HomeGraph 一定有问题,但我们没有收到任何错误...?

如果您得到 {} 作为实际状态值,那么测试套件似乎无法从主页图表读取数据。这可能有两个原因。

  • 在您的生产项目中,您的测试帐户具有不同的 agentUserId
  • 您的生产项目将具有与暂存项目不同的服务帐户密钥。您可能上传了错误的密钥,这会导致测试套件中的 Home Graph API 调用不成功。

谢谢!问题已经以某种方式自行解决。也许 Google 有一个错误,但我们没有做任何事情,测试现在通过了。