【问题标题】:Google Custom Device Action Giving Error on Raspberry Pi Google AssistantRaspberry Pi Google Assistant 上的 Google 自定义设备操作给出错误
【发布时间】:2018-12-04 04:40:14
【问题描述】:

我正在我的 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 来查看它是否修复了任何问题 - 它没有。出于隐私考虑,我已将包裹名称更改为自定义。我在这里很困惑。任何帮助表示赞赏!

谢谢!

【问题讨论】:

    标签: python raspberry-pi google-assistant-sdk


    【解决方案1】:

    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"
            }
        }
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-06
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多