mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Explicitly pass in the config_entry in uptimerobot coordinator (#137883)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
32d13f3356
commit
e698e436d6
@ -8,7 +8,6 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers import device_registry as dr
|
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from .const import DOMAIN, PLATFORMS
|
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"
|
"Wrong API key type detected, use the 'main' API key"
|
||||||
)
|
)
|
||||||
uptime_robot_api = UptimeRobot(key, async_get_clientsession(hass))
|
uptime_robot_api = UptimeRobot(key, async_get_clientsession(hass))
|
||||||
dev_reg = dr.async_get(hass)
|
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id] = coordinator = UptimeRobotDataUpdateCoordinator(
|
hass.data[DOMAIN][entry.entry_id] = coordinator = UptimeRobotDataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
config_entry_id=entry.entry_id,
|
entry,
|
||||||
dev_reg=dev_reg,
|
|
||||||
api=uptime_robot_api,
|
api=uptime_robot_api,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,19 +26,18 @@ class UptimeRobotDataUpdateCoordinator(DataUpdateCoordinator[list[UptimeRobotMon
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry_id: str,
|
config_entry: ConfigEntry,
|
||||||
dev_reg: dr.DeviceRegistry,
|
|
||||||
api: UptimeRobot,
|
api: UptimeRobot,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize coordinator."""
|
"""Initialize coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_interval=COORDINATOR_UPDATE_INTERVAL,
|
update_interval=COORDINATOR_UPDATE_INTERVAL,
|
||||||
)
|
)
|
||||||
self._config_entry_id = config_entry_id
|
self._device_registry = dr.async_get(hass)
|
||||||
self._device_registry = dev_reg
|
|
||||||
self.api = api
|
self.api = api
|
||||||
|
|
||||||
async def _async_update_data(self) -> list[UptimeRobotMonitor]:
|
async def _async_update_data(self) -> list[UptimeRobotMonitor]:
|
||||||
@ -58,7 +57,7 @@ class UptimeRobotDataUpdateCoordinator(DataUpdateCoordinator[list[UptimeRobotMon
|
|||||||
current_monitors = {
|
current_monitors = {
|
||||||
list(device.identifiers)[0][1]
|
list(device.identifiers)[0][1]
|
||||||
for device in dr.async_entries_for_config_entry(
|
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}
|
new_monitors = {str(monitor.id) for monitor in monitors}
|
||||||
@ -73,7 +72,7 @@ class UptimeRobotDataUpdateCoordinator(DataUpdateCoordinator[list[UptimeRobotMon
|
|||||||
# create new devices and entities.
|
# 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 - {str(monitor.id) for monitor in self.data}:
|
||||||
self.hass.async_create_task(
|
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
|
return monitors
|
||||||
|
Loading…
x
Reference in New Issue
Block a user