<ph type="x-smartling-placeholder">
您可以根据需要向设备模型添加任意数量的特征。这些特征是 并非只能局限于一种设备类型,您可以根据自己的喜好来使用这些设备。
以下是添加任何特征并处理传入命令的过程:
确定您需要的特征 添加。
打开
hotword.py
文件。cd assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/library
nano hotword.py
将以下代码块添加到 会处理
action.devices.commands.OnOff
命令(不要删除现有的 代码块中)。if command == "action.devices.commands.
command-name ":
if params['parameter-name ']:
ifconditional :
print('Something happened.')
else:
print('Something else happened.')在上述代码块中找到每个变量所需的信息。
command-name
从以下位置前往特定特征页面: 第 1 步(例如 ColorTemperature)。 使用设备命令表中的命令。 parameter-name
再次查看设备命令 表格。每个命令都有一个或多个参数 及其关联。这些项列在 EXECUTE 中的 "params"
下 请求 JSON。请使用确切的参数名称。请注意,其中一些 参数是指包含其他参数的对象 - 只需使用 顶级对象。conditional
您并不一定要使用条件语句 ,但可能有助于您区分 命令。 下面是一些特征亮度特征的示例 和 ColorTemperature:
if command == "action.devices.commands.BrightnessAbsolute":
if params['brightness']:
if params['brightness'] > 50:
print('brightness > 50')
else:
print('brightness <= 50')
if command == "action.devices.commands.ColorAbsolute":
if params['color']:
if params['color'].get('name') == "blue":
print('The color is blue.')
else:
print('The color is not blue.')更新设备模型 替换成您在第 1 步中添加的特征。
运行修改后的源代码。
cd assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/library
python hotword.py --device-model-id
my-model 请尝试查询。
Hey Google,将亮度设为 65%。
Ok Google,设为蓝色