mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Update Tile unique ID to include username (#52175)
This commit is contained in:
parent
fbf85fd86b
commit
f538e07902
@ -7,7 +7,7 @@ from pytile.errors import InvalidAuthError, SessionExpiredError, TileError
|
|||||||
|
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client, entity_registry
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
from homeassistant.util.async_ import gather_with_concurrency
|
from homeassistant.util.async_ import gather_with_concurrency
|
||||||
|
|
||||||
@ -33,6 +33,31 @@ async def async_setup_entry(hass, entry):
|
|||||||
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id] = {}
|
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id] = {}
|
||||||
hass.data[DOMAIN][DATA_TILE][entry.entry_id] = {}
|
hass.data[DOMAIN][DATA_TILE][entry.entry_id] = {}
|
||||||
|
|
||||||
|
# The existence of shared Tiles across multiple accounts requires an entity ID
|
||||||
|
# change:
|
||||||
|
#
|
||||||
|
# Old: tile_{uuid}
|
||||||
|
# New: {username}_{uuid}
|
||||||
|
#
|
||||||
|
# Find any entities with the old format and update them:
|
||||||
|
ent_reg = entity_registry.async_get(hass)
|
||||||
|
for entity in [
|
||||||
|
e
|
||||||
|
for e in ent_reg.entities.values()
|
||||||
|
if e.config_entry_id == entry.entry_id
|
||||||
|
and not e.unique_id.startswith(entry.data[CONF_USERNAME])
|
||||||
|
]:
|
||||||
|
new_unique_id = f"{entry.data[CONF_USERNAME]}_".join(
|
||||||
|
entity.unique_id.split(f"{DOMAIN}_")
|
||||||
|
)
|
||||||
|
LOGGER.debug(
|
||||||
|
"Migrating entity %s from old unique ID '%s' to new unique ID '%s'",
|
||||||
|
entity.entity_id,
|
||||||
|
entity.unique_id,
|
||||||
|
new_unique_id,
|
||||||
|
)
|
||||||
|
ent_reg.async_update_entity(entity.entity_id, new_unique_id=new_unique_id)
|
||||||
|
|
||||||
websession = aiohttp_client.async_get_clientsession(hass)
|
websession = aiohttp_client.async_get_clientsession(hass)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -30,7 +30,9 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
TileDeviceTracker(
|
TileDeviceTracker(
|
||||||
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][tile_uuid], tile
|
entry,
|
||||||
|
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][tile_uuid],
|
||||||
|
tile,
|
||||||
)
|
)
|
||||||
for tile_uuid, tile in hass.data[DOMAIN][DATA_TILE][entry.entry_id].items()
|
for tile_uuid, tile in hass.data[DOMAIN][DATA_TILE][entry.entry_id].items()
|
||||||
]
|
]
|
||||||
@ -61,10 +63,11 @@ async def async_setup_scanner(hass, config, async_see, discovery_info=None):
|
|||||||
class TileDeviceTracker(CoordinatorEntity, TrackerEntity):
|
class TileDeviceTracker(CoordinatorEntity, TrackerEntity):
|
||||||
"""Representation of a network infrastructure device."""
|
"""Representation of a network infrastructure device."""
|
||||||
|
|
||||||
def __init__(self, coordinator, tile):
|
def __init__(self, entry, coordinator, tile):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
||||||
|
self._entry = entry
|
||||||
self._tile = tile
|
self._tile = tile
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -116,7 +119,7 @@ class TileDeviceTracker(CoordinatorEntity, TrackerEntity):
|
|||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the unique ID of the entity."""
|
"""Return the unique ID of the entity."""
|
||||||
return f"tile_{self._tile.uuid}"
|
return f"{self._entry.data[CONF_USERNAME]}_{self._tile.uuid}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_type(self):
|
def source_type(self):
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Tile",
|
"name": "Tile",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/tile",
|
"documentation": "https://www.home-assistant.io/integrations/tile",
|
||||||
"requirements": ["pytile==5.2.0"],
|
"requirements": ["pytile==5.2.2"],
|
||||||
"codeowners": ["@bachya"],
|
"codeowners": ["@bachya"],
|
||||||
"iot_class": "cloud_polling"
|
"iot_class": "cloud_polling"
|
||||||
}
|
}
|
||||||
|
@ -1918,7 +1918,7 @@ python_opendata_transport==0.2.1
|
|||||||
pythonegardia==1.0.40
|
pythonegardia==1.0.40
|
||||||
|
|
||||||
# homeassistant.components.tile
|
# homeassistant.components.tile
|
||||||
pytile==5.2.0
|
pytile==5.2.2
|
||||||
|
|
||||||
# homeassistant.components.touchline
|
# homeassistant.components.touchline
|
||||||
pytouchline==0.7
|
pytouchline==0.7
|
||||||
|
@ -1061,7 +1061,7 @@ python-velbus==2.1.2
|
|||||||
python_awair==0.2.1
|
python_awair==0.2.1
|
||||||
|
|
||||||
# homeassistant.components.tile
|
# homeassistant.components.tile
|
||||||
pytile==5.2.0
|
pytile==5.2.2
|
||||||
|
|
||||||
# homeassistant.components.traccar
|
# homeassistant.components.traccar
|
||||||
pytraccar==0.9.0
|
pytraccar==0.9.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user