2323DATA_PRIVILEGED_KEY : HassKey [bool | None ] = HassKey (DOMAIN )
2424
2525
26+ async def async_migrate_entry (hass : HomeAssistant , entry : PingConfigEntry ) -> bool :
27+ """Migrate old config entries."""
28+ if entry .version == 1 and entry .minor_version == 1 :
29+ _LOGGER .debug ("Migrating to minor version 2" )
30+
31+ # Migrate device registry identifiers from homeassistant domain to ping domain
32+ registry = dr .async_get (hass )
33+ if (
34+ device := registry .async_get_device (
35+ identifiers = {(HOMEASSISTANT_DOMAIN , entry .entry_id )}
36+ )
37+ ) is not None and entry .entry_id in device .config_entries :
38+ registry .async_update_device (
39+ device_id = device .id ,
40+ new_identifiers = {(DOMAIN , entry .entry_id )},
41+ )
42+
43+ hass .config_entries .async_update_entry (entry , minor_version = 2 )
44+
45+ return True
46+
47+
2648async def async_setup (hass : HomeAssistant , config : ConfigType ) -> bool :
2749 """Set up the ping integration."""
2850 hass .data [DATA_PRIVILEGED_KEY ] = await _can_use_icmp_lib_with_privilege ()
@@ -32,19 +54,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
3254
3355async def async_setup_entry (hass : HomeAssistant , entry : PingConfigEntry ) -> bool :
3456 """Set up Ping (ICMP) from a config entry."""
35-
36- # Migrate device registry identifiers from homeassistant domain to ping domain
37- registry = dr .async_get (hass )
38- if (
39- device := registry .async_get_device (
40- identifiers = {(HOMEASSISTANT_DOMAIN , entry .entry_id )}
41- )
42- ) is not None and entry .entry_id in device .config_entries :
43- registry .async_update_device (
44- device_id = device .id ,
45- new_identifiers = {(DOMAIN , entry .entry_id )},
46- )
47-
4857 privileged = hass .data [DATA_PRIVILEGED_KEY ]
4958
5059 host : str = entry .options [CONF_HOST ]
0 commit comments