Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
Fixed an issue where if failed if there was missing GEO data
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Jul 30, 2018
1 parent 7ab9b4b commit 992e41f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions custom_components/sensor/authenticated.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.helpers.entity import Entity

__version__ = '0.0.8'
__version__ = '0.0.9'

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -102,9 +102,13 @@ def new_ip(self, ip_address, access_time, hostname):
geo_region = geo['data']['subdivision_1_name']
geo_city = geo['data']['city_name']
self.write_file(ip_address, access_time, hostname, geo_country, geo_region, geo_city)
self._new_ip = True
self._new_ip = 'true'
_LOGGER.debug(ip_address)
_LOGGER.debug(geo_country)
_LOGGER.debug(geo_region)
_LOGGER.debug(geo_city)
if self._notify:
self.hass.components.persistent_notification.create('{}'.format(ip_address + ' (' + geo_country + ', ' + geo_region + ', ' + geo_city + ')'), 'New successful login from')
self.hass.components.persistent_notification.create('{}'.format(ip_address + ' (' + str(geo_country) + ', ' + str(geo_region) + ', ' + str(geo_city) + ')'), 'New successful login from')
else:
_LOGGER.debug('persistent_notifications is disabled in config, enable_notification=%s', self._notify)

Expand All @@ -119,7 +123,7 @@ def update_ip(self, ip_address, access_time, hostname):
doc[ip_address]['last_authenticated'] = access_time
doc[ip_address]['hostname'] = hostname

self._new_ip = False
self._new_ip = 'false'

with open(self._out, 'w') as f:
yaml.dump(doc, f, default_flow_style=False)
Expand Down

0 comments on commit 992e41f

Please sign in to comment.