1 """Support for Traccar device tracking."""
3 from __future__
import annotations
5 from datetime
import timedelta
17 from .
import DOMAIN, TRACKER_UPDATE
29 EVENT_DEVICE_FUEL_DROP,
33 EVENT_DEVICE_OVERSPEED,
45 _LOGGER = logging.getLogger(__name__)
48 SCAN_INTERVAL = DEFAULT_SCAN_INTERVAL
53 EVENT_DEVICE_FUEL_DROP,
58 EVENT_DEVICE_OVERSPEED,
72 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
74 """Configure a dispatcher connection based on a config entry."""
77 def _receive_data(device, latitude, longitude, battery, accuracy, attrs):
78 """Receive set location."""
79 if device
in hass.data[DOMAIN][
"devices"]:
82 hass.data[DOMAIN][
"devices"].
add(device)
85 [
TraccarEntity(device, latitude, longitude, battery, accuracy, attrs)]
88 hass.data[DOMAIN][
"unsub_device_tracker"][entry.entry_id] = (
93 dev_reg = dr.async_get(hass)
96 for device
in dev_reg.devices.get_devices_for_config_entry_id(entry.entry_id)
97 for identifier
in device.identifiers
103 for dev_id
in dev_ids:
104 hass.data[DOMAIN][
"devices"].
add(dev_id)
106 entities.append(entity)
112 """Represent a tracked device."""
114 _attr_has_entity_name =
True
117 def __init__(self, device, latitude, longitude, battery, accuracy, attributes):
118 """Set up Traccar entity."""
129 identifiers={(DOMAIN, device)},
134 """Return battery value of the device."""
138 """Register state update callback."""
145 if self.latitude
is not None or self.longitude
is not None:
160 attr = state.attributes
165 ATTR_ALTITUDE: attr.get(ATTR_ALTITUDE),
166 ATTR_BEARING: attr.get(ATTR_BEARING),
167 ATTR_SPEED: attr.get(ATTR_SPEED),
169 self.
_battery_battery = attr.get(ATTR_BATTERY)
172 """Clean up after entity before removal."""
178 self, device, latitude, longitude, battery, accuracy, attributes
180 """Mark the device as seen."""
181 if device != self.
_device_device:
def _async_receive_data(self, device, latitude, longitude, battery, accuracy, attributes)
_attr_extra_state_attributes
def __init__(self, device, latitude, longitude, battery, accuracy, attributes)
None async_added_to_hass(self)
None async_will_remove_from_hass(self)
None async_write_ha_state(self)
State|None async_get_last_state(self)
bool add(self, _T matcher)
IssData update(pyiss.ISS iss)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)