fix: Einstellungen liessen sich gar nicht speichern
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.
This commit is contained in:
@@ -48,7 +48,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: NinstripConfigEntry) ->
|
|||||||
entry.runtime_data = coordinator
|
entry.runtime_data = coordinator
|
||||||
await async_start_catalog(hass, async_get_shared(hass))
|
await async_start_catalog(hass, async_get_shared(hass))
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
entry.async_on_unload(entry.add_update_listener(_async_options_updated))
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@@ -69,6 +68,8 @@ async def async_remove_entry(hass: HomeAssistant, entry: NinstripConfigEntry) ->
|
|||||||
ir.async_delete_issue(hass, DOMAIN, f"wifi_guard_{entry.entry_id}")
|
ir.async_delete_issue(hass, DOMAIN, f"wifi_guard_{entry.entry_id}")
|
||||||
|
|
||||||
|
|
||||||
async def _async_options_updated(hass: HomeAssistant, entry: NinstripConfigEntry) -> None:
|
# Kein add_update_listener zum Neuladen: der Einstellungsdialog ist ein
|
||||||
"""Eine geaenderte Abfragehaeufigkeit wirkt ohne Neustart."""
|
# OptionsFlowWithReload und laedt selbst neu. Beides zusammen weist Home
|
||||||
await hass.config_entries.async_reload(entry.entry_id)
|
# 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.
|
||||||
|
|||||||
+28
-1
@@ -6,11 +6,12 @@ from unittest.mock import MagicMock
|
|||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from pytest_homeassistant_custom_component.common import MockConfigEntry
|
from pytest_homeassistant_custom_component.common import MockConfigEntry
|
||||||
|
|
||||||
from custom_components.ninstrip.api import NinstripAuthError, NinstripConnectionError
|
from custom_components.ninstrip.api import NinstripAuthError, NinstripConnectionError
|
||||||
from custom_components.ninstrip.const import DOMAIN
|
from custom_components.ninstrip.const import CONF_DEVICE_BASE_URL, CONF_SCAN_INTERVAL, DOMAIN
|
||||||
from tests_unit.samples import MAC_K1Y
|
from tests_unit.samples import MAC_K1Y
|
||||||
|
|
||||||
|
|
||||||
@@ -57,3 +58,29 @@ async def test_abgelehntes_token_verlangt_neue_anmeldung(
|
|||||||
assert any(
|
assert any(
|
||||||
flow["context"]["source"] == "reauth" for flow in hass.config_entries.flow.async_progress()
|
flow["context"]["source"] == "reauth" for flow in hass.config_entries.flow.async_progress()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_einstellungen_lassen_sich_am_laufenden_eintrag_sichern(
|
||||||
|
hass: HomeAssistant, init_integration: MockConfigEntry
|
||||||
|
) -> None:
|
||||||
|
"""Am wirklich eingerichteten Eintrag - hier klemmte es.
|
||||||
|
|
||||||
|
Der Eintrag hatte zusaetzlich einen add_update_listener zum Neuladen, und
|
||||||
|
zusammen mit einem OptionsFlowWithReload weist Home Assistant das
|
||||||
|
Speichern rundheraus ab ("Config entry update listeners should not be used
|
||||||
|
with OptionsFlowWithReload"). In ha-dev liess sich dadurch keine einzige
|
||||||
|
Einstellung sichern. Die Tests in test_config_flow.py sehen das nicht:
|
||||||
|
dort ist async_setup_entry durchweg ersetzt, der Eintrag wird also nie
|
||||||
|
wirklich aufgesetzt und meldet auch keinen Listener an.
|
||||||
|
"""
|
||||||
|
ergebnis = await hass.config_entries.options.async_init(init_integration.entry_id)
|
||||||
|
ergebnis = await hass.config_entries.options.async_configure(
|
||||||
|
ergebnis["flow_id"],
|
||||||
|
{CONF_SCAN_INTERVAL: 45, CONF_DEVICE_BASE_URL: "http://192.168.1.131:8124"},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert ergebnis["type"] is FlowResultType.CREATE_ENTRY
|
||||||
|
assert init_integration.options == {
|
||||||
|
CONF_SCAN_INTERVAL: 45,
|
||||||
|
CONF_DEVICE_BASE_URL: "http://192.168.1.131:8124",
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user