Explicitly pass in the config_entry in traccar_server coordinator (#137893)

explicitly pass in the config_entry in coordinator
pull/138060/head
Michael 2025-02-09 14:26:39 +01:00 committed by GitHub
parent 7986e0fec1
commit 8a7ee039d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 21 deletions

View File

@ -21,13 +21,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from homeassistant.helpers.event import async_track_time_interval
from .const import (
CONF_CUSTOM_ATTRIBUTES,
CONF_EVENTS,
CONF_MAX_ACCURACY,
CONF_SKIP_ACCURACY_FILTER_FOR,
DOMAIN,
)
from .const import CONF_EVENTS, DOMAIN
from .coordinator import TraccarServerCoordinator
PLATFORMS: list[Platform] = [
@ -47,6 +41,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
coordinator = TraccarServerCoordinator(
hass=hass,
config_entry=entry,
client=ApiClient(
client_session=client_session,
host=entry.data[CONF_HOST],
@ -56,10 +51,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
ssl=entry.data[CONF_SSL],
verify_ssl=entry.data[CONF_VERIFY_SSL],
),
events=entry.options.get(CONF_EVENTS, []),
max_accuracy=entry.options.get(CONF_MAX_ACCURACY, 0.0),
skip_accuracy_filter_for=entry.options.get(CONF_SKIP_ACCURACY_FILTER_FOR, []),
custom_attributes=entry.options.get(CONF_CUSTOM_ATTRIBUTES, []),
)
await coordinator.async_config_entry_first_refresh()

View File

@ -22,7 +22,15 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.util import dt as dt_util
from .const import DOMAIN, EVENTS, LOGGER
from .const import (
CONF_CUSTOM_ATTRIBUTES,
CONF_EVENTS,
CONF_MAX_ACCURACY,
CONF_SKIP_ACCURACY_FILTER_FOR,
DOMAIN,
EVENTS,
LOGGER,
)
from .helpers import get_device, get_first_geofence
@ -46,25 +54,24 @@ class TraccarServerCoordinator(DataUpdateCoordinator[TraccarServerCoordinatorDat
def __init__(
self,
hass: HomeAssistant,
config_entry: ConfigEntry,
client: ApiClient,
*,
events: list[str],
max_accuracy: float,
skip_accuracy_filter_for: list[str],
custom_attributes: list[str],
) -> None:
"""Initialize global Traccar Server data updater."""
super().__init__(
hass=hass,
logger=LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=None,
)
self.client = client
self.custom_attributes = custom_attributes
self.events = events
self.max_accuracy = max_accuracy
self.skip_accuracy_filter_for = skip_accuracy_filter_for
self.custom_attributes = config_entry.options.get(CONF_CUSTOM_ATTRIBUTES, [])
self.events = config_entry.options.get(CONF_EVENTS, [])
self.max_accuracy = config_entry.options.get(CONF_MAX_ACCURACY, 0.0)
self.skip_accuracy_filter_for = config_entry.options.get(
CONF_SKIP_ACCURACY_FILTER_FOR, []
)
self._geofences: list[GeofenceModel] = []
self._last_event_import: datetime | None = None
self._should_log_subscription_error: bool = True