Home Assistant Unofficial Reference 2024.12.1
util.py
Go to the documentation of this file.
1 """Support for Wireless Sensor Tags."""
2 
3 import logging
4 
5 from wirelesstagpy.sensortag import SensorTag
6 
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers import entity_registry as er
9 
10 from .const import DOMAIN
11 
12 _LOGGER = logging.getLogger(__name__)
13 
14 
16  hass: HomeAssistant, tag: SensorTag, domain: str, key: str
17 ) -> None:
18  """Migrate old unique id to new one with use of tag's uuid."""
19  registry = er.async_get(hass)
20  new_unique_id = f"{tag.uuid}_{key}"
21 
22  if registry.async_get_entity_id(domain, DOMAIN, new_unique_id):
23  return
24 
25  old_unique_id = f"{tag.tag_id}_{key}"
26  if entity_id := registry.async_get_entity_id(domain, DOMAIN, old_unique_id):
27  _LOGGER.debug("Updating unique id for %s %s", key, entity_id)
28  registry.async_update_entity(entity_id, new_unique_id=new_unique_id)
None async_migrate_unique_id(HomeAssistant hass, SensorTag tag, str domain, str key)
Definition: util.py:17