mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
开发板的状态更新需要在开发板部分刷新以后发送的请求里面更新, 不应该直接服务器自己更新
This commit is contained in:
parent
c796af7d07
commit
09cfeb04ee
1 changed files with 0 additions and 31 deletions
|
|
@ -90,8 +90,6 @@ def create_iot_query_function(device_name, prop_name, prop_info):
|
||||||
logger.bind(tag=TAG).info(
|
logger.bind(tag=TAG).info(
|
||||||
f"查询函数接收到的响应参数: success='{response_success}', failure='{response_failure}'")
|
f"查询函数接收到的响应参数: success='{response_success}', failure='{response_failure}'")
|
||||||
|
|
||||||
value = await get_iot_status(conn, device_name, prop_name)
|
|
||||||
|
|
||||||
# 查询成功,生成结果
|
# 查询成功,生成结果
|
||||||
if value is not None:
|
if value is not None:
|
||||||
# 使用大模型提供的成功响应,并替换其中的占位符
|
# 使用大模型提供的成功响应,并替换其中的占位符
|
||||||
|
|
@ -114,35 +112,6 @@ def create_iot_query_function(device_name, prop_name, prop_info):
|
||||||
return wrap_async_function(iot_query_function)
|
return wrap_async_function(iot_query_function)
|
||||||
|
|
||||||
|
|
||||||
async def update_state_by_method(conn, device_name, method_name, params):
|
|
||||||
"""根据方法和参数自动更新设备状态"""
|
|
||||||
try:
|
|
||||||
# 规则1: 方法名为TurnOn,设置power为True
|
|
||||||
if method_name == "TurnOn":
|
|
||||||
await set_iot_status(conn, device_name, "power", True)
|
|
||||||
|
|
||||||
# 规则2: 方法名为TurnOff,设置power为False
|
|
||||||
elif method_name == "TurnOff":
|
|
||||||
await set_iot_status(conn, device_name, "power", False)
|
|
||||||
|
|
||||||
# 规则3: Set开头的方法,尝试更新对应参数
|
|
||||||
elif method_name.startswith("Set"):
|
|
||||||
# 从参数中找到可能的状态值
|
|
||||||
for param_name, param_value in params.items():
|
|
||||||
# 尝试更新对应名称的属性
|
|
||||||
await set_iot_status(conn, device_name, param_name, param_value)
|
|
||||||
|
|
||||||
# 其他方法,尝试直接从参数更新状态
|
|
||||||
else:
|
|
||||||
for param_name, param_value in params.items():
|
|
||||||
# 检查设备是否有此属性
|
|
||||||
status = await get_iot_status(conn, device_name, param_name)
|
|
||||||
if status is not None: # 属性存在
|
|
||||||
await set_iot_status(conn, device_name, param_name, param_value)
|
|
||||||
except Exception as e:
|
|
||||||
logger.bind(tag=TAG).warning(f"自动更新状态失败: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
class IotDescriptor:
|
class IotDescriptor:
|
||||||
"""
|
"""
|
||||||
A class to represent an IoT descriptor.
|
A class to represent an IoT descriptor.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue