1919from homeassistant .const import CONF_API_KEY , CONF_URL , CONF_VERIFY_SSL
2020from homeassistant .core import HomeAssistant , callback
2121from homeassistant .exceptions import ConfigEntryAuthFailed
22- from homeassistant .helpers import entity_registry as er
22+ from homeassistant .helpers import device_registry as dr , entity_registry as er
2323from homeassistant .helpers .aiohttp_client import async_get_clientsession
2424from homeassistant .helpers .update_coordinator import DataUpdateCoordinator , UpdateFailed
2525
@@ -89,7 +89,8 @@ def async_migrate_entities_unique_ids(
8989 """Migrate unique_ids in the entity registry after updating Uptime Kuma."""
9090
9191 if (
92- coordinator .version is coordinator .api .version
92+ coordinator .version is None
93+ or coordinator .version .version == coordinator .api .version .version
9394 or int (coordinator .api .version .major ) < 2
9495 ):
9596 return
@@ -116,6 +117,32 @@ def async_migrate_entities_unique_ids(
116117 new_unique_id = f"{ registry_entry .config_entry_id } _{ monitor .monitor_id !s} _{ registry_entry .translation_key } " ,
117118 )
118119
120+ # migrate device identifiers and update version
121+ device_reg = dr .async_get (hass )
122+ for monitor in metrics .values ():
123+ if device := device_reg .async_get_device (
124+ {(DOMAIN , f"{ coordinator .config_entry .entry_id } _{ monitor .monitor_name !s} " )}
125+ ):
126+ new_identifier = {
127+ (DOMAIN , f"{ coordinator .config_entry .entry_id } _{ monitor .monitor_id !s} " )
128+ }
129+ device_reg .async_update_device (
130+ device .id ,
131+ new_identifiers = new_identifier ,
132+ sw_version = coordinator .api .version .version ,
133+ )
134+ if device := device_reg .async_get_device (
135+ {(DOMAIN , f"{ coordinator .config_entry .entry_id } _update" )}
136+ ):
137+ device_reg .async_update_device (
138+ device .id ,
139+ sw_version = coordinator .api .version .version ,
140+ )
141+
142+ hass .async_create_task (
143+ hass .config_entries .async_reload (coordinator .config_entry .entry_id )
144+ )
145+
119146
120147class UptimeKumaSoftwareUpdateCoordinator (DataUpdateCoordinator [LatestRelease ]):
121148 """Uptime Kuma coordinator for retrieving update information."""
0 commit comments