Add sensor entities to Traccar Server (#111374)

This commit is contained in:
Joakim Sørensen 2024-04-02 12:11:28 +02:00 committed by GitHub
parent e473914407
commit a1ae4ec23d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 318 additions and 41 deletions

View file

@ -10,12 +10,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import (
ATTR_ADDRESS,
ATTR_ALTITUDE,
ATTR_CATEGORY,
ATTR_GEOFENCE,
ATTR_MOTION,
ATTR_SPEED,
ATTR_STATUS,
ATTR_TRACCAR_ID,
ATTR_TRACKER,
@ -44,23 +40,13 @@ class TraccarServerDeviceTracker(TraccarServerEntity, TrackerEntity):
_attr_has_entity_name = True
_attr_name = None
@property
def battery_level(self) -> int:
"""Return battery value of the device."""
return self.traccar_position["attributes"].get("batteryLevel", -1)
@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: geofence_name,
ATTR_MOTION: self.traccar_position["attributes"].get("motion", False),
ATTR_SPEED: self.traccar_position["speed"],
ATTR_STATUS: self.traccar_device["status"],
ATTR_TRACCAR_ID: self.traccar_device["id"],
ATTR_TRACKER: DOMAIN,