From 7af62c35f505837966dc9af78730dcbf22d1727a Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Wed, 20 Sep 2023 08:59:49 +0200 Subject: [PATCH] Move faa_delays coordinator to its own file (#100548) --- .coveragerc | 1 + .../components/faa_delays/__init__.py | 33 +---------------- .../components/faa_delays/coordinator.py | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 homeassistant/components/faa_delays/coordinator.py diff --git a/.coveragerc b/.coveragerc index 2a75526e63a..ac08240fd0f 100644 --- a/.coveragerc +++ b/.coveragerc @@ -357,6 +357,7 @@ omit = homeassistant/components/ezviz/update.py homeassistant/components/faa_delays/__init__.py homeassistant/components/faa_delays/binary_sensor.py + homeassistant/components/faa_delays/coordinator.py homeassistant/components/familyhub/camera.py homeassistant/components/fastdotcom/* homeassistant/components/ffmpeg/camera.py diff --git a/homeassistant/components/faa_delays/__init__.py b/homeassistant/components/faa_delays/__init__.py index b165492d076..3606da33499 100644 --- a/homeassistant/components/faa_delays/__init__.py +++ b/homeassistant/components/faa_delays/__init__.py @@ -1,20 +1,10 @@ """The FAA Delays integration.""" -import asyncio -from datetime import timedelta -import logging - -from aiohttp import ClientConnectionError -from faadelays import Airport - from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ID, Platform from homeassistant.core import HomeAssistant -from homeassistant.helpers import aiohttp_client -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import DOMAIN - -_LOGGER = logging.getLogger(__name__) +from .coordinator import FAADataUpdateCoordinator PLATFORMS = [Platform.BINARY_SENSOR] @@ -40,24 +30,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) return unload_ok - - -class FAADataUpdateCoordinator(DataUpdateCoordinator): - """Class to manage fetching FAA API data from a single endpoint.""" - - def __init__(self, hass, code): - """Initialize the coordinator.""" - super().__init__( - hass, _LOGGER, name=DOMAIN, update_interval=timedelta(minutes=1) - ) - self.session = aiohttp_client.async_get_clientsession(hass) - self.data = Airport(code, self.session) - self.code = code - - async def _async_update_data(self): - try: - async with asyncio.timeout(10): - await self.data.update() - except ClientConnectionError as err: - raise UpdateFailed(err) from err - return self.data diff --git a/homeassistant/components/faa_delays/coordinator.py b/homeassistant/components/faa_delays/coordinator.py new file mode 100644 index 00000000000..f2aefdada66 --- /dev/null +++ b/homeassistant/components/faa_delays/coordinator.py @@ -0,0 +1,35 @@ +"""DataUpdateCoordinator for faa_delays integration.""" +import asyncio +from datetime import timedelta +import logging + +from aiohttp import ClientConnectionError +from faadelays import Airport + +from homeassistant.helpers import aiohttp_client +from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed + +from .const import DOMAIN + +_LOGGER = logging.getLogger(__name__) + + +class FAADataUpdateCoordinator(DataUpdateCoordinator): + """Class to manage fetching FAA API data from a single endpoint.""" + + def __init__(self, hass, code): + """Initialize the coordinator.""" + super().__init__( + hass, _LOGGER, name=DOMAIN, update_interval=timedelta(minutes=1) + ) + self.session = aiohttp_client.async_get_clientsession(hass) + self.data = Airport(code, self.session) + self.code = code + + async def _async_update_data(self): + try: + async with asyncio.timeout(10): + await self.data.update() + except ClientConnectionError as err: + raise UpdateFailed(err) from err + return self.data