From edada1df3563a3cc62106485017f452f50d81d59 Mon Sep 17 00:00:00 2001 From: Seb Harrington Date: Sat, 20 Apr 2024 21:25:38 +0100 Subject: [PATCH] Update helpers.py to use netbox long / lat fields. updated helper function get_device_location to use netbox's native location fields --- netbox_device_map/helpers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/netbox_device_map/helpers.py b/netbox_device_map/helpers.py index 6215ead..fca6175 100644 --- a/netbox_device_map/helpers.py +++ b/netbox_device_map/helpers.py @@ -14,7 +14,10 @@ LatLon = tuple[float, float] def get_device_location(device: Device) -> LatLon | None: - """Extract device geolocation from special custom field""" + """If netbox longitude and latitude fields are populated for a device then use them.""" + if device.longitude and device.latitude: + return (device.longitude, device.latitude) + """... Otherwise extract device geolocation from special custom field""" if location_cf := device.custom_field_data.get(LOCATION_CF_NAME): return tuple(map(float, location_cf.replace(' ', '').split(',', maxsplit=1)))