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())
|
||
|
|
|