Skip to content

Commit

Permalink
Merge pull request #58 from Snuffy2/Check-if-lat/long-are-none
Browse files Browse the repository at this point in the history
Check if lat/long are none
  • Loading branch information
Snuffy2 authored Sep 21, 2022
2 parents 1b76288 + 2ab091a commit 2475d86
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
4 changes: 3 additions & 1 deletion custom_components/places/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
STATE_OPTIONS = ["zone, place", "formatted_place", "zone_name, place"]
MAP_ZOOM_MIN = 1
MAP_ZOOM_MAX = 20
COMPONENT_CONFIG_URL = "/~https://github.com/custom-components/places#configuration-options"
COMPONENT_CONFIG_URL = (
"/~https://github.com/custom-components/places#configuration-options"
)

# Note the input displayed to the user will be translated. See the
# translations/<lang>.json file and strings.json. See here for further information:
Expand Down
59 changes: 34 additions & 25 deletions custom_components/places/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,12 @@ def __init__(self, hass, config, config_entry, name, unique_id):
self._last_place_name = None
self._distance_km = 0
self._distance_m = 0
self._location_current = home_latitude + "," + home_longitude
self._location_previous = home_latitude + "," + home_longitude
if home_latitude is not None and home_longitude is not None:
self._location_current = str(home_latitude) + "," + str(home_longitude)
self._location_previous = str(home_latitude) + "," + str(home_longitude)
else:
self._location_current = None
self._location_previous = None
self._updateskipped = 0
self._direction = "stationary"
self._map_link = None
Expand Down Expand Up @@ -610,6 +614,8 @@ def do_update(self, reason):
devicetracker_zone_name_state = None
home_latitude = None
home_longitude = None
old_latitude = None
old_longitude = None
last_distance_m = None
last_updated = None
current_location = None
Expand Down Expand Up @@ -673,33 +679,36 @@ def do_update(self, reason):
_LOGGER.debug("(" + self._name + ") Previous State: " + str(previous_state))

now = datetime.now()
old_latitude = str(self._latitude)
if not self.is_float(old_latitude):
old_latitude = None
old_longitude = str(self._longitude)
if not self.is_float(old_latitude):
old_latitude = None
new_latitude = str(
if self.is_float(self._latitude):
old_latitude = str(self._latitude)
if self.is_float(self._longitude):
old_longitude = str(self._longitude)
if self.is_float(
self._hass.states.get(self._devicetracker_id).attributes.get("latitude")
)
if not self.is_float(new_latitude):
new_latitude = None
new_longitude = str(
):
new_latitude = str(
self._hass.states.get(self._devicetracker_id).attributes.get("latitude")
)
if self.is_float(
self._hass.states.get(self._devicetracker_id).attributes.get("longitude")
)
if not self.is_float(new_longitude):
new_longitude = None
home_latitude = str(self._home_latitude)
if not self.is_float(home_latitude):
home_latitude = None
home_longitude = str(self._home_longitude)
if not self.is_float(home_longitude):
home_longitude = None
):
new_longitude = str(
self._hass.states.get(self._devicetracker_id).attributes.get(
"longitude"
)
)
if self.is_float(self._home_latitude):
home_latitude = str(self._home_latitude)
if self.is_float(self._home_longitude):
home_longitude = str(self._home_longitude)
last_distance_m = self._distance_m
last_updated = self._mtime
current_location = new_latitude + "," + new_longitude
previous_location = old_latitude + "," + old_longitude
home_location = home_latitude + "," + home_longitude
if new_latitude is not None and new_longitude is not None:
current_location = str(new_latitude) + "," + str(new_longitude)
if old_latitude is not None and old_longitude is not None:
previous_location = str(old_latitude) + "," + str(old_longitude)
if home_latitude is not None and home_longitude is not None:
home_location = str(home_latitude) + "," + str(home_longitude)
prev_last_place_name = self._last_place_name
_LOGGER.debug(
"("
Expand Down

0 comments on commit 2475d86

Please sign in to comment.