diff --git a/custom_components/ninstrip/__init__.py b/custom_components/ninstrip/__init__.py index 6838130..7ff2c0d 100644 --- a/custom_components/ninstrip/__init__.py +++ b/custom_components/ninstrip/__init__.py @@ -48,7 +48,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: NinstripConfigEntry) -> entry.runtime_data = coordinator await async_start_catalog(hass, async_get_shared(hass)) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) - entry.async_on_unload(entry.add_update_listener(_async_options_updated)) 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}") -async def _async_options_updated(hass: HomeAssistant, entry: NinstripConfigEntry) -> None: - """Eine geaenderte Abfragehaeufigkeit wirkt ohne Neustart.""" - await hass.config_entries.async_reload(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. diff --git a/tests/test_init.py b/tests/test_init.py index 0539d22..728796b 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -6,11 +6,12 @@ from unittest.mock import MagicMock from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant +from homeassistant.data_entry_flow import FlowResultType from homeassistant.helpers import device_registry as dr from pytest_homeassistant_custom_component.common import MockConfigEntry 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 @@ -57,3 +58,29 @@ async def test_abgelehntes_token_verlangt_neue_anmeldung( assert any( 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", + }