hass-core/homeassistant/components/brother/coordinator.py
Maciej Bieniek 19eb51deeb
Move Brother DataUpdateCoordinator to the coordinator module (#116772)
* Store data in config_entry.runtime_data

* Update homeassistant/components/brother/__init__.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Fix setdefault

* Do not include ignored and disabled

* Check loaded entries

---------

Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-05-04 16:29:08 +02:00

37 lines
1.1 KiB
Python

"""Coordinator for Brother integration."""
from asyncio import timeout
import logging
from brother import Brother, BrotherSensors, SnmpError, UnsupportedModelError
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import DOMAIN, UPDATE_INTERVAL
_LOGGER = logging.getLogger(__name__)
class BrotherDataUpdateCoordinator(DataUpdateCoordinator[BrotherSensors]):
"""Class to manage fetching Brother data from the printer."""
def __init__(self, hass: HomeAssistant, brother: Brother) -> None:
"""Initialize."""
self.brother = brother
super().__init__(
hass,
_LOGGER,
name=DOMAIN,
update_interval=UPDATE_INTERVAL,
)
async def _async_update_data(self) -> BrotherSensors:
"""Update data via library."""
try:
async with timeout(20):
data = await self.brother.async_update()
except (ConnectionError, SnmpError, UnsupportedModelError) as error:
raise UpdateFailed(error) from error
return data