From 1789f223fd92a067fef63d572f79678905cf5c67 Mon Sep 17 00:00:00 2001 From: Robert Bradley Date: Fri, 8 Nov 2024 06:44:42 +0000 Subject: [PATCH 1/2] fix: #975 adding routine to handle migration error --- custom_components/uk_bin_collection/__init__.py | 14 ++++++++++++++ custom_components/uk_bin_collection/config_flow.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/custom_components/uk_bin_collection/__init__.py b/custom_components/uk_bin_collection/__init__.py index 4901900e80..d4e538cdba 100644 --- a/custom_components/uk_bin_collection/__init__.py +++ b/custom_components/uk_bin_collection/__init__.py @@ -28,6 +28,20 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool: _LOGGER.debug(f"{LOG_PREFIX} async_setup called with config: {config}") return True +async def async_migrate_entry(self, config_entry) -> bool: + """Migrate old config entries to new version.""" + if config_entry.version == 1: + _LOGGER.info(f"{LOG_PREFIX} Migrating config entry {config_entry.entry_id} from version 1 to 2.") + + # Example: Add default update_interval if not present + data = config_entry.data.copy() + data.setdefault("update_interval", 12) + + self.hass.config_entries.async_update_entry(config_entry, data=data) + config_entry.version = 2 + + _LOGGER.info(f"{LOG_PREFIX} Migration of config entry {config_entry.entry_id} successful.") + return True async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry diff --git a/custom_components/uk_bin_collection/config_flow.py b/custom_components/uk_bin_collection/config_flow.py index eb4bfdfa17..109e198a42 100644 --- a/custom_components/uk_bin_collection/config_flow.py +++ b/custom_components/uk_bin_collection/config_flow.py @@ -18,7 +18,7 @@ class UkBinCollectionConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handle a config flow for UkBinCollection.""" - VERSION = 2 # Incremented version for config flow changes + VERSION = 1 # Incremented version for config flow changes def __init__(self): self.councils_data: Optional[Dict[str, Any]] = None From 7abf2310ae295acab5d4d90b287127215e0b93a0 Mon Sep 17 00:00:00 2001 From: Robert Bradley Date: Fri, 8 Nov 2024 06:45:30 +0000 Subject: [PATCH 2/2] fix: #975 adding routine to handle migration error --- custom_components/uk_bin_collection/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/uk_bin_collection/config_flow.py b/custom_components/uk_bin_collection/config_flow.py index 109e198a42..eb4bfdfa17 100644 --- a/custom_components/uk_bin_collection/config_flow.py +++ b/custom_components/uk_bin_collection/config_flow.py @@ -18,7 +18,7 @@ class UkBinCollectionConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handle a config flow for UkBinCollection.""" - VERSION = 1 # Incremented version for config flow changes + VERSION = 2 # Incremented version for config flow changes def __init__(self): self.councils_data: Optional[Dict[str, Any]] = None