mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
Merge pull request #1892 from xinnan-tech/py_fix_mcp
update:添加Home Assistant插件超时处理和错误日志
This commit is contained in:
@@ -33,10 +33,16 @@ def hass_get_state(conn, entity_id=""):
|
||||
future = asyncio.run_coroutine_threadsafe(
|
||||
handle_hass_get_state(conn, entity_id), conn.loop
|
||||
)
|
||||
ha_response = future.result()
|
||||
# 添加10秒超时
|
||||
ha_response = future.result(timeout=10)
|
||||
return ActionResponse(Action.REQLLM, ha_response, None)
|
||||
except asyncio.TimeoutError:
|
||||
logger.bind(tag=TAG).error("获取Home Assistant状态超时")
|
||||
return ActionResponse(Action.ERROR, "请求超时", None)
|
||||
except Exception as e:
|
||||
logger.bind(tag=TAG).error(f"处理设置属性意图错误: {e}")
|
||||
error_msg = f"执行Home Assistant操作失败"
|
||||
logger.bind(tag=TAG).error(error_msg)
|
||||
return ActionResponse(Action.ERROR, error_msg, None)
|
||||
|
||||
|
||||
async def handle_hass_get_state(conn, entity_id):
|
||||
|
||||
@@ -55,10 +55,16 @@ def hass_set_state(conn, entity_id="", state={}):
|
||||
future = asyncio.run_coroutine_threadsafe(
|
||||
handle_hass_set_state(conn, entity_id, state), conn.loop
|
||||
)
|
||||
ha_response = future.result()
|
||||
# 添加10秒超时
|
||||
ha_response = future.result(timeout=10)
|
||||
return ActionResponse(Action.REQLLM, ha_response, None)
|
||||
except asyncio.TimeoutError:
|
||||
logger.bind(tag=TAG).error("设置Home Assistant状态超时")
|
||||
return ActionResponse(Action.ERROR, "请求超时", None)
|
||||
except Exception as e:
|
||||
logger.bind(tag=TAG).error(f"处理设置属性意图错误: {e}")
|
||||
error_msg = f"执行Home Assistant操作失败"
|
||||
logger.bind(tag=TAG).error(error_msg)
|
||||
return ActionResponse(Action.ERROR, error_msg, None)
|
||||
|
||||
|
||||
async def handle_hass_set_state(conn, entity_id, state):
|
||||
|
||||
Reference in New Issue
Block a user