mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Migrate entity unique ids in PI-Hole (#90883)
* migrate entity unique ids * Update homeassistant/components/pi_hole/__init__.py --------- Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
b4fec762bc
commit
397fbc0e41
@ -16,9 +16,9 @@ from homeassistant.const import (
|
||||
CONF_VERIFY_SSL,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
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.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
@ -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)
|
||||
|
||||
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)
|
||||
api = Hole(
|
||||
host,
|
||||
|
Loading…
x
Reference in New Issue
Block a user