Mosquitto 2 в CT 107 (порт 1883, пароли для frigate/homeassistant/hub), проверено публикацией. Frigate переключён на этот брокер, API найден на 192.168.1.126:5000 (не .110), порты 5000/8971/8554/8555 проброшены. HA: добавлены интеграции mqtt и frigate. Frigate-интеграция не вставала: требование hass-web-proxy-lib==0.0.8 требует Python 3.14, в HA 3.13 — поставили 0.0.7 и поправили манифест. Jellyfin: старый ключ отдавал 401. Получен новый через логин akadmin и POST /Auth/Keys (нужен заголовок Authorization: MediaBrowser Token="..."), проверен по /Items/Counts, прописан в bots.env.
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
"""Подключает Frigate к HA."""
|
|
import json
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
TOK = open("/root/.ha-token", encoding="utf-8").read().strip()
|
|
BASE = "http://127.0.0.1:8123"
|
|
HDR = {"Authorization": "Bearer " + TOK, "Content-Type": "application/json"}
|
|
|
|
|
|
def call(path, method="GET", body=None):
|
|
data = json.dumps(body).encode() if body is not None else None
|
|
r = urllib.request.Request(BASE + path, data=data, method=method, headers=HDR)
|
|
try:
|
|
with urllib.request.urlopen(r, timeout=60) as x:
|
|
raw = x.read()
|
|
return (json.loads(raw) if raw else {}), None
|
|
except urllib.error.HTTPError as e:
|
|
return None, f"HTTP {e.code}: {e.read()[:250].decode('utf-8', 'replace')}"
|
|
except Exception as e:
|
|
return None, str(e)[:120]
|
|
|
|
|
|
flow, err = call("/api/config/config_entries/flow", "POST", {"handler": "frigate"})
|
|
if err:
|
|
print("старт:", err)
|
|
raise SystemExit(1)
|
|
fid = flow["flow_id"]
|
|
schema = flow.get("data_schema") or []
|
|
names = [f.get("name") for f in schema]
|
|
print("поля:", names)
|
|
|
|
payload = {"url": "http://192.168.1.126:5000", "validate_ssl": False}
|
|
# шаг 1
|
|
res, err2 = call(f"/api/config/config_entries/flow/{fid}", "POST", payload)
|
|
print("шаг1:", err2 or (res or {}).get("type"), (res or {}).get("errors"))
|
|
|
|
for _ in range(3):
|
|
if not res or res.get("type") != "form":
|
|
break
|
|
step = res.get("step_id")
|
|
sch = res.get("data_schema") or []
|
|
print(f" шаг: {step} | поля: {[f.get('name') for f in sch]}")
|
|
p2 = {}
|
|
for f in sch:
|
|
n = f.get("name")
|
|
if n in payload:
|
|
p2[n] = payload[n]
|
|
elif f.get("default") is not None:
|
|
p2[n] = f["default"]
|
|
elif f.get("type") == "boolean":
|
|
p2[n] = True
|
|
res, err3 = call(f"/api/config/config_entries/flow/{fid}", "POST", p2)
|
|
print(" →", err3 or (res or {}).get("type"), (res or {}).get("errors"))
|