From d1442573b55085ac7ca6101f3d923cf026cd8480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=84=E5=87=A4=E7=A7=91=E6=8A=80?= Date: Mon, 17 Mar 2025 13:38:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E9=A1=B9?= =?UTF-8?q?=EF=BC=8C=E6=8E=A7=E5=88=B6iot=E8=87=AA=E5=8A=A8=E6=B3=A8?= =?UTF-8?q?=E5=86=8Cfunction=20call=E5=8A=9F=E8=83=BD=E7=9A=84=E5=BC=80?= =?UTF-8?q?=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/config.yaml | 3 +++ main/xiaozhi-server/core/handle/iotHandle.py | 22 +++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index 7fa8a24ae..f9cd6087b 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -102,6 +102,9 @@ Intent: - change_role - get_weather +# 是否使用iot_function_handler处理,开启后iot消息会自动注册到function_call中 +use_iot_function_handler: false + Memory: mem0ai: type: mem0ai diff --git a/main/xiaozhi-server/core/handle/iotHandle.py b/main/xiaozhi-server/core/handle/iotHandle.py index 551e26b24..cf7e714a4 100644 --- a/main/xiaozhi-server/core/handle/iotHandle.py +++ b/main/xiaozhi-server/core/handle/iotHandle.py @@ -257,6 +257,7 @@ def register_device_type(descriptor): async def handleIotDescriptors(conn, descriptors): """处理物联网描述""" + bUseIotFunctionHandler = conn.config.get("use_iot_function_handler", False) functions_changed = False for descriptor in descriptors: @@ -265,16 +266,17 @@ async def handleIotDescriptors(conn, descriptors): descriptor["methods"]) conn.iot_descriptors[descriptor["name"]] = iot_descriptor - # 注册或获取设备类型 - type_id = register_device_type(descriptor) - device_functions = device_type_registry.get_device_functions(type_id) - - # 在连接级注册设备函数 - if hasattr(conn, 'func_handler'): - for func_name in device_functions: - conn.func_handler.function_registry.register_function(func_name) - logger.bind(tag=TAG).info(f"注册IOT函数到function handler: {func_name}") - functions_changed = True + if bUseIotFunctionHandler: + # 注册或获取设备类型 + type_id = register_device_type(descriptor) + device_functions = device_type_registry.get_device_functions(type_id) + + # 在连接级注册设备函数 + if hasattr(conn, 'func_handler'): + for func_name in device_functions: + conn.func_handler.function_registry.register_function(func_name) + logger.bind(tag=TAG).info(f"注册IOT函数到function handler: {func_name}") + functions_changed = True # 如果注册了新函数,更新function描述列表 if functions_changed and hasattr(conn, 'func_handler'):