Handled fail where core.location does not provide values for latitude and longitude. Added handling for coordinates N, S, E, W.
This commit is contained in:
parent
e70402e92c
commit
61fe7f6d3e
1 changed files with 21 additions and 4 deletions
|
@ -116,6 +116,8 @@ class Module(core.module.Module):
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
widget = self.widget()
|
widget = self.widget()
|
||||||
|
__lat = None
|
||||||
|
__lon = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
util.location.reset()
|
util.location.reset()
|
||||||
|
@ -123,10 +125,23 @@ class Module(core.module.Module):
|
||||||
# Fetch fresh location information
|
# Fetch fresh location information
|
||||||
__info = util.location.location_info()
|
__info = util.location.location_info()
|
||||||
|
|
||||||
# Contstruct coordinates string
|
# Contstruct coordinates string if util.location has provided required info
|
||||||
|
if __lat and __lon:
|
||||||
__lat = "{:.2f}".format(__info["latitude"])
|
__lat = "{:.2f}".format(__info["latitude"])
|
||||||
__lon = "{:.2f}".format(__info["longitude"])
|
__lon = "{:.2f}".format(__info["longitude"])
|
||||||
__coords = __lat + "°N" + "," + " " + __lon + "°E"
|
if __lat < 0:
|
||||||
|
__coords = __lat + "°S"
|
||||||
|
else:
|
||||||
|
__coords = __lat + "°N"
|
||||||
|
__coords += ","
|
||||||
|
if __lon < 0:
|
||||||
|
__coords += __lon + "°W"
|
||||||
|
else:
|
||||||
|
__coords += __lon + "°E"
|
||||||
|
else:
|
||||||
|
__lat = "Unknown"
|
||||||
|
__lon = "Unknown"
|
||||||
|
__coords = "Unknown"
|
||||||
|
|
||||||
# Set widget values
|
# Set widget values
|
||||||
widget.set("public_ip", __info["public_ip"])
|
widget.set("public_ip", __info["public_ip"])
|
||||||
|
@ -139,6 +154,8 @@ class Module(core.module.Module):
|
||||||
core.event.trigger("update", [widget.module.id], redraw_only=True)
|
core.event.trigger("update", [widget.module.id], redraw_only=True)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
widget.set("public_ip", None)
|
widget.set("public_ip", None)
|
||||||
|
print("OH NOES!")
|
||||||
|
print(__info)
|
||||||
logging.error(str(ex))
|
logging.error(str(ex))
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
|
|
Loading…
Reference in a new issue