hass-core/homeassistant/components/traccar_server/helpers.py
Joakim Sørensen 640463c559
Add Traccar server integration (#109002)
* Add Traccar server integration

* Add explination

* Update homeassistant/components/traccar_server/coordinator.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Add data_description

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-01-31 14:50:18 +01:00

23 lines
608 B
Python

"""Helper functions for the Traccar Server integration."""
from __future__ import annotations
from pytraccar import DeviceModel, GeofenceModel
def get_device(device_id: int, devices: list[DeviceModel]) -> DeviceModel | None:
"""Return the device."""
return next(
(dev for dev in devices if dev["id"] == device_id),
None,
)
def get_first_geofence(
geofences: list[GeofenceModel],
target: list[int],
) -> GeofenceModel | None:
"""Return the geofence."""
return next(
(geofence for geofence in geofences if geofence["id"] in target),
None,
)