mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-10-27 16:10:49 +08:00
fix: migrate the unique_id of the service entities (#1778)
The description of the service was appended to the unique_id of the service entities without a migration step, so the entities registered before that change were replaced by new ones. The entity_id of the new entity is different, which silently breaks every automation, script and dashboard referring to the old one. Look up the entities that are still registered under the old unique_id when the entry is set up, and rewrite it in place. The entity_id is left untouched, so nothing referring to it has to be updated. The lookup is keyed on the unique_id only and scoped to the config entry, and nothing is written when the current unique_id is already registered, so it is idempotent and cannot replace an entity that is in use. An entity that cannot be migrated is reported and skipped, the others are still migrated. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -380,6 +380,18 @@ class MIoTDevice:
|
||||
f'{ha_domain}.{self._model_strs[0][:9]}_{self.did_tag}_'
|
||||
f'{self._model_strs[-1][:20]}_s_{siid}_{description}')
|
||||
|
||||
def gen_service_entity_id_legacy(
|
||||
self, ha_domain: str, siid: int
|
||||
) -> list[str]:
|
||||
"""Return the service entity ids generated by previous versions.
|
||||
|
||||
The description of the service was appended to the id, an entity
|
||||
registered before that change is still stored under the id without it.
|
||||
"""
|
||||
return [
|
||||
f'{ha_domain}.{self._model_strs[0][:9]}_{self.did_tag}_'
|
||||
f'{self._model_strs[-1][:20]}_s_{siid}']
|
||||
|
||||
def gen_prop_entity_id(
|
||||
self, ha_domain: str, spec_name: str, siid: int, piid: int
|
||||
) -> str:
|
||||
|
||||
Reference in New Issue
Block a user