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."""
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"],
},
)

View file

@ -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"]
}

View file

@ -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

View file

@ -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