From 8a7ee039d1276bbc8b6b59d1325b197b5def3c1b Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Sun, 9 Feb 2025 14:26:39 +0100 Subject: [PATCH] Explicitly pass in the config_entry in traccar_server coordinator (#137893) explicitly pass in the config_entry in coordinator --- .../components/traccar_server/__init__.py | 13 ++------- .../components/traccar_server/coordinator.py | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/traccar_server/__init__.py b/homeassistant/components/traccar_server/__init__.py index c7a65d2d4a8..44aeedc3376 100644 --- a/homeassistant/components/traccar_server/__init__.py +++ b/homeassistant/components/traccar_server/__init__.py @@ -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() diff --git a/homeassistant/components/traccar_server/coordinator.py b/homeassistant/components/traccar_server/coordinator.py index 95ce42469f1..2c878856cc2 100644 --- a/homeassistant/components/traccar_server/coordinator.py +++ b/homeassistant/components/traccar_server/coordinator.py @@ -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