"""Добавляет кастомные репозитории в 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" REPOS = [ ("akinin/ha_keenetic", "integration"), ("tombabolewski/ha-vidaa-tv", "integration"), ] 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 print(" авторизация ок") for i, (repo, cat) in enumerate(REPOS, start=1): await ws.send_json({ "id": i, "type": "hacs/repositories/add", "repository": repo, "category": cat, }) data = await ws.receive_json() ok = data.get("success") print(f" {repo}: {'добавлен' if ok else json.dumps(data.get('error') or data, ensure_ascii=False)[:150]}") await ws.send_json({"id": 99, "type": "hacs/repositories/list"}) data = await ws.receive_json() repos = data.get("result") or [] print("\n репозиториев:", len(repos)) for r in repos: print(f" - {r.get('full_name')} | {r.get('category')} | {r.get('installed_version') or '—'}") asyncio.run(main())