我正在我的Raspberry Pi 3上创建一个Google助手,并且试图创建一个自定义设备操作来最终打开我的车库门。在这个时间点上,它所做的就是用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周围玩耍,看看它是否可以修复任何东西-没错。我已将软件包名称更改为自定义,仅出于保密目的。我在这里很困惑。任何帮助表示赞赏!
谢谢!
答案 0 :(得分:0)
从the sample code看,函数签名似乎有所不同,因为它直接添加了参数。
@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)
看一下动作包,似乎您没有提供任何与命令执行一起进行的动作。如the sample所示:
{
"deviceExecution": {
"command": "com.example.commands.BlinkLight",
"params": {
"speed": "$speed",
"number": "$number"
}
}
}
没有任何参数,它可能根本不会映射任何功能。