Update __init__.py

This commit is contained in:
thekiwismarthome
2026-02-13 21:38:33 +13:00
committed by GitHub
parent b4ea6bc7f0
commit d22b234f68
@@ -32,8 +32,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
component_path = os.path.dirname(__file__) component_path = os.path.dirname(__file__)
config_path = hass.config.path() config_path = hass.config.path()
# Get country from config entry (defaults to NZ) # Get country from options (or fall back to data, or default to NZ)
country = entry.data.get("country", "NZ") country = entry.options.get("country") or entry.data.get("country", "NZ")
_LOGGER.info("Using country: %s", country) _LOGGER.info("Using country: %s", country)
# Initialize storage with 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.setdefault(DOMAIN, {})
hass.data[DOMAIN][DATA_STORAGE] = storage hass.data[DOMAIN][DATA_STORAGE] = storage
hass.data[DOMAIN]["image_handler"] = image_handler 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 # Register WebSocket commands
await _async_register_websocket_handlers(hass, storage) await _async_register_websocket_handlers(hass, storage)
@@ -59,6 +62,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True 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: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry.""" """Unload a config entry."""
_LOGGER.info("Unloading Shopping List Manager") _LOGGER.info("Unloading Shopping List Manager")