From 3a754723f0747d614b45324c827c835314af4dbf Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Mon, 24 Feb 2025 22:01:07 +0800 Subject: [PATCH] =?UTF-8?q?fixed:iot=20boolean=20=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=8E=A5=E6=94=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 4 +++- core/connection.py | 4 +++- core/handle/iotHandle.py | 14 +++++--------- core/handle/textHandle.py | 3 +-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/config.yaml b/config.yaml index 9fbb78d53..5dd2793e9 100644 --- a/config.yaml +++ b/config.yaml @@ -41,7 +41,9 @@ manager: enabled: false ip: 0.0.0.0 port: 8002 - +iot: + Speaker: + volume: 100 xiaozhi: type: hello version: 1 diff --git a/core/connection.py b/core/connection.py index cbf183b9b..ead530805 100644 --- a/core/connection.py +++ b/core/connection.py @@ -4,6 +4,7 @@ import uuid import time import queue import asyncio +import traceback from config.logger import setup_logging import threading import websockets @@ -149,7 +150,8 @@ class ConnectionHandler: await ws.close() return except Exception as e: - self.logger.bind(tag=TAG).error(f"Connection error: {str(e)}") + stack_trace = traceback.format_exc() + self.logger.bind(tag=TAG).error(f"Connection error: {str(e)}-{stack_trace}") await ws.close() return diff --git a/core/handle/iotHandle.py b/core/handle/iotHandle.py index 99f059e2d..7fba6991d 100644 --- a/core/handle/iotHandle.py +++ b/core/handle/iotHandle.py @@ -44,12 +44,10 @@ class IotDescriptor: property_item["description"] = value["description"] if value["type"] == "number": property_item["value"] = 0 - elif value["type"] == "bool": + elif value["type"] == "boolean": property_item["value"] = False - elif value["type"] == "string": - property_item["value"] = "" else: - raise ValueError("Invalid type") + property_item["value"] = "" self.properties.append(property_item) # 根据描述创建方法 @@ -75,12 +73,10 @@ class IotDescriptor: method[k]["description"] = v["description"] if v["type"] == "number": method[k]["value"] = 0 - elif v["type"] == "bool": + elif v["type"] == "boolean": method[k]["value"] = False - elif v["type"] == "string": - method[k]["value"] = "" else: - raise ValueError("Invalid type") + method[k]["value"] = "" self.methods.append(method) @@ -92,7 +88,7 @@ async def handleIotDescriptors(conn, descriptors): "name":"Speaker", "description":"当前 AI 机器人的扬声器", "properties":{ - "volume":{"description":"当前音量 值","type":"number"} 可以有bool, int, string三种类型 + "volume":{"description":"当前音量 值","type":"number"} 可以有boolean, number, string三种类型 }, "methods":{ "SetVolume":{ diff --git a/core/handle/textHandle.py b/core/handle/textHandle.py index 8e34aa724..133fddf72 100644 --- a/core/handle/textHandle.py +++ b/core/handle/textHandle.py @@ -39,7 +39,6 @@ async def handleTextMessage(conn, message): await startToChat(conn, msg_json["text"]) elif msg_json["type"] == "iot": if "descriptors" in msg_json: - pass - # await handleIotDescriptors(conn, msg_json["descriptors"]) + await handleIotDescriptors(conn, msg_json["descriptors"]) except json.JSONDecodeError: await conn.websocket.send(message)