【问题标题】:google local home 1500ms timeout issue谷歌本地主页 1500 毫秒超时问题
【发布时间】:2026-02-08 02:50:01
【问题描述】:

我正在按照 Google Codelabs 上的“为智能家居操作启用本地履行”​​教程开展 Google Home 本地履行项目。

该项目只关注本地控制,不访问远程控制。

在运行 this.app.getDeviceManager().send(deviceCommand) 之前,我需要在 executeHandler 上对我的 firestore 数据库运行查询。

这会给我如下超时错误。 状态类型:“RESPONSE_UNAVAILABLE” 成功:假 externalDebugString: "Pubsub 失败,超时 1500 毫秒。"

有没有办法可以将超时设置为超过 1500 毫秒?

以下是我的executeHandler代码:

executeHandler(request: IntentFlow.ExecuteRequest):
Promise<IntentFlow.ExecuteResponse> {
// TODO: Implement local execution
console.log("EXECUTE intent: " + JSON.stringify(request, null, 2));

const command = request.inputs[0].payload.commands[0];
const execution = command.execution[0];
const response = new Execute.Response.Builder().setRequestId(request.requestId);

const promises: Array<Promise<void>> = command.devices.map(async (device) => {
  console.log("Handling EXECUTE intent for device: " + JSON.stringify(device));

  // Convert execution params to a string for the local device
  const params = execution.params as IFireplaceParams;
  const tcpMsg = 'MWIB2,02';
  const payload = this.stringToHex(tcpMsg);
  console.log("Sending request to the smart home device:", payload);

  const firebaseDataObj = await this.queryFirebase(device.id);
  console.log("firebaseDataObj:", JSON.stringify(firebaseDataObj));

  // Construct a local device command over TCP
  const deviceCommand = new DataFlow.TcpRequestData();
  deviceCommand.requestId = request.requestId;
  deviceCommand.deviceId = device.id;
  deviceCommand.data = payload;
  deviceCommand.port = SERVER_PORT;
  deviceCommand.operation = Constants.TcpOperation.WRITE;

  try {
    const result = await this.app.getDeviceManager().send(deviceCommand);
    console.log("Sending deviceCommand result:", JSON.stringify(result));
    const state = { online: true };
    response.setSuccessState(result.deviceId, Object.assign(state, params));
  } catch (err) {
    err.errorCode = err.errorCode || 'invalid_request';
    response.setErrorState(device.id, err.errorCode);
    console.error('An error occurred sending the command', err.errorCode);
  }
});

return Promise.all(promises)
  .then(() => {
    return response.build();
  })
  .catch((e) => {
    const err = new IntentFlow.HandlerError(request.requestId, 'invalid_request', e.message);
    return Promise.reject(err);
  });

}

【问题讨论】:

    标签: google-smart-home


    【解决方案1】:

    不建议从本地家庭应用直接与外部服务通信,因为它可能不受所有支持的执行环境的支持: https://developers.google.com/assistant/smarthome/concepts/local#execution-environment

    文档建议将执行所需的其他数据作为SYNC 响应的customData 字段的一部分传递: https://developers.google.com/assistant/smarthome/develop/local#update_sync_response_in_the_cloud_fulfillment

    【讨论】: