In ha-dev brach jeder Versuch, den Abfrageabstand oder die HA-Adresse zu
sichern, mit einem 500er ab. Im Protokoll stand der Grund:
ValueError: Config entry update listeners should not be used with
OptionsFlowWithReload
Der Eintrag meldete zusaetzlich einen add_update_listener an, der beim
Aendern neu laedt - genau das macht OptionsFlowWithReload aber schon
selbst, und Home Assistant weist die Kombination rundheraus ab. Der
Listener faellt weg.
Die Tests in test_config_flow.py konnten das nicht sehen: dort ist
async_setup_entry durchweg ersetzt, der Eintrag wird also nie wirklich
aufgesetzt und meldet auch keinen Listener an. Der neue Test in
test_init.py laeuft am eingerichteten Eintrag und faellt, wenn man den
Listener wieder einbaut - gegengeprueft.
76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
"""Die ninstrip-Integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.const import CONF_HOST, CONF_TOKEN, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import config_validation as cv
|
|
from homeassistant.helpers import issue_registry as ir
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
from homeassistant.helpers.typing import ConfigType
|
|
|
|
from .api import NinstripClient
|
|
from .const import DEFAULT_PORT, DOMAIN
|
|
from .coordinator import NinstripConfigEntry, NinstripCoordinator
|
|
from .shared import async_get_shared, async_start_catalog, async_stop_catalog
|
|
|
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
|
|
|
PLATFORMS: list[Platform] = [
|
|
Platform.LIGHT,
|
|
Platform.SELECT,
|
|
Platform.SENSOR,
|
|
Platform.BUTTON,
|
|
Platform.SWITCH,
|
|
Platform.NUMBER,
|
|
Platform.BINARY_SENSOR,
|
|
Platform.UPDATE,
|
|
]
|
|
|
|
|
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|
"""Die Ausgabe fuer die Abbilder haengt an http und wird einmal angemeldet."""
|
|
async_get_shared(hass)
|
|
return True
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: NinstripConfigEntry) -> bool:
|
|
"""Einen Strip einrichten."""
|
|
client = NinstripClient(
|
|
async_get_clientsession(hass),
|
|
entry.data[CONF_HOST],
|
|
entry.data[CONF_TOKEN],
|
|
port=entry.data.get("port", DEFAULT_PORT),
|
|
)
|
|
coordinator = NinstripCoordinator(hass, entry, client)
|
|
await coordinator.async_config_entry_first_refresh()
|
|
|
|
entry.runtime_data = coordinator
|
|
await async_start_catalog(hass, async_get_shared(hass))
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: NinstripConfigEntry) -> bool:
|
|
entladen = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
|
# Der Katalog gehoert allen Eintraegen gemeinsam; er laeuft weiter,
|
|
# solange noch einer da ist.
|
|
if entladen and not [
|
|
anderer
|
|
for anderer in hass.config_entries.async_loaded_entries(DOMAIN)
|
|
if anderer.entry_id != entry.entry_id
|
|
]:
|
|
async_stop_catalog(async_get_shared(hass))
|
|
return entladen
|
|
|
|
|
|
async def async_remove_entry(hass: HomeAssistant, entry: NinstripConfigEntry) -> None:
|
|
ir.async_delete_issue(hass, DOMAIN, f"wifi_guard_{entry.entry_id}")
|
|
|
|
|
|
# Kein add_update_listener zum Neuladen: der Einstellungsdialog ist ein
|
|
# OptionsFlowWithReload und laedt selbst neu. Beides zusammen weist Home
|
|
# Assistant seit 2026.x rundheraus ab ("Config entry update listeners should
|
|
# not be used with OptionsFlowWithReload") - gemerkt am 22.09.2026, als sich
|
|
# in ha-dev keine einzige Einstellung speichern liess.
|