Explicitly pass in the config_entry in uptimerobot coordinator (#137883)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-08 20:25:14 +01:00 committed by GitHub
parent 32d13f3356
commit e698e436d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 10 deletions

View File

@ -8,7 +8,6 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN, PLATFORMS
@ -24,12 +23,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"Wrong API key type detected, use the 'main' API key"
)
uptime_robot_api = UptimeRobot(key, async_get_clientsession(hass))
dev_reg = dr.async_get(hass)
hass.data[DOMAIN][entry.entry_id] = coordinator = UptimeRobotDataUpdateCoordinator(
hass,
config_entry_id=entry.entry_id,
dev_reg=dev_reg,
entry,
api=uptime_robot_api,
)

View File

@ -26,19 +26,18 @@ class UptimeRobotDataUpdateCoordinator(DataUpdateCoordinator[list[UptimeRobotMon
def __init__(
self,
hass: HomeAssistant,
config_entry_id: str,
dev_reg: dr.DeviceRegistry,
config_entry: ConfigEntry,
api: UptimeRobot,
) -> None:
"""Initialize coordinator."""
super().__init__(
hass,
LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=COORDINATOR_UPDATE_INTERVAL,
)
self._config_entry_id = config_entry_id
self._device_registry = dev_reg
self._device_registry = dr.async_get(hass)
self.api = api
async def _async_update_data(self) -> list[UptimeRobotMonitor]:
@ -58,7 +57,7 @@ class UptimeRobotDataUpdateCoordinator(DataUpdateCoordinator[list[UptimeRobotMon
current_monitors = {
list(device.identifiers)[0][1]
for device in dr.async_entries_for_config_entry(
self._device_registry, self._config_entry_id
self._device_registry, self.config_entry.entry_id
)
}
new_monitors = {str(monitor.id) for monitor in monitors}
@ -73,7 +72,7 @@ class UptimeRobotDataUpdateCoordinator(DataUpdateCoordinator[list[UptimeRobotMon
# create new devices and entities.
if self.data and new_monitors - {str(monitor.id) for monitor in self.data}:
self.hass.async_create_task(
self.hass.config_entries.async_reload(self._config_entry_id)
self.hass.config_entries.async_reload(self.config_entry.entry_id)
)
return monitors