HA: своя интеграция hub_devices — 104 device_tracker с именами, типами и IP. Итого 197 сущностей. Подключён ha_keenetic (CPU/WAN/порты/Wi-Fi/WireGuard), установлен vidaa_tv для Hisense. Инфраструктура: headscale отдавал 500 из-за отсутствия Upgrade-заголовков в nginx — исправлено, узел перерегистрирован, маршруты включены. tinyproxy заменён своим CONNECT-прокси на VPS + SSH-туннель (не зависит от Tailscale). Для HACS сделан прозрачный маршрут до GitHub: SSH-туннели на 6 хостов и DNAT в CT 106 с обновлением IP каждые 6 часов. Грабли: дубликат контейнера HA перехватывал порт; ScannerEntity выключен в реестре по умолчанию; легаси-платформы device_tracker удалены из HA 2026.2; имена контейнеров берутся из конфигов Proxmox, а не из роутера.
53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
"""Интеграция: устройства из Buryans Hub как device_tracker."""
|
|
import logging
|
|
|
|
import aiohttp
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
|
|
|
from .const import DOMAIN, SCAN_INTERVAL
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
PLATFORMS = ["device_tracker"]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
url = entry.data["url"].rstrip("/")
|
|
|
|
async def _fetch():
|
|
try:
|
|
timeout = aiohttp.ClientTimeout(total=20)
|
|
async with aiohttp.ClientSession(timeout=timeout) as session:
|
|
async with session.get(f"{url}/data/devices") as resp:
|
|
if resp.status != 200:
|
|
raise UpdateFailed(f"HTTP {resp.status}")
|
|
data = await resp.json()
|
|
except UpdateFailed:
|
|
raise
|
|
except Exception as e: # noqa: BLE001
|
|
raise UpdateFailed(str(e)) from e
|
|
|
|
items = data.get("items") or []
|
|
payload = (items[0].get("payload") if items else {}) or {}
|
|
devices = payload.get("devices") or []
|
|
return {d.get("mac") or d.get("ip"): d for d in devices if d.get("mac") or d.get("ip")}
|
|
|
|
coordinator = DataUpdateCoordinator(
|
|
hass, _LOGGER, name=DOMAIN, update_method=_fetch, update_interval=SCAN_INTERVAL
|
|
)
|
|
await coordinator.async_config_entry_first_refresh()
|
|
|
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
|
if unload_ok:
|
|
hass.data.get(DOMAIN, {}).pop(entry.entry_id, None)
|
|
return unload_ok
|