mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Remove global registry reference in coordinator for UptimeRobot (#142938)
* Remove global registry reference in coordinator for UptimeRobot * rework current_monitors listing * fix logic
This commit is contained in:
parent
13d530d110
commit
535d128f8a
@ -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)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user