1919from homeassistant .exceptions import ConfigEntryNotReady
2020from homeassistant .helpers import config_validation as cv , issue_registry as ir
2121from homeassistant .helpers .dispatcher import async_dispatcher_send
22+ from homeassistant .helpers .entity_registry import RegistryEntry , async_migrate_entries
2223from homeassistant .helpers .typing import ConfigType
2324
2425from .const import (
@@ -257,10 +258,11 @@ async def async_migrate_entry(
257258 config_entry .minor_version ,
258259 )
259260
260- if config_entry .version > 1 :
261+ if config_entry .version > 2 :
261262 # This means the user has downgraded from a future version
262263 return False
263264
265+ # 1.2 Migrate subentries to include configured numbers to title
264266 if config_entry .version == 1 and config_entry .minor_version == 1 :
265267 for subentry in config_entry .subentries .values ():
266268 property_map = {
@@ -278,6 +280,21 @@ async def async_migrate_entry(
278280
279281 hass .config_entries .async_update_entry (config_entry , minor_version = 2 )
280282
283+ # 2.1 Migrate all entity unique IDs to replace "satel" prefix with config entry ID, allows multiple entries to be configured
284+ if config_entry .version == 1 :
285+
286+ @callback
287+ def migrate_unique_id (entity_entry : RegistryEntry ) -> dict [str , str ]:
288+ """Migrate the unique ID to a new format."""
289+ return {
290+ "new_unique_id" : entity_entry .unique_id .replace (
291+ "satel" , config_entry .entry_id
292+ )
293+ }
294+
295+ await async_migrate_entries (hass , config_entry .entry_id , migrate_unique_id )
296+ hass .config_entries .async_update_entry (config_entry , version = 2 , minor_version = 1 )
297+
281298 _LOGGER .debug (
282299 "Migration to configuration version %s.%s successful" ,
283300 config_entry .version ,
0 commit comments