handle errors when gps coordinates are out of range

This commit is contained in:
Jakob Ketterl 2021-09-30 23:03:21 +02:00
parent 460bada88f
commit 0b64b4ac97
2 changed files with 12 additions and 1 deletions

View File

@ -2,6 +2,9 @@ from owrx.config import Config
from owrx.locator import Locator
from owrx.property import PropertyFilter
from owrx.property.filter import ByPropertyName
import logging
logger = logging.getLogger(__name__)
class ReceiverDetails(PropertyFilter):
@ -20,5 +23,8 @@ class ReceiverDetails(PropertyFilter):
def __dict__(self):
receiver_info = super().__dict__()
receiver_info["locator"] = Locator.fromCoordinates(receiver_info["receiver_gps"])
try:
receiver_info["locator"] = Locator.fromCoordinates(receiver_info["receiver_gps"])
except ValueError as e:
logger.error("invalid receiver location, check in settings: %s", str(e))
return receiver_info

View File

@ -5,6 +5,11 @@ class Locator(object):
lat = coordinates["lat"]
lon = coordinates["lon"]
if not -90 < lat < 90:
raise ValueError("invalid latitude: {}".format(lat))
if not -180 < lon < 180:
raise ValueError("invalid longitude: {}".format(lon))
lon = lon + 180
lat = lat + 90