From 4778c55d2bb9a256054de2ddfbcab6a2da1a1db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 3 Nov 2023 18:09:56 +0100 Subject: [PATCH] Bump pytraccar from 1.0.0 to 2.0.0 (#103318) --- .../components/traccar/device_tracker.py | 53 ++++++++++--------- .../components/traccar/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/traccar/device_tracker.py b/homeassistant/components/traccar/device_tracker.py index f1236a66700..3406997fd98 100644 --- a/homeassistant/components/traccar/device_tracker.py +++ b/homeassistant/components/traccar/device_tracker.py @@ -274,7 +274,8 @@ class TraccarScanner: """Import device data from Traccar.""" for position in self._positions: device = next( - (dev for dev in self._devices if dev.id == position.device_id), None + (dev for dev in self._devices if dev["id"] == position["deviceId"]), + None, ) if not device: @@ -282,36 +283,36 @@ class TraccarScanner: attr = { ATTR_TRACKER: "traccar", - ATTR_ADDRESS: position.address, - ATTR_SPEED: position.speed, - ATTR_ALTITUDE: position.altitude, - ATTR_MOTION: position.attributes.get("motion", False), - ATTR_TRACCAR_ID: device.id, + ATTR_ADDRESS: position["address"], + ATTR_SPEED: position["speed"], + ATTR_ALTITUDE: position["altitude"], + ATTR_MOTION: position["attributes"].get("motion", False), + ATTR_TRACCAR_ID: device["id"], ATTR_GEOFENCE: next( ( - geofence.name + geofence["name"] for geofence in self._geofences - if geofence.id in (device.geofence_ids or []) + if geofence["id"] in (position["geofenceIds"] or []) ), None, ), - ATTR_CATEGORY: device.category, - ATTR_STATUS: device.status, + ATTR_CATEGORY: device["category"], + ATTR_STATUS: device["status"], } skip_accuracy_filter = False for custom_attr in self._custom_attributes: - if device.attributes.get(custom_attr) is not None: - attr[custom_attr] = position.attributes[custom_attr] + if device["attributes"].get(custom_attr) is not None: + attr[custom_attr] = position["attributes"][custom_attr] if custom_attr in self._skip_accuracy_on: skip_accuracy_filter = True - if position.attributes.get(custom_attr) is not None: - attr[custom_attr] = position.attributes[custom_attr] + if position["attributes"].get(custom_attr) is not None: + attr[custom_attr] = position["attributes"][custom_attr] if custom_attr in self._skip_accuracy_on: skip_accuracy_filter = True - accuracy = position.accuracy or 0.0 + accuracy = position["accuracy"] or 0.0 if ( not skip_accuracy_filter and self._max_accuracy > 0 @@ -325,10 +326,10 @@ class TraccarScanner: continue await self._async_see( - dev_id=slugify(device.name), - gps=(position.latitude, position.longitude), + dev_id=slugify(device["name"]), + gps=(position["latitude"], position["longitude"]), gps_accuracy=accuracy, - battery=position.attributes.get("batteryLevel", -1), + battery=position["attributes"].get("batteryLevel", -1), attributes=attr, ) @@ -337,7 +338,7 @@ class TraccarScanner: # get_reports_events requires naive UTC datetimes as of 1.0.0 start_intervel = dt_util.utcnow().replace(tzinfo=None) events = await self._api.get_reports_events( - devices=[device.id for device in self._devices], + devices=[device["id"] for device in self._devices], start_time=start_intervel, end_time=start_intervel - self._scan_interval, event_types=self._event_types.keys(), @@ -345,20 +346,20 @@ class TraccarScanner: if events is not None: for event in events: self._hass.bus.async_fire( - f"traccar_{self._event_types.get(event.type)}", + f"traccar_{self._event_types.get(event['type'])}", { - "device_traccar_id": event.device_id, + "device_traccar_id": event["deviceId"], "device_name": next( ( - dev.name + dev["name"] for dev in self._devices - if dev.id == event.device_id + if dev["id"] == event["deviceId"] ), None, ), - "type": event.type, - "serverTime": event.event_time, - "attributes": event.attributes, + "type": event["type"], + "serverTime": event["eventTime"], + "attributes": event["attributes"], }, ) diff --git a/homeassistant/components/traccar/manifest.json b/homeassistant/components/traccar/manifest.json index 1c2cda69ffe..403ba3987ab 100644 --- a/homeassistant/components/traccar/manifest.json +++ b/homeassistant/components/traccar/manifest.json @@ -7,5 +7,5 @@ "documentation": "https://www.home-assistant.io/integrations/traccar", "iot_class": "local_polling", "loggers": ["pytraccar"], - "requirements": ["pytraccar==1.0.0", "stringcase==1.2.0"] + "requirements": ["pytraccar==2.0.0", "stringcase==1.2.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 22abb8ab832..4a90b20c0f3 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2214,7 +2214,7 @@ pytomorrowio==0.3.6 pytouchline==0.7 # homeassistant.components.traccar -pytraccar==1.0.0 +pytraccar==2.0.0 # homeassistant.components.tradfri pytradfri[async]==9.0.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c6da8673336..ae05caf404c 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1649,7 +1649,7 @@ pytile==2023.04.0 pytomorrowio==0.3.6 # homeassistant.components.traccar -pytraccar==1.0.0 +pytraccar==2.0.0 # homeassistant.components.tradfri pytradfri[async]==9.0.1