Pass in the config_entry in brother coordinator init (#137726)

explicitly pass in the config_entry in brother coordinator init
This commit is contained in:
Michael 2025-02-07 19:52:13 +01:00 committed by GitHub
parent babb1c5589
commit 8f1a0eadc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 8 deletions

View File

@ -5,17 +5,14 @@ from __future__ import annotations
from brother import Brother, SnmpError
from homeassistant.components.snmp import async_get_snmp_engine
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_TYPE, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from .coordinator import BrotherDataUpdateCoordinator
from .coordinator import BrotherConfigEntry, BrotherDataUpdateCoordinator
PLATFORMS = [Platform.SENSOR]
type BrotherConfigEntry = ConfigEntry[BrotherDataUpdateCoordinator]
async def async_setup_entry(hass: HomeAssistant, entry: BrotherConfigEntry) -> bool:
"""Set up Brother from a config entry."""
@ -30,7 +27,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: BrotherConfigEntry) -> b
except (ConnectionError, SnmpError, TimeoutError) as error:
raise ConfigEntryNotReady from error
coordinator = BrotherDataUpdateCoordinator(hass, brother)
coordinator = BrotherDataUpdateCoordinator(hass, entry, brother)
await coordinator.async_config_entry_first_refresh()
entry.runtime_data = coordinator

View File

@ -5,6 +5,7 @@ import logging
from brother import Brother, BrotherSensors, SnmpError, UnsupportedModelError
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
@ -12,17 +13,24 @@ from .const import DOMAIN, UPDATE_INTERVAL
_LOGGER = logging.getLogger(__name__)
type BrotherConfigEntry = ConfigEntry[BrotherDataUpdateCoordinator]
class BrotherDataUpdateCoordinator(DataUpdateCoordinator[BrotherSensors]):
"""Class to manage fetching Brother data from the printer."""
def __init__(self, hass: HomeAssistant, brother: Brother) -> None:
config_entry: BrotherConfigEntry
def __init__(
self, hass: HomeAssistant, config_entry: BrotherConfigEntry, brother: Brother
) -> None:
"""Initialize."""
self.brother = brother
super().__init__(
hass,
_LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=UPDATE_INTERVAL,
)

View File

@ -7,7 +7,7 @@ from typing import Any
from homeassistant.core import HomeAssistant
from . import BrotherConfigEntry
from .coordinator import BrotherConfigEntry
async def async_get_config_entry_diagnostics(

View File

@ -24,8 +24,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import BrotherConfigEntry, BrotherDataUpdateCoordinator
from .const import DOMAIN
from .coordinator import BrotherConfigEntry, BrotherDataUpdateCoordinator
ATTR_COUNTER = "counter"
ATTR_REMAINING_PAGES = "remaining_pages"