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

Commit

Permalink
fix issue with excluded IP's
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Jul 21, 2019
1 parent 1642000 commit 476270a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .devcontainer/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ logger:


sensor:
- platform: authenticated
- platform: authenticated
exclude:
- 8.8.8.8
- 1.1.1.1
19 changes: 12 additions & 7 deletions custom_components/authenticated/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
exclude = config.get(CONF_EXCLUDE)
hass.data[PLATFORM_NAME] = {}

if not load_authentications(hass.config.path(".storage/auth")):
if not load_authentications(hass.config.path(".storage/auth"), exclude):
return False

out = str(hass.config.path(OUTFILE))
Expand Down Expand Up @@ -104,16 +104,16 @@ def __init__(self, hass, notify, out, exclude, provider):

def initial_run(self):
"""Run this at startup to initialize the platform data."""
users, tokens = load_authentications(self.hass.config.path(".storage/auth"))
users, tokens = load_authentications(
self.hass.config.path(".storage/auth"), self.exclude
)

if os.path.isfile(self.out):
self.stored = get_outfile_content(self.out)
else:
_LOGGER.debug("File has not been created, no data pressent.")

for access in tokens:
if access in self.exclude:
continue

try:
ValidateIP(access)
Expand Down Expand Up @@ -166,7 +166,9 @@ def initial_run(self):
def update(self):
"""Method to update sensor value"""
updated = False
users, tokens = load_authentications(self.hass.config.path(".storage/auth"))
users, tokens = load_authentications(
self.hass.config.path(".storage/auth"), self.exclude
)
for access in tokens:
try:
ValidateIP(access)
Expand Down Expand Up @@ -210,7 +212,8 @@ def update(self):
):
self.last_ip = self.hass.data[PLATFORM_NAME][ipaddr]
break
self._state = self.last_ip.ip_address
if self.last_ip is not None:
self._state = self.last_ip.ip_address
if updated:
self.write_to_file()

Expand Down Expand Up @@ -300,7 +303,7 @@ def get_hostname(ip_address):
return hostname


def load_authentications(authfile):
def load_authentications(authfile, exclude):
"""Load info from auth file."""
if not os.path.exists(authfile):
_LOGGER.critical("File is missing %s", authfile)
Expand All @@ -317,6 +320,8 @@ def load_authentications(authfile):

for token in tokens:
try:
if token["last_used_ip"] in exclude:
continue
if token["last_used_ip"] in tokens_cleaned:
if (
token["last_used_at"]
Expand Down

0 comments on commit 476270a

Please sign in to comment.