Add accuracy and status for Traccar (#23180)
* Fix read gps position accuracy & read device status * Fix: W291 trailing whitespace & E501 line too long (80 > 79 characters) * Upgrade pytraccar dependency to 0.7.0 * met snake casepull/23279/head
parent
b1b269b302
commit
9cf9be8850
|
@ -25,6 +25,7 @@ ATTR_MOTION = 'motion'
|
|||
ATTR_SPEED = 'speed'
|
||||
ATTR_TRACKER = 'tracker'
|
||||
ATTR_TRACCAR_ID = 'traccar_id'
|
||||
ATTR_STATUS = 'status'
|
||||
|
||||
EVENT_DEVICE_MOVING = 'device_moving'
|
||||
EVENT_COMMAND_RESULT = 'command_result'
|
||||
|
@ -131,30 +132,39 @@ class TraccarScanner:
|
|||
|
||||
async def import_device_data(self):
|
||||
"""Import device data from Traccar."""
|
||||
for devicename in self._api.device_info:
|
||||
device = self._api.device_info[devicename]
|
||||
for device_unique_id in self._api.device_info:
|
||||
device_info = self._api.device_info[device_unique_id]
|
||||
device = None
|
||||
attr = {}
|
||||
attr[ATTR_TRACKER] = 'traccar'
|
||||
if device.get('address') is not None:
|
||||
attr[ATTR_ADDRESS] = device['address']
|
||||
if device.get('geofence') is not None:
|
||||
attr[ATTR_GEOFENCE] = device['geofence']
|
||||
if device.get('category') is not None:
|
||||
attr[ATTR_CATEGORY] = device['category']
|
||||
if device.get('speed') is not None:
|
||||
attr[ATTR_SPEED] = device['speed']
|
||||
if device.get('battery') is not None:
|
||||
attr[ATTR_BATTERY_LEVEL] = device['battery']
|
||||
if device.get('motion') is not None:
|
||||
attr[ATTR_MOTION] = device['motion']
|
||||
if device.get('traccar_id') is not None:
|
||||
attr[ATTR_TRACCAR_ID] = device['traccar_id']
|
||||
if device_info.get('address') is not None:
|
||||
attr[ATTR_ADDRESS] = device_info['address']
|
||||
if device_info.get('geofence') is not None:
|
||||
attr[ATTR_GEOFENCE] = device_info['geofence']
|
||||
if device_info.get('category') is not None:
|
||||
attr[ATTR_CATEGORY] = device_info['category']
|
||||
if device_info.get('speed') is not None:
|
||||
attr[ATTR_SPEED] = device_info['speed']
|
||||
if device_info.get('battery') is not None:
|
||||
attr[ATTR_BATTERY_LEVEL] = device_info['battery']
|
||||
if device_info.get('motion') is not None:
|
||||
attr[ATTR_MOTION] = device_info['motion']
|
||||
if device_info.get('traccar_id') is not None:
|
||||
attr[ATTR_TRACCAR_ID] = device_info['traccar_id']
|
||||
for dev in self._api.devices:
|
||||
if dev['id'] == device_info['traccar_id']:
|
||||
device = dev
|
||||
break
|
||||
if device is not None and device.get('status') is not None:
|
||||
attr[ATTR_STATUS] = device['status']
|
||||
for custom_attr in self._custom_attributes:
|
||||
if device.get(custom_attr) is not None:
|
||||
attr[custom_attr] = device[custom_attr]
|
||||
if device_info.get(custom_attr) is not None:
|
||||
attr[custom_attr] = device_info[custom_attr]
|
||||
await self._async_see(
|
||||
dev_id=slugify(device['device_id']),
|
||||
gps=(device.get('latitude'), device.get('longitude')),
|
||||
dev_id=slugify(device_info['device_id']),
|
||||
gps=(device_info.get('latitude'),
|
||||
device_info.get('longitude')),
|
||||
gps_accuracy=(device_info.get('accuracy')),
|
||||
attributes=attr)
|
||||
|
||||
async def import_events(self):
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
"name": "Traccar",
|
||||
"documentation": "https://www.home-assistant.io/components/traccar",
|
||||
"requirements": [
|
||||
"pytraccar==0.5.0",
|
||||
"pytraccar==0.7.0",
|
||||
"stringcase==1.2.0"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": [
|
||||
"@ludeeus"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1429,7 +1429,7 @@ pytile==2.0.6
|
|||
pytouchline==0.7
|
||||
|
||||
# homeassistant.components.traccar
|
||||
pytraccar==0.5.0
|
||||
pytraccar==0.7.0
|
||||
|
||||
# homeassistant.components.trackr
|
||||
pytrackr==0.0.5
|
||||
|
|
Loading…
Reference in New Issue