- 新增完整的 Home Assistant 集成示例,支持文本对话与上下文会话 - 实现小爱音箱事件解析与 TTS 播报,支持实时打断功能 - 添加连续会话管理,支持区域上下文注入和会话超时结束 - 提供完整的配置系统、类型定义和错误处理 - 包含 Rust 扩展模块用于小爱音箱通信,支持音频流处理 - 添加单元测试、集成测试脚本和 Docker 部署支持 - 提供详细的使用文档和配置说明
31 lines
779 B
Python
31 lines
779 B
Python
import asyncio
|
|
import sys
|
|
|
|
from hass.config_loader import load_config
|
|
from hass.ha_client import HomeAssistantClient
|
|
from hass.memory import ConversationMemory
|
|
|
|
|
|
async def main() -> None:
|
|
config_path = sys.argv[1] if len(sys.argv) > 1 else "config.json"
|
|
text = sys.argv[2] if len(sys.argv) > 2 else "打开客厅灯"
|
|
|
|
config = load_config(config_path)
|
|
memory = ConversationMemory(config.runtime.persist_state_path)
|
|
await memory.load()
|
|
|
|
client = HomeAssistantClient(
|
|
config.homeassistant, memory, concurrency=config.runtime.concurrency
|
|
)
|
|
await client.start()
|
|
try:
|
|
reply = await client.process_text(text)
|
|
print(reply.speech)
|
|
finally:
|
|
await client.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|
|
|