mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
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:
parent
babb1c5589
commit
8f1a0eadc0
@ -5,17 +5,14 @@ from __future__ import annotations
|
|||||||
from brother import Brother, SnmpError
|
from brother import Brother, SnmpError
|
||||||
|
|
||||||
from homeassistant.components.snmp import async_get_snmp_engine
|
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.const import CONF_HOST, CONF_TYPE, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
|
|
||||||
from .coordinator import BrotherDataUpdateCoordinator
|
from .coordinator import BrotherConfigEntry, BrotherDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [Platform.SENSOR]
|
PLATFORMS = [Platform.SENSOR]
|
||||||
|
|
||||||
type BrotherConfigEntry = ConfigEntry[BrotherDataUpdateCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: BrotherConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: BrotherConfigEntry) -> bool:
|
||||||
"""Set up Brother from a config entry."""
|
"""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:
|
except (ConnectionError, SnmpError, TimeoutError) as error:
|
||||||
raise ConfigEntryNotReady from error
|
raise ConfigEntryNotReady from error
|
||||||
|
|
||||||
coordinator = BrotherDataUpdateCoordinator(hass, brother)
|
coordinator = BrotherDataUpdateCoordinator(hass, entry, brother)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
entry.runtime_data = coordinator
|
entry.runtime_data = coordinator
|
||||||
|
@ -5,6 +5,7 @@ import logging
|
|||||||
|
|
||||||
from brother import Brother, BrotherSensors, SnmpError, UnsupportedModelError
|
from brother import Brother, BrotherSensors, SnmpError, UnsupportedModelError
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
@ -12,17 +13,24 @@ from .const import DOMAIN, UPDATE_INTERVAL
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type BrotherConfigEntry = ConfigEntry[BrotherDataUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class BrotherDataUpdateCoordinator(DataUpdateCoordinator[BrotherSensors]):
|
class BrotherDataUpdateCoordinator(DataUpdateCoordinator[BrotherSensors]):
|
||||||
"""Class to manage fetching Brother data from the printer."""
|
"""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."""
|
"""Initialize."""
|
||||||
self.brother = brother
|
self.brother = brother
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_interval=UPDATE_INTERVAL,
|
update_interval=UPDATE_INTERVAL,
|
||||||
)
|
)
|
||||||
|
@ -7,7 +7,7 @@ from typing import Any
|
|||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import BrotherConfigEntry
|
from .coordinator import BrotherConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
|
@ -24,8 +24,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from . import BrotherConfigEntry, BrotherDataUpdateCoordinator
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .coordinator import BrotherConfigEntry, BrotherDataUpdateCoordinator
|
||||||
|
|
||||||
ATTR_COUNTER = "counter"
|
ATTR_COUNTER = "counter"
|
||||||
ATTR_REMAINING_PAGES = "remaining_pages"
|
ATTR_REMAINING_PAGES = "remaining_pages"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user