From d22b234f68003f9159981ac561f123f98efaf6b0 Mon Sep 17 00:00:00 2001 From: thekiwismarthome <134335563+thekiwismarthome@users.noreply.github.com> Date: Fri, 13 Feb 2026 21:38:33 +1300 Subject: [PATCH] Update __init__.py --- .../shopping_list_manager/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/custom_components/shopping_list_manager/__init__.py b/custom_components/shopping_list_manager/__init__.py index 7318487..50aae81 100644 --- a/custom_components/shopping_list_manager/__init__.py +++ b/custom_components/shopping_list_manager/__init__.py @@ -32,8 +32,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: component_path = os.path.dirname(__file__) config_path = hass.config.path() - # Get country from config entry (defaults to NZ) - country = entry.data.get("country", "NZ") + # Get country from options (or fall back to data, or default to NZ) + country = entry.options.get("country") or entry.data.get("country", "NZ") _LOGGER.info("Using country: %s", country) # Initialize storage with country @@ -47,7 +47,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][DATA_STORAGE] = storage hass.data[DOMAIN]["image_handler"] = image_handler - hass.data[DOMAIN]["country"] = country # Store for later use + hass.data[DOMAIN]["country"] = country + + # Register update listener for options changes + entry.async_on_unload(entry.add_update_listener(update_listener)) # Register WebSocket commands await _async_register_websocket_handlers(hass, storage) @@ -59,6 +62,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return True +async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None: + """Handle options update.""" + # Reload the integration when options change + await hass.config_entries.async_reload(entry.entry_id) + + async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" _LOGGER.info("Unloading Shopping List Manager")