mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Explicitly pass in the config_entry in mikrotik coordinator (#138089)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
e1c222c54e
commit
de19f8550f
@ -1,19 +1,16 @@
|
||||
"""The Mikrotik component."""
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .const import ATTR_MANUFACTURER, DOMAIN
|
||||
from .coordinator import MikrotikDataUpdateCoordinator, get_api
|
||||
from .coordinator import MikrotikConfigEntry, MikrotikDataUpdateCoordinator, get_api
|
||||
from .errors import CannotConnect, LoginError
|
||||
|
||||
PLATFORMS = [Platform.DEVICE_TRACKER]
|
||||
|
||||
type MikrotikConfigEntry = ConfigEntry[MikrotikDataUpdateCoordinator]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, config_entry: MikrotikConfigEntry
|
||||
@ -47,6 +44,8 @@ async def async_setup_entry(
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant, config_entry: MikrotikConfigEntry
|
||||
) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|
||||
|
@ -45,6 +45,8 @@ from .errors import CannotConnect, LoginError
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type MikrotikConfigEntry = ConfigEntry[MikrotikDataUpdateCoordinator]
|
||||
|
||||
|
||||
class MikrotikData:
|
||||
"""Handle all communication with the Mikrotik API."""
|
||||
@ -246,17 +248,21 @@ class MikrotikData:
|
||||
class MikrotikDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||
"""Mikrotik Hub Object."""
|
||||
|
||||
config_entry: MikrotikConfigEntry
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, config_entry: ConfigEntry, api: librouteros.Api
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: MikrotikConfigEntry,
|
||||
api: librouteros.Api,
|
||||
) -> None:
|
||||
"""Initialize the Mikrotik Client."""
|
||||
self.hass = hass
|
||||
self.config_entry: ConfigEntry = config_entry
|
||||
self._mk_data = MikrotikData(self.hass, self.config_entry, api)
|
||||
self._mk_data = MikrotikData(hass, config_entry, api)
|
||||
super().__init__(
|
||||
self.hass,
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=f"{DOMAIN} - {self.host}",
|
||||
config_entry=config_entry,
|
||||
name=f"{DOMAIN} - {config_entry.data[CONF_HOST]}",
|
||||
update_interval=timedelta(seconds=10),
|
||||
)
|
||||
|
||||
|
@ -14,8 +14,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import MikrotikConfigEntry
|
||||
from .coordinator import Device, MikrotikDataUpdateCoordinator
|
||||
from .coordinator import Device, MikrotikConfigEntry, MikrotikDataUpdateCoordinator
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
Loading…
x
Reference in New Issue
Block a user