Skip to content
Snippets Groups Projects
Unverified Commit 397fbc0e authored by Michael's avatar Michael Committed by GitHub
Browse files

Migrate entity unique ids in PI-Hole (#90883)


* migrate entity unique ids

* Update homeassistant/components/pi_hole/__init__.py

---------

Co-authored-by: default avatarPaulus Schoutsen <paulus@home-assistant.io>
parent b4fec762
No related branches found
No related tags found
No related merge requests found
...@@ -16,9 +16,9 @@ from homeassistant.const import ( ...@@ -16,9 +16,9 @@ from homeassistant.const import (
CONF_VERIFY_SSL, CONF_VERIFY_SSL,
Platform, Platform,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv, entity_registry as er
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import (
...@@ -64,6 +64,38 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ...@@ -64,6 +64,38 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
_LOGGER.debug("Setting up %s integration with host %s", DOMAIN, host) _LOGGER.debug("Setting up %s integration with host %s", DOMAIN, host)
name_to_key = {
"Core Update Available": "core_update_available",
"Web Update Available": "web_update_available",
"FTL Update Available": "ftl_update_available",
"Status": "status",
"Ads Blocked Today": "ads_blocked_today",
"Ads Percentage Blocked Today": "ads_percentage_today",
"Seen Clients": "clients_ever_seen",
"DNS Queries Today": "dns_queries_today",
"Domains Blocked": "domains_being_blocked",
"DNS Queries Cached": "queries_cached",
"DNS Queries Forwarded": "queries_forwarded",
"DNS Unique Clients": "unique_clients",
"DNS Unique Domains": "unique_domains",
}
@callback
def update_unique_id(
entity_entry: er.RegistryEntry,
) -> dict[str, str] | None:
"""Update unique ID of entity entry."""
unique_id_parts = entity_entry.unique_id.split("/")
if len(unique_id_parts) == 2 and unique_id_parts[1] in name_to_key:
name = unique_id_parts[1]
new_unique_id = entity_entry.unique_id.replace(name, name_to_key[name])
_LOGGER.debug("Migrate %s to %s", entity_entry.unique_id, new_unique_id)
return {"new_unique_id": new_unique_id}
return None
await er.async_migrate_entries(hass, entry.entry_id, update_unique_id)
session = async_get_clientsession(hass, verify_tls) session = async_get_clientsession(hass, verify_tls)
api = Hole( api = Hole(
host, host,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment