mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix custom attribute lookup in Traccar Server (#109331)
This commit is contained in:
parent
c1f883519d
commit
3511f35418
@ -93,10 +93,9 @@ class TraccarServerCoordinator(DataUpdateCoordinator[TraccarServerCoordinatorDat
|
|||||||
skip_accuracy_filter = False
|
skip_accuracy_filter = False
|
||||||
|
|
||||||
for custom_attr in self.custom_attributes:
|
for custom_attr in self.custom_attributes:
|
||||||
attr[custom_attr] = getattr(
|
attr[custom_attr] = device["attributes"].get(
|
||||||
device["attributes"],
|
|
||||||
custom_attr,
|
custom_attr,
|
||||||
getattr(position["attributes"], custom_attr, None),
|
position["attributes"].get(custom_attr, None),
|
||||||
)
|
)
|
||||||
if custom_attr in self.skip_accuracy_filter_for:
|
if custom_attr in self.skip_accuracy_filter_for:
|
||||||
skip_accuracy_filter = True
|
skip_accuracy_filter = True
|
||||||
@ -151,13 +150,16 @@ class TraccarServerCoordinator(DataUpdateCoordinator[TraccarServerCoordinatorDat
|
|||||||
device = get_device(event["deviceId"], devices)
|
device = get_device(event["deviceId"], devices)
|
||||||
self.hass.bus.async_fire(
|
self.hass.bus.async_fire(
|
||||||
# This goes against two of the HA core guidelines:
|
# 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
|
# 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']]}",
|
f"traccar_{EVENTS[event['type']]}",
|
||||||
{
|
{
|
||||||
"device_traccar_id": event["deviceId"],
|
"device_traccar_id": event["deviceId"],
|
||||||
"device_name": getattr(device, "name", None),
|
"device_name": device["name"] if device else None,
|
||||||
"type": event["type"],
|
"type": event["type"],
|
||||||
"serverTime": event["eventTime"],
|
"serverTime": event["eventTime"],
|
||||||
"attributes": event["attributes"],
|
"attributes": event["attributes"],
|
||||||
|
@ -51,12 +51,13 @@ class TraccarServerDeviceTracker(TraccarServerEntity, TrackerEntity):
|
|||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, Any]:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return device specific attributes."""
|
"""Return device specific attributes."""
|
||||||
|
geofence_name = self.traccar_geofence["name"] if self.traccar_geofence else None
|
||||||
return {
|
return {
|
||||||
**self.traccar_attributes,
|
**self.traccar_attributes,
|
||||||
ATTR_ADDRESS: self.traccar_position["address"],
|
ATTR_ADDRESS: self.traccar_position["address"],
|
||||||
ATTR_ALTITUDE: self.traccar_position["altitude"],
|
ATTR_ALTITUDE: self.traccar_position["altitude"],
|
||||||
ATTR_CATEGORY: self.traccar_device["category"],
|
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_MOTION: self.traccar_position["attributes"].get("motion", False),
|
||||||
ATTR_SPEED: self.traccar_position["speed"],
|
ATTR_SPEED: self.traccar_position["speed"],
|
||||||
ATTR_STATUS: self.traccar_device["status"],
|
ATTR_STATUS: self.traccar_device["status"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user