From 57563a49d1bc7d806c20e3921f26122c1547bb41 Mon Sep 17 00:00:00 2001 From: Jorim Tielemans Date: Mon, 30 Jul 2018 11:35:13 +0200 Subject: [PATCH 1/2] Use boolean instead of string And update the readme --- README.md | 18 +++++++++--------- custom_components/sensor/authenticated.py | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 7455c4b..b1d9b5d 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # sensor.authenticated A platform which allows you to get information sucessfull logins to Home Assistant. - + To get started put `/custom_components/sensor/authenticated.py` here: `/custom_components/sensor/authenticated.py` - + **Example configuration.yaml:** ```yaml @@ -14,12 +14,12 @@ sensor: **Configuration variables:** -key | description -:--- | :--- -**platform (Required)** | The sensor platform name. -**enable_notification (Optional)** | Turn on/off `persistant_notifications` when a new IP is detected, can be `True`/`False` defaults to `True`. -**exclude (Optional)** | A list of IP adresses you want to exclude. - +| key | required | default | description +| --- | --- | --- | --- +| **platform** | yes | | The sensor platform name. +| **enable_notification** | no | `true` | Turn on/off `persistant_notifications` when a new IP is detected, can be `true`/`false`. +| **exclude** | no | | A list of IP adresses you want to exclude. + **Sample overview:**\ ![Sample overview](/img/overview.png) @@ -47,4 +47,4 @@ logger: default: warn logs: custom_components.sensor.authenticated: debug -``` \ No newline at end of file +``` diff --git a/custom_components/sensor/authenticated.py b/custom_components/sensor/authenticated.py index a1ae1a2..447a221 100644 --- a/custom_components/sensor/authenticated.py +++ b/custom_components/sensor/authenticated.py @@ -37,7 +37,7 @@ OUTFILE = '.ip_authenticated.yaml' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ - vol.Optional(CONF_NOTIFY, default='True'): cv.string, + vol.Optional(CONF_NOTIFY, default=True): cv.boolean, vol.Optional(CONF_EXCLUDE, default='None'): vol.All(cv.ensure_list, [cv.string]), }) @@ -64,7 +64,7 @@ def __init__(self, hass, notify, log, out, exclude): self._country = None self._region = None self._city = None - self._new_ip = 'false' + self._new_ip = False self._last_authenticated_time = None self._previous_authenticated_time = None self._exclude = exclude @@ -102,8 +102,8 @@ 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' - if self._notify == 'True': + self._new_ip = True + if self._notify: self.hass.components.persistent_notification.create('{}'.format(ip_address + ' (' + geo_country + ', ' + geo_region + ', ' + geo_city + ')'), 'New successful login from') else: _LOGGER.debug('persistent_notifications is disabled in config, enable_notification=%s', self._notify) @@ -119,7 +119,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) From f99c14371d08cefcb8f42ad2942fb89befe78d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 30 Jul 2018 11:47:24 +0200 Subject: [PATCH 2/2] Update authenticated.py --- custom_components/sensor/authenticated.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/sensor/authenticated.py b/custom_components/sensor/authenticated.py index 447a221..f22e203 100644 --- a/custom_components/sensor/authenticated.py +++ b/custom_components/sensor/authenticated.py @@ -14,7 +14,7 @@ from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.helpers.entity import Entity -__version__ = '0.0.7' +__version__ = '0.0.8' _LOGGER = logging.getLogger(__name__)