Use first refresh method from data update coordinator in PI-Hole integration (#84453)

This commit is contained in:
Michael 2022-12-22 19:33:23 +01:00 committed by GitHub
parent 2e195d848f
commit 20b5e92656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,7 +18,6 @@ from homeassistant.const import (
Platform, Platform,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
@ -99,21 +98,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
_LOGGER.debug("Setting up %s integration with host %s", DOMAIN, host) _LOGGER.debug("Setting up %s integration with host %s", DOMAIN, host)
try: session = async_get_clientsession(hass, verify_tls)
session = async_get_clientsession(hass, verify_tls) api = Hole(
api = Hole( host,
host, session,
session, location=location,
location=location, tls=use_tls,
tls=use_tls, api_token=api_key,
api_token=api_key, )
)
await api.get_data()
await api.get_versions()
except HoleError as ex:
_LOGGER.warning("Failed to connect: %s", ex)
raise ConfigEntryNotReady from ex
async def async_update_data() -> None: async def async_update_data() -> None:
"""Fetch data from API endpoint.""" """Fetch data from API endpoint."""
@ -135,6 +127,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
DATA_KEY_COORDINATOR: coordinator, DATA_KEY_COORDINATOR: coordinator,
} }
await coordinator.async_config_entry_first_refresh()
await hass.config_entries.async_forward_entry_setups(entry, _async_platforms(entry)) await hass.config_entries.async_forward_entry_setups(entry, _async_platforms(entry))
return True return True