Bump pytraccar from 1.0.0 to 2.0.0 (#103318)

This commit is contained in:
Joakim Sørensen 2023-11-03 18:09:56 +01:00 committed by GitHub
parent 0f1c96ba97
commit 4778c55d2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 29 deletions

View File

@ -274,7 +274,8 @@ class TraccarScanner:
"""Import device data from Traccar.""" """Import device data from Traccar."""
for position in self._positions: for position in self._positions:
device = next( 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: if not device:
@ -282,36 +283,36 @@ class TraccarScanner:
attr = { attr = {
ATTR_TRACKER: "traccar", ATTR_TRACKER: "traccar",
ATTR_ADDRESS: position.address, ATTR_ADDRESS: position["address"],
ATTR_SPEED: position.speed, ATTR_SPEED: position["speed"],
ATTR_ALTITUDE: position.altitude, ATTR_ALTITUDE: position["altitude"],
ATTR_MOTION: position.attributes.get("motion", False), ATTR_MOTION: position["attributes"].get("motion", False),
ATTR_TRACCAR_ID: device.id, ATTR_TRACCAR_ID: device["id"],
ATTR_GEOFENCE: next( ATTR_GEOFENCE: next(
( (
geofence.name geofence["name"]
for geofence in self._geofences for geofence in self._geofences
if geofence.id in (device.geofence_ids or []) if geofence["id"] in (position["geofenceIds"] or [])
), ),
None, None,
), ),
ATTR_CATEGORY: device.category, ATTR_CATEGORY: device["category"],
ATTR_STATUS: device.status, ATTR_STATUS: device["status"],
} }
skip_accuracy_filter = False skip_accuracy_filter = False
for custom_attr in self._custom_attributes: for custom_attr in self._custom_attributes:
if device.attributes.get(custom_attr) is not None: if device["attributes"].get(custom_attr) is not None:
attr[custom_attr] = position.attributes[custom_attr] attr[custom_attr] = position["attributes"][custom_attr]
if custom_attr in self._skip_accuracy_on: if custom_attr in self._skip_accuracy_on:
skip_accuracy_filter = True skip_accuracy_filter = True
if position.attributes.get(custom_attr) is not None: if position["attributes"].get(custom_attr) is not None:
attr[custom_attr] = position.attributes[custom_attr] attr[custom_attr] = position["attributes"][custom_attr]
if custom_attr in self._skip_accuracy_on: if custom_attr in self._skip_accuracy_on:
skip_accuracy_filter = True skip_accuracy_filter = True
accuracy = position.accuracy or 0.0 accuracy = position["accuracy"] or 0.0
if ( if (
not skip_accuracy_filter not skip_accuracy_filter
and self._max_accuracy > 0 and self._max_accuracy > 0
@ -325,10 +326,10 @@ class TraccarScanner:
continue continue
await self._async_see( await self._async_see(
dev_id=slugify(device.name), dev_id=slugify(device["name"]),
gps=(position.latitude, position.longitude), gps=(position["latitude"], position["longitude"]),
gps_accuracy=accuracy, gps_accuracy=accuracy,
battery=position.attributes.get("batteryLevel", -1), battery=position["attributes"].get("batteryLevel", -1),
attributes=attr, attributes=attr,
) )
@ -337,7 +338,7 @@ class TraccarScanner:
# get_reports_events requires naive UTC datetimes as of 1.0.0 # get_reports_events requires naive UTC datetimes as of 1.0.0
start_intervel = dt_util.utcnow().replace(tzinfo=None) start_intervel = dt_util.utcnow().replace(tzinfo=None)
events = await self._api.get_reports_events( 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, start_time=start_intervel,
end_time=start_intervel - self._scan_interval, end_time=start_intervel - self._scan_interval,
event_types=self._event_types.keys(), event_types=self._event_types.keys(),
@ -345,20 +346,20 @@ class TraccarScanner:
if events is not None: if events is not None:
for event in events: for event in events:
self._hass.bus.async_fire( 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( "device_name": next(
( (
dev.name dev["name"]
for dev in self._devices for dev in self._devices
if dev.id == event.device_id if dev["id"] == event["deviceId"]
), ),
None, None,
), ),
"type": event.type, "type": event["type"],
"serverTime": event.event_time, "serverTime": event["eventTime"],
"attributes": event.attributes, "attributes": event["attributes"],
}, },
) )

View File

@ -7,5 +7,5 @@
"documentation": "https://www.home-assistant.io/integrations/traccar", "documentation": "https://www.home-assistant.io/integrations/traccar",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["pytraccar"], "loggers": ["pytraccar"],
"requirements": ["pytraccar==1.0.0", "stringcase==1.2.0"] "requirements": ["pytraccar==2.0.0", "stringcase==1.2.0"]
} }

View File

@ -2214,7 +2214,7 @@ pytomorrowio==0.3.6
pytouchline==0.7 pytouchline==0.7
# homeassistant.components.traccar # homeassistant.components.traccar
pytraccar==1.0.0 pytraccar==2.0.0
# homeassistant.components.tradfri # homeassistant.components.tradfri
pytradfri[async]==9.0.1 pytradfri[async]==9.0.1

View File

@ -1649,7 +1649,7 @@ pytile==2023.04.0
pytomorrowio==0.3.6 pytomorrowio==0.3.6
# homeassistant.components.traccar # homeassistant.components.traccar
pytraccar==1.0.0 pytraccar==2.0.0
# homeassistant.components.tradfri # homeassistant.components.tradfri
pytradfri[async]==9.0.1 pytradfri[async]==9.0.1