Skip to content

Commit 03b74eb

Browse files
committed
fix: migrate change unique_id
1 parent 020c74e commit 03b74eb

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

custom_components/mypyllant/__init__.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
)
1414
from homeassistant.helpers import selector
1515
from homeassistant.helpers.template import as_datetime
16+
from homeassistant.helpers.entity_registry import async_migrate_entries, RegistryEntry
17+
from homeassistant.core import callback
1618

1719
from myPyllant import export, report
1820

@@ -58,21 +60,28 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
5860

5961
if config_entry.version == 1:
6062
"""
61-
from homeassistant.helpers.entity_registry import async_migrate_entries, RegistryEntry
6263
from homeassistant.helpers.device_registry import async_entries_for_config_entry
63-
from homeassistant.core import callback
6464
6565
devices = async_entries_for_config_entry(
6666
hass.data["device_registry"], config_entry.entry_id
6767
)
68+
"""
6869

6970
@callback
7071
def update_unique_id(entity_entry: RegistryEntry):
71-
return {"new_unique_id": entity_entry.unique_id} # change entity_entry.unique_id
72+
# All entities which are bound to system needs to be starting with {system_id}_home
73+
if entity_entry.unique_id.count(
74+
"_"
75+
) == 4 and entity_entry.unique_id.endswith("_heating_energy_efficiency"):
76+
return {
77+
"new_unique_id": entity_entry.unique_id.replace(
78+
"_heating_energy_efficiency", "_home_heating_energy_efficiency"
79+
)
80+
}
81+
return None
7282

7383
await async_migrate_entries(hass, config_entry.entry_id, update_unique_id)
74-
config_entry.version = 2 # set to new version
75-
"""
84+
config_entry.version = 2 # set to new version
7685

7786
_LOGGER.debug("Migration to version %s successful", config_entry.version)
7887
return True

custom_components/mypyllant/config_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async def async_step_init(
160160

161161

162162
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # type: ignore
163-
VERSION = 1 # This needs to be changed if a migration is necessary
163+
VERSION = 2 # This needs to be changed if a migration is necessary
164164
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL
165165

166166
@staticmethod

0 commit comments

Comments
 (0)