|
13 | 13 | )
|
14 | 14 | from homeassistant.helpers import selector
|
15 | 15 | from homeassistant.helpers.template import as_datetime
|
| 16 | +from homeassistant.helpers.entity_registry import async_migrate_entries, RegistryEntry |
| 17 | +from homeassistant.core import callback |
16 | 18 |
|
17 | 19 | from myPyllant import export, report
|
18 | 20 |
|
@@ -58,21 +60,28 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
58 | 60 |
|
59 | 61 | if config_entry.version == 1:
|
60 | 62 | """
|
61 |
| - from homeassistant.helpers.entity_registry import async_migrate_entries, RegistryEntry |
62 | 63 | from homeassistant.helpers.device_registry import async_entries_for_config_entry
|
63 |
| - from homeassistant.core import callback |
64 | 64 |
|
65 | 65 | devices = async_entries_for_config_entry(
|
66 | 66 | hass.data["device_registry"], config_entry.entry_id
|
67 | 67 | )
|
| 68 | + """ |
68 | 69 |
|
69 | 70 | @callback
|
70 | 71 | 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 |
72 | 82 |
|
73 | 83 | 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 |
76 | 85 |
|
77 | 86 | _LOGGER.debug("Migration to version %s successful", config_entry.version)
|
78 | 87 | return True
|
|
0 commit comments