mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-23 23:53:55 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b9174b67e | ||
|
|
6c04a6cf69 |
@@ -167,5 +167,5 @@ public interface Constant {
|
|||||||
/**
|
/**
|
||||||
* 版本号
|
* 版本号
|
||||||
*/
|
*/
|
||||||
public static final String VERSION = "0.3.7";
|
public static final String VERSION = "0.3.8";
|
||||||
}
|
}
|
||||||
+3
-2
@@ -260,8 +260,9 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
|||||||
dataMap.put("id", deviceId);
|
dataMap.put("id", deviceId);
|
||||||
dataMap.put("mac_address", deviceId);
|
dataMap.put("mac_address", deviceId);
|
||||||
|
|
||||||
dataMap.put("board", (deviceReport.getChipModelName() != null) ? deviceReport.getChipModelName()
|
dataMap.put("board", (deviceReport.getBoard() != null && deviceReport.getBoard().getType() != null)
|
||||||
: (deviceReport.getBoard() != null ? deviceReport.getBoard().getType() : "unknown"));
|
? deviceReport.getBoard().getType()
|
||||||
|
: (deviceReport.getChipModelName() != null ? deviceReport.getChipModelName() : "unknown"));
|
||||||
dataMap.put("app_version", (deviceReport.getApplication() != null)
|
dataMap.put("app_version", (deviceReport.getApplication() != null)
|
||||||
? deviceReport.getApplication().getVersion()
|
? deviceReport.getApplication().getVersion()
|
||||||
: null);
|
: null);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import sys
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
from config.config_loader import load_config
|
from config.config_loader import load_config
|
||||||
|
|
||||||
SERVER_VERSION = "0.3.7"
|
SERVER_VERSION = "0.3.8"
|
||||||
|
|
||||||
|
|
||||||
def get_module_abbreviation(module_name, module_dict):
|
def get_module_abbreviation(module_name, module_dict):
|
||||||
|
|||||||
@@ -243,8 +243,8 @@ class ConnectionHandler:
|
|||||||
begin_time = time.time()
|
begin_time = time.time()
|
||||||
private_config = get_private_config_from_api(
|
private_config = get_private_config_from_api(
|
||||||
self.config,
|
self.config,
|
||||||
self.headers.get("device-id", None),
|
self.headers.get("device-id"),
|
||||||
self.headers.get("client-id", None),
|
self.headers.get("client-id", self.headers.get("device-id")),
|
||||||
)
|
)
|
||||||
private_config["delete_audio"] = bool(self.config.get("delete_audio", True))
|
private_config["delete_audio"] = bool(self.config.get("delete_audio", True))
|
||||||
self.logger.bind(tag=TAG).info(
|
self.logger.bind(tag=TAG).info(
|
||||||
@@ -622,7 +622,7 @@ class ConnectionHandler:
|
|||||||
)
|
)
|
||||||
if not bHasError:
|
if not bHasError:
|
||||||
response_message.clear()
|
response_message.clear()
|
||||||
self.logger.bind(tag=TAG).info(
|
self.logger.bind(tag=TAG).debug(
|
||||||
f"function_name={function_name}, function_id={function_id}, function_arguments={function_arguments}"
|
f"function_name={function_name}, function_id={function_id}, function_arguments={function_arguments}"
|
||||||
)
|
)
|
||||||
function_call_data = {
|
function_call_data = {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class FunctionHandler:
|
|||||||
func = funcItem.func
|
func = funcItem.func
|
||||||
arguments = function_call_data["arguments"]
|
arguments = function_call_data["arguments"]
|
||||||
arguments = json.loads(arguments) if arguments else {}
|
arguments = json.loads(arguments) if arguments else {}
|
||||||
logger.bind(tag=TAG).info(f"调用函数: {function_name}, 参数: {arguments}")
|
logger.bind(tag=TAG).debug(f"调用函数: {function_name}, 参数: {arguments}")
|
||||||
if (
|
if (
|
||||||
funcItem.type == ToolType.SYSTEM_CTL
|
funcItem.type == ToolType.SYSTEM_CTL
|
||||||
or funcItem.type == ToolType.IOT_CTL
|
or funcItem.type == ToolType.IOT_CTL
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ def create_iot_function(device_name, method_name, method_info):
|
|||||||
response_failure = "操作失败"
|
response_failure = "操作失败"
|
||||||
|
|
||||||
# 打印响应参数
|
# 打印响应参数
|
||||||
logger.bind(tag=TAG).info(
|
logger.bind(tag=TAG).debug(
|
||||||
f"控制函数接收到的响应参数: success='{response_success}', failure='{response_failure}'"
|
f"控制函数接收到的响应参数: success='{response_success}', failure='{response_failure}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ class IotDescriptor:
|
|||||||
# 根据描述创建属性
|
# 根据描述创建属性
|
||||||
if properties is not None:
|
if properties is not None:
|
||||||
for key, value in properties.items():
|
for key, value in properties.items():
|
||||||
property_item = globals()[key] = {}
|
property_item = {}
|
||||||
property_item["name"] = key
|
property_item["name"] = key
|
||||||
property_item["description"] = value["description"]
|
property_item["description"] = value["description"]
|
||||||
if value["type"] == "number":
|
if value["type"] == "number":
|
||||||
@@ -160,18 +160,17 @@ class IotDescriptor:
|
|||||||
# 根据描述创建方法
|
# 根据描述创建方法
|
||||||
if methods is not None:
|
if methods is not None:
|
||||||
for key, value in methods.items():
|
for key, value in methods.items():
|
||||||
method = globals()[key] = {}
|
method = {}
|
||||||
method["description"] = value["description"]
|
method["description"] = value["description"]
|
||||||
method["name"] = key
|
method["name"] = key
|
||||||
for k, v in value["parameters"].items():
|
# 检查方法是否有参数
|
||||||
method[k] = {}
|
if "parameters" in value:
|
||||||
method[k]["description"] = v["description"]
|
method["parameters"] = {}
|
||||||
if v["type"] == "number":
|
for k, v in value["parameters"].items():
|
||||||
method[k]["value"] = 0
|
method["parameters"][k] = {
|
||||||
elif v["type"] == "boolean":
|
"description": v["description"],
|
||||||
method[k]["value"] = False
|
"type": v["type"],
|
||||||
else:
|
}
|
||||||
method[k]["value"] = ""
|
|
||||||
self.methods.append(method)
|
self.methods.append(method)
|
||||||
|
|
||||||
|
|
||||||
@@ -221,13 +220,19 @@ def register_device_type(descriptor):
|
|||||||
func_name = f"{device_name.lower()}_{method_name.lower()}"
|
func_name = f"{device_name.lower()}_{method_name.lower()}"
|
||||||
|
|
||||||
# 创建参数字典,添加原有参数
|
# 创建参数字典,添加原有参数
|
||||||
parameters = {
|
parameters = {}
|
||||||
param_name: {
|
required_params = []
|
||||||
"type": param_info["type"],
|
|
||||||
"description": param_info["description"],
|
# 如果方法有参数,则添加参数信息
|
||||||
|
if "parameters" in method_info:
|
||||||
|
parameters = {
|
||||||
|
param_name: {
|
||||||
|
"type": param_info["type"],
|
||||||
|
"description": param_info["description"],
|
||||||
|
}
|
||||||
|
for param_name, param_info in method_info["parameters"].items()
|
||||||
}
|
}
|
||||||
for param_name, param_info in method_info["parameters"].items()
|
required_params = list(method_info["parameters"].keys())
|
||||||
}
|
|
||||||
|
|
||||||
# 添加响应参数
|
# 添加响应参数
|
||||||
parameters.update(
|
parameters.update(
|
||||||
@@ -244,7 +249,6 @@ def register_device_type(descriptor):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# 构建必须参数列表(原有参数 + 响应参数)
|
# 构建必须参数列表(原有参数 + 响应参数)
|
||||||
required_params = list(method_info["parameters"].keys())
|
|
||||||
required_params.extend(["response_success", "response_failure"])
|
required_params.extend(["response_success", "response_failure"])
|
||||||
|
|
||||||
func_desc = {
|
func_desc = {
|
||||||
@@ -282,6 +286,25 @@ async def handleIotDescriptors(conn, descriptors):
|
|||||||
functions_changed = False
|
functions_changed = False
|
||||||
|
|
||||||
for descriptor in descriptors:
|
for descriptor in descriptors:
|
||||||
|
|
||||||
|
# 如果descriptor没有properties和methods,则直接跳过
|
||||||
|
if "properties" not in descriptor and "methods" not in descriptor:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 处理缺失properties的情况
|
||||||
|
if "properties" not in descriptor:
|
||||||
|
descriptor["properties"] = {}
|
||||||
|
# 从methods中提取所有参数作为properties
|
||||||
|
if "methods" in descriptor:
|
||||||
|
for method_name, method_info in descriptor["methods"].items():
|
||||||
|
if "parameters" in method_info:
|
||||||
|
for param_name, param_info in method_info["parameters"].items():
|
||||||
|
# 将参数信息转换为属性信息
|
||||||
|
descriptor["properties"][param_name] = {
|
||||||
|
"description": param_info["description"],
|
||||||
|
"type": param_info["type"],
|
||||||
|
}
|
||||||
|
|
||||||
# 创建IOT设备描述符
|
# 创建IOT设备描述符
|
||||||
iot_descriptor = IotDescriptor(
|
iot_descriptor = IotDescriptor(
|
||||||
descriptor["name"],
|
descriptor["name"],
|
||||||
@@ -375,19 +398,17 @@ async def send_iot_conn(conn, name, method_name, parameters):
|
|||||||
for method in value.methods:
|
for method in value.methods:
|
||||||
# 找到了方法
|
# 找到了方法
|
||||||
if method["name"] == method_name:
|
if method["name"] == method_name:
|
||||||
await conn.websocket.send(
|
# 构建命令对象
|
||||||
json.dumps(
|
command = {
|
||||||
{
|
"name": name,
|
||||||
"type": "iot",
|
"method": method_name,
|
||||||
"commands": [
|
}
|
||||||
{
|
|
||||||
"name": name,
|
# 只有当参数不为空时才添加parameters字段
|
||||||
"method": method_name,
|
if parameters:
|
||||||
"parameters": parameters,
|
command["parameters"] = parameters
|
||||||
}
|
send_message = json.dumps({"type": "iot", "commands": [command]})
|
||||||
],
|
await conn.websocket.send(send_message)
|
||||||
}
|
logger.bind(tag=TAG).info(f"发送物联网指令: {send_message}")
|
||||||
)
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
logger.bind(tag=TAG).error(f"未找到方法{method_name}")
|
logger.bind(tag=TAG).error(f"未找到方法{method_name}")
|
||||||
|
|||||||
Reference in New Issue
Block a user