首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google自定义设备操作在Raspberry Pi Google Assistant上出现错误

Google自定义设备操作在Raspberry Pi Google Assistant上出现错误
EN

Stack Overflow用户
提问于 2018-12-03 06:08:03
回答 1查看 170关注 0票数 1

我正在我的Raspberry Pi 3上创建一个google助手,并且我正在尝试创建一个自定义的设备操作,以最终打开我的车库门。它所做的一切就是在这个时间点上玩LED。

这是我的actions.json文件:

代码语言:javascript
复制
{
    "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": []
}

但是当我运行这个命令时,我得到了这个错误:

代码语言:javascript
复制
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

这是我的处理程序:

代码语言:javascript
复制
@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,看看它是否修复了什么--它没有。为了保护隐私,我已经把我的包名改成了custom。我对此很困惑。感谢任何人的帮助!

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2018-12-04 04:40:15

看看the sample code,看起来函数签名有点不同,因为它直接添加了参数。

代码语言:javascript
复制
@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所示

代码语言:javascript
复制
{
    "deviceExecution": {
        "command": "com.example.commands.BlinkLight",
        "params": {
            "speed": "$speed",
            "number": "$number"
        }
    }
}

如果没有任何参数,它可能根本不会映射任何函数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53585059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档