diff --git a/homeassistant/components/uptimerobot/coordinator.py b/homeassistant/components/uptimerobot/coordinator.py index 2f6225fa498..7ecb1ee3313 100644 --- a/homeassistant/components/uptimerobot/coordinator.py +++ b/homeassistant/components/uptimerobot/coordinator.py @@ -39,7 +39,6 @@ class UptimeRobotDataUpdateCoordinator(DataUpdateCoordinator[list[UptimeRobotMon name=DOMAIN, update_interval=COORDINATOR_UPDATE_INTERVAL, ) - self._device_registry = dr.async_get(hass) self.api = api async def _async_update_data(self) -> list[UptimeRobotMonitor]: @@ -56,23 +55,21 @@ class UptimeRobotDataUpdateCoordinator(DataUpdateCoordinator[list[UptimeRobotMon monitors: list[UptimeRobotMonitor] = response.data - current_monitors = { - list(device.identifiers)[0][1] - for device in dr.async_entries_for_config_entry( - self._device_registry, self.config_entry.entry_id - ) - } + current_monitors = ( + {str(monitor.id) for monitor in self.data} if self.data else set() + ) new_monitors = {str(monitor.id) for monitor in monitors} if stale_monitors := current_monitors - new_monitors: for monitor_id in stale_monitors: - if device := self._device_registry.async_get_device( + device_registry = dr.async_get(self.hass) + if device := device_registry.async_get_device( identifiers={(DOMAIN, monitor_id)} ): - self._device_registry.async_remove_device(device.id) + device_registry.async_remove_device(device.id) # If there are new monitors, we should reload the config entry so we can # create new devices and entities. - if self.data and new_monitors - {str(monitor.id) for monitor in self.data}: + if self.data and new_monitors - current_monitors: self.hass.async_create_task( self.hass.config_entries.async_reload(self.config_entry.entry_id) )