python - Raspberry Pi Google Assistant 上的 Google 自定义设备操作给出错误
问题描述
我正在我的 Raspberry Pi 3 上创建一个谷歌助手,我正在尝试创建一个自定义设备操作以最终打开我的车库门。它所做的只是在这个时间点使用 LED 播放。
这是我的 actions.json 文件:
{
"manifest": {
"displayName": "Garage door",
"invocationName": "Garage door",
"category": "PRODUCTIVITY"
},
"actions": [
{
"name": "me.custom.actions.GarageDoor",
"availability": {
"deviceClasses": [
{
"assistantSdkDevice": {}
}
]
},
"intent": {
"name": "me.custom.intents.GarageDoor",
"trigger": {
"queryPatterns": [
"open the garage door",
"close the garage door"
]
}
},
"fulfillment": {
"staticFulfillment": {
"templatedResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Okay"
}
},
{
"deviceExecution": {
"command": "me.custom.commands.GarageDoor"
}
}
]
}
}
}
}
],
"types": []
}
但是当我运行命令时,我得到了这个错误:
INFO:root:Transcript of user request: "open the garage door".
INFO:root:Playing assistant response.
WARNING:root:Error during command execution
Traceback (most recent call last):
File "/home/pi/assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc/device_helpers.py", line 94, in dispatch_command
self.handlers[command](**params)
TypeError: gdoor() argument after ** must be a mapping, not NoneType
这是我的处理程序:
@device_handler.command('me.custom.commands.GarageDoor')
def gdoor(*args):
print(args)
global g_open
if g_open:
GPIO.output(18, 0)
g_open = 0
else:
GPIO.output(18, 1)
g_open = 1
我在玩 *args 以查看它是否修复了任何东西 - 它没有。出于隐私考虑,我已将包裹名称更改为自定义。我在这里很困惑。任何帮助表示赞赏!
谢谢!
解决方案
查看示例代码,函数签名似乎有点不同,因为它直接添加了参数。
@device_handler.command('com.example.commands.BlinkLight')
def blink(speed, number):
logging.info('Blinking device %s times.' % number)
delay = 1
if speed == "SLOWLY":
delay = 2
elif speed == "QUICKLY":
delay = 0.5
for i in range(int(number)):
logging.info('Device is blinking.')
time.sleep(delay)
查看操作包,您似乎没有提供任何操作来配合命令执行。如示例所示:
{
"deviceExecution": {
"command": "com.example.commands.BlinkLight",
"params": {
"speed": "$speed",
"number": "$number"
}
}
}
如果没有任何参数,它可能根本不会映射任何函数。
推荐阅读
- javascript - 汇总观察者触发时如何运行代码
- tcp - 在嵌入式 Linux 中设置 tcp 连接
- python - 在 Kaggle 上使用 TPU 训练模型时出现 NotFoundError
- ibm-cloud - IBM Cloud auth refresh_token 刷新过期的 access_token?
- python - 代码运行了 20 分钟以上,然后没有输出就停止了,这是什么问题?
- c++ - 从向量中擦除元素(hackerrank)
- python - 带有日期的 Pandas DataFrame 中的字典
- javascript - 使用 Moment.js 将 2 个日期之间的差异转换为 'y mod d' 格式
- javascript - 动态更改和保存文本框中的内容
- bash - Bash argument input changes?