Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
`<config directory>/custom_components/sensor/authenticated.py`

**Example configuration.yaml:**

```yaml
Expand All @@ -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)

Expand Down Expand Up @@ -47,4 +47,4 @@ logger:
default: warn
logs:
custom_components.sensor.authenticated: debug
```
```
12 changes: 6 additions & 6 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.7'
__version__ = '0.0.8'

_LOGGER = logging.getLogger(__name__)

Expand All @@ -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]),
})
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down