Fix custom attribute lookup in Traccar Server (#109331)
parent
c1f883519d
commit
3511f35418
|
@ -93,10 +93,9 @@ class TraccarServerCoordinator(DataUpdateCoordinator[TraccarServerCoordinatorDat
|
|||
skip_accuracy_filter = False
|
||||
|
||||
for custom_attr in self.custom_attributes:
|
||||
attr[custom_attr] = getattr(
|
||||
device["attributes"],
|
||||
attr[custom_attr] = device["attributes"].get(
|
||||
custom_attr,
|
||||
getattr(position["attributes"], custom_attr, None),
|
||||
position["attributes"].get(custom_attr, None),
|
||||
)
|
||||
if custom_attr in self.skip_accuracy_filter_for:
|
||||
skip_accuracy_filter = True
|
||||
|
@ -151,13 +150,16 @@ class TraccarServerCoordinator(DataUpdateCoordinator[TraccarServerCoordinatorDat
|
|||
device = get_device(event["deviceId"], devices)
|
||||
self.hass.bus.async_fire(
|
||||
# This goes against two of the HA core guidelines:
|
||||
# 1. Event names should be prefixed with the domain name of the integration
|
||||
# 1. Event names should be prefixed with the domain name of
|
||||
# the integration
|
||||
# 2. This should be event entities
|
||||
# However, to not break it for those who currently use the "old" integration, this is kept as is.
|
||||
#
|
||||
# However, to not break it for those who currently use
|
||||
# the "old" integration, this is kept as is.
|
||||
f"traccar_{EVENTS[event['type']]}",
|
||||
{
|
||||
"device_traccar_id": event["deviceId"],
|
||||
"device_name": getattr(device, "name", None),
|
||||
"device_name": device["name"] if device else None,
|
||||
"type": event["type"],
|
||||
"serverTime": event["eventTime"],
|
||||
"attributes": event["attributes"],
|
||||
|
|
|
@ -51,12 +51,13 @@ class TraccarServerDeviceTracker(TraccarServerEntity, TrackerEntity):
|
|||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return device specific attributes."""
|
||||
geofence_name = self.traccar_geofence["name"] if self.traccar_geofence else None
|
||||
return {
|
||||
**self.traccar_attributes,
|
||||
ATTR_ADDRESS: self.traccar_position["address"],
|
||||
ATTR_ALTITUDE: self.traccar_position["altitude"],
|
||||
ATTR_CATEGORY: self.traccar_device["category"],
|
||||
ATTR_GEOFENCE: getattr(self.traccar_geofence, "name", None),
|
||||
ATTR_GEOFENCE: geofence_name,
|
||||
ATTR_MOTION: self.traccar_position["attributes"].get("motion", False),
|
||||
ATTR_SPEED: self.traccar_position["speed"],
|
||||
ATTR_STATUS: self.traccar_device["status"],
|
||||
|
|
Loading…
Reference in New Issue