mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 01:23:55 +08:00
feat: 为多个模块添加类型注解以增强代码可读性
为 ConnectionHandler 相关的函数参数添加类型注解,使用 TYPE_CHECKING 避免循环导入。主要修改包括: - 在 abortHandle、textHandle 等处理模块中为 conn 参数添加 ConnectionHandler 类型注解 - 在 websocket_server、connection 等核心模块中为方法参数添加类型注解 - 在 plugins_func 下的多个功能模块中为函数参数添加类型注解 - 在 providers 相关模块中为工具执行器和方法添加类型注解 - 统一代码格式,如将单引号字符串改为双引号 Fixes #2034
This commit is contained in:
@@ -3,6 +3,10 @@ from plugins_func.functions.hass_init import initialize_hass_handler
|
||||
from config.logger import setup_logging
|
||||
import asyncio
|
||||
import requests
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.connection import ConnectionHandler
|
||||
|
||||
TAG = __name__
|
||||
logger = setup_logging()
|
||||
@@ -27,7 +31,7 @@ hass_get_state_function_desc = {
|
||||
|
||||
|
||||
@register_function("hass_get_state", hass_get_state_function_desc, ToolType.SYSTEM_CTL)
|
||||
def hass_get_state(conn, entity_id=""):
|
||||
def hass_get_state(conn: "ConnectionHandler", entity_id=""):
|
||||
try:
|
||||
ha_response = handle_hass_get_state(conn, entity_id)
|
||||
return ActionResponse(Action.REQLLM, ha_response, None)
|
||||
@@ -40,7 +44,7 @@ def hass_get_state(conn, entity_id=""):
|
||||
return ActionResponse(Action.ERROR, error_msg, None)
|
||||
|
||||
|
||||
def handle_hass_get_state(conn, entity_id):
|
||||
def handle_hass_get_state(conn: "ConnectionHandler", entity_id):
|
||||
ha_config = initialize_hass_handler(conn)
|
||||
api_key = ha_config.get("api_key")
|
||||
base_url = ha_config.get("base_url")
|
||||
|
||||
Reference in New Issue
Block a user