mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
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 case
This commit is contained in:
parent
b1b269b302
commit
9cf9be8850
@ -25,6 +25,7 @@ ATTR_MOTION = 'motion'
|
|||||||
ATTR_SPEED = 'speed'
|
ATTR_SPEED = 'speed'
|
||||||
ATTR_TRACKER = 'tracker'
|
ATTR_TRACKER = 'tracker'
|
||||||
ATTR_TRACCAR_ID = 'traccar_id'
|
ATTR_TRACCAR_ID = 'traccar_id'
|
||||||
|
ATTR_STATUS = 'status'
|
||||||
|
|
||||||
EVENT_DEVICE_MOVING = 'device_moving'
|
EVENT_DEVICE_MOVING = 'device_moving'
|
||||||
EVENT_COMMAND_RESULT = 'command_result'
|
EVENT_COMMAND_RESULT = 'command_result'
|
||||||
@ -131,30 +132,39 @@ class TraccarScanner:
|
|||||||
|
|
||||||
async def import_device_data(self):
|
async def import_device_data(self):
|
||||||
"""Import device data from Traccar."""
|
"""Import device data from Traccar."""
|
||||||
for devicename in self._api.device_info:
|
for device_unique_id in self._api.device_info:
|
||||||
device = self._api.device_info[devicename]
|
device_info = self._api.device_info[device_unique_id]
|
||||||
|
device = None
|
||||||
attr = {}
|
attr = {}
|
||||||
attr[ATTR_TRACKER] = 'traccar'
|
attr[ATTR_TRACKER] = 'traccar'
|
||||||
if device.get('address') is not None:
|
if device_info.get('address') is not None:
|
||||||
attr[ATTR_ADDRESS] = device['address']
|
attr[ATTR_ADDRESS] = device_info['address']
|
||||||
if device.get('geofence') is not None:
|
if device_info.get('geofence') is not None:
|
||||||
attr[ATTR_GEOFENCE] = device['geofence']
|
attr[ATTR_GEOFENCE] = device_info['geofence']
|
||||||
if device.get('category') is not None:
|
if device_info.get('category') is not None:
|
||||||
attr[ATTR_CATEGORY] = device['category']
|
attr[ATTR_CATEGORY] = device_info['category']
|
||||||
if device.get('speed') is not None:
|
if device_info.get('speed') is not None:
|
||||||
attr[ATTR_SPEED] = device['speed']
|
attr[ATTR_SPEED] = device_info['speed']
|
||||||
if device.get('battery') is not None:
|
if device_info.get('battery') is not None:
|
||||||
attr[ATTR_BATTERY_LEVEL] = device['battery']
|
attr[ATTR_BATTERY_LEVEL] = device_info['battery']
|
||||||
if device.get('motion') is not None:
|
if device_info.get('motion') is not None:
|
||||||
attr[ATTR_MOTION] = device['motion']
|
attr[ATTR_MOTION] = device_info['motion']
|
||||||
if device.get('traccar_id') is not None:
|
if device_info.get('traccar_id') is not None:
|
||||||
attr[ATTR_TRACCAR_ID] = device['traccar_id']
|
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:
|
for custom_attr in self._custom_attributes:
|
||||||
if device.get(custom_attr) is not None:
|
if device_info.get(custom_attr) is not None:
|
||||||
attr[custom_attr] = device[custom_attr]
|
attr[custom_attr] = device_info[custom_attr]
|
||||||
await self._async_see(
|
await self._async_see(
|
||||||
dev_id=slugify(device['device_id']),
|
dev_id=slugify(device_info['device_id']),
|
||||||
gps=(device.get('latitude'), device.get('longitude')),
|
gps=(device_info.get('latitude'),
|
||||||
|
device_info.get('longitude')),
|
||||||
|
gps_accuracy=(device_info.get('accuracy')),
|
||||||
attributes=attr)
|
attributes=attr)
|
||||||
|
|
||||||
async def import_events(self):
|
async def import_events(self):
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Traccar",
|
"name": "Traccar",
|
||||||
"documentation": "https://www.home-assistant.io/components/traccar",
|
"documentation": "https://www.home-assistant.io/components/traccar",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"pytraccar==0.5.0",
|
"pytraccar==0.7.0",
|
||||||
"stringcase==1.2.0"
|
"stringcase==1.2.0"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
|
@ -1429,7 +1429,7 @@ pytile==2.0.6
|
|||||||
pytouchline==0.7
|
pytouchline==0.7
|
||||||
|
|
||||||
# homeassistant.components.traccar
|
# homeassistant.components.traccar
|
||||||
pytraccar==0.5.0
|
pytraccar==0.7.0
|
||||||
|
|
||||||
# homeassistant.components.trackr
|
# homeassistant.components.trackr
|
||||||
pytrackr==0.0.5
|
pytrackr==0.0.5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user