"""Добавляет YandexStation в HACS и ставит его.""" import asyncio import json import aiohttp TOKEN = open("/tmp/ha-token", encoding="utf-8").read().strip() WS = "ws://127.0.0.1:8123/api/websocket" REPO = "AlexxIT/YandexStation" async def main(): async with aiohttp.ClientSession() as session: async with session.ws_connect(WS) as ws: await ws.receive_json() await ws.send_json({"type": "auth", "access_token": TOKEN}) msg = await ws.receive_json() if msg["type"] != "auth_ok": print(" auth:", msg) return await ws.send_json({"id": 1, "type": "hacs/repositories/add", "repository": REPO, "category": "integration"}) d = await ws.receive_json() print(f" добавить {REPO}: {'ок' if d.get('success') else json.dumps(d.get('error') or d, ensure_ascii=False)[:200]}") if not d.get("success"): return await ws.send_json({"id": 2, "type": "hacs/repositories/list"}) lst = await ws.receive_json() target = None for r in (lst.get("result") or []): if (r.get("full_name") or "").lower() == REPO.lower(): target = r break if not target: print(" репозиторий не найден в списке") return print(" id:", target.get("id"), "| версия:", target.get("available_version") or target.get("last_version")) await ws.send_json({"id": 3, "type": "hacs/repository/download", "repository": target.get("id")}) d3 = await ws.receive_json() print(" установка:", "ок" if d3.get("success") else json.dumps(d3.get("error") or d3, ensure_ascii=False)[:200]) asyncio.run(main())