Skip to content

Commit

Permalink
Cleanup old device_tracker stuff (home-assistant#8627)
Browse files Browse the repository at this point in the history
* Cleanup old device_tracker stuff

* Fix lint
  • Loading branch information
pvizeli authored and balloob committed Jul 24, 2017
1 parent 654ad41 commit f86bd15
Show file tree
Hide file tree
Showing 22 changed files with 512 additions and 713 deletions.
26 changes: 9 additions & 17 deletions homeassistant/components/device_tracker/actiontec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
import logging
import re
import telnetlib
import threading
from collections import namedtuple
from datetime import timedelta
import voluptuous as vol

import homeassistant.helpers.config_validation as cv
import homeassistant.util.dt as dt_util
from homeassistant.components.device_tracker import (
DOMAIN, PLATFORM_SCHEMA, DeviceScanner)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.util import Throttle

MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -54,7 +49,6 @@ def __init__(self, config):
self.host = config[CONF_HOST]
self.username = config[CONF_USERNAME]
self.password = config[CONF_PASSWORD]
self.lock = threading.Lock()
self.last_results = []
data = self.get_actiontec_data()
self.success_init = data is not None
Expand All @@ -74,7 +68,6 @@ def get_device_name(self, device):
return client.ip
return None

@Throttle(MIN_TIME_BETWEEN_SCANS)
def _update_info(self):
"""Ensure the information from the router is up to date.
Expand All @@ -84,16 +77,15 @@ def _update_info(self):
if not self.success_init:
return False

with self.lock:
now = dt_util.now()
actiontec_data = self.get_actiontec_data()
if not actiontec_data:
return False
self.last_results = [Device(data['mac'], name, now)
for name, data in actiontec_data.items()
if data['timevalid'] > -60]
_LOGGER.info("Scan successful")
return True
now = dt_util.now()
actiontec_data = self.get_actiontec_data()
if not actiontec_data:
return False
self.last_results = [Device(data['mac'], name, now)
for name, data in actiontec_data.items()
if data['timevalid'] > -60]
_LOGGER.info("Scan successful")
return True

def get_actiontec_data(self):
"""Retrieve data from Actiontec MI424WR and return parsed result."""
Expand Down
19 changes: 5 additions & 14 deletions homeassistant/components/device_tracker/aruba.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@
"""
import logging
import re
import threading
from datetime import timedelta

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.device_tracker import (
DOMAIN, PLATFORM_SCHEMA, DeviceScanner)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.util import Throttle

_LOGGER = logging.getLogger(__name__)

REQUIREMENTS = ['pexpect==4.0.1']

MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)

_DEVICES_REGEX = re.compile(
r'(?P<name>([^\s]+))\s+' +
r'(?P<ip>([0-9]{1,3}[\.]){3}[0-9]{1,3})\s+' +
Expand Down Expand Up @@ -52,8 +47,6 @@ def __init__(self, config):
self.username = config[CONF_USERNAME]
self.password = config[CONF_PASSWORD]

self.lock = threading.Lock()

self.last_results = {}

# Test the router is accessible.
Expand All @@ -74,7 +67,6 @@ def get_device_name(self, device):
return client['name']
return None

@Throttle(MIN_TIME_BETWEEN_SCANS)
def _update_info(self):
"""Ensure the information from the Aruba Access Point is up to date.
Expand All @@ -83,13 +75,12 @@ def _update_info(self):
if not self.success_init:
return False

with self.lock:
data = self.get_aruba_data()
if not data:
return False
data = self.get_aruba_data()
if not data:
return False

self.last_results = data.values()
return True
self.last_results = data.values()
return True

def get_aruba_data(self):
"""Retrieve data from Aruba Access Point and return parsed result."""
Expand Down
33 changes: 12 additions & 21 deletions homeassistant/components/device_tracker/asuswrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
import re
import socket
import telnetlib
import threading
from collections import namedtuple
from datetime import timedelta

import voluptuous as vol

from homeassistant.components.device_tracker import (
DOMAIN, PLATFORM_SCHEMA, DeviceScanner)
from homeassistant.const import (
CONF_HOST, CONF_PASSWORD, CONF_USERNAME, CONF_PORT)
from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['pexpect==4.0.1']
Expand All @@ -32,8 +29,6 @@

DEFAULT_SSH_PORT = 22

MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)

SECRET_GROUP = 'Password or SSH Key'

PLATFORM_SCHEMA = vol.All(
Expand Down Expand Up @@ -123,8 +118,6 @@ def __init__(self, config):
self.password,
self.mode == "ap")

self.lock = threading.Lock()

self.last_results = {}

# Test the router is accessible.
Expand All @@ -145,7 +138,6 @@ def get_device_name(self, device):
return client['host']
return None

@Throttle(MIN_TIME_BETWEEN_SCANS)
def _update_info(self):
"""Ensure the information from the ASUSWRT router is up to date.
Expand All @@ -154,19 +146,18 @@ def _update_info(self):
if not self.success_init:
return False

with self.lock:
_LOGGER.info('Checking Devices')
data = self.get_asuswrt_data()
if not data:
return False

active_clients = [client for client in data.values() if
client['status'] == 'REACHABLE' or
client['status'] == 'DELAY' or
client['status'] == 'STALE' or
client['status'] == 'IN_ASSOCLIST']
self.last_results = active_clients
return True
_LOGGER.info('Checking Devices')
data = self.get_asuswrt_data()
if not data:
return False

active_clients = [client for client in data.values() if
client['status'] == 'REACHABLE' or
client['status'] == 'DELAY' or
client['status'] == 'STALE' or
client['status'] == 'IN_ASSOCLIST']
self.last_results = active_clients
return True

def get_asuswrt_data(self):
"""Retrieve data from ASUSWRT and return parsed result."""
Expand Down
38 changes: 13 additions & 25 deletions homeassistant/components/device_tracker/bt_home_hub_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"""
import logging
import re
import threading
from datetime import timedelta
import xml.etree.ElementTree as ET
import json
from urllib.parse import unquote
Expand All @@ -19,13 +17,10 @@
from homeassistant.components.device_tracker import (
DOMAIN, PLATFORM_SCHEMA, DeviceScanner)
from homeassistant.const import CONF_HOST
from homeassistant.util import Throttle

_LOGGER = logging.getLogger(__name__)
_MAC_REGEX = re.compile(r'(([0-9A-Fa-f]{1,2}\:){5}[0-9A-Fa-f]{1,2})')

MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string
})
Expand All @@ -46,11 +41,7 @@ def __init__(self, config):
"""Initialise the scanner."""
_LOGGER.info("Initialising BT Home Hub 5")
self.host = config.get(CONF_HOST, '192.168.1.254')

self.lock = threading.Lock()

self.last_results = {}

self.url = 'http://{}/nonAuth/home_status.xml'.format(self.host)

# Test the router is accessible
Expand All @@ -65,17 +56,15 @@ def scan_devices(self):

def get_device_name(self, device):
"""Return the name of the given device or None if we don't know."""
with self.lock:
# If not initialised and not already scanned and not found.
if device not in self.last_results:
self._update_info()
# If not initialised and not already scanned and not found.
if device not in self.last_results:
self._update_info()

if not self.last_results:
return None
if not self.last_results:
return None

return self.last_results.get(device)
return self.last_results.get(device)

@Throttle(MIN_TIME_BETWEEN_SCANS)
def _update_info(self):
"""Ensure the information from the BT Home Hub 5 is up to date.
Expand All @@ -84,18 +73,17 @@ def _update_info(self):
if not self.success_init:
return False

with self.lock:
_LOGGER.info("Scanning")
_LOGGER.info("Scanning")

data = _get_homehub_data(self.url)
data = _get_homehub_data(self.url)

if not data:
_LOGGER.warning("Error scanning devices")
return False
if not data:
_LOGGER.warning("Error scanning devices")
return False

self.last_results = data
self.last_results = data

return True
return True


def _get_homehub_data(url):
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/device_tracker/cisco_ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
https://home-assistant.io/components/device_tracker.cisco_ios/
"""
import logging
from datetime import timedelta

import voluptuous as vol

Expand All @@ -14,9 +13,6 @@
DOMAIN, PLATFORM_SCHEMA, DeviceScanner)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, \
CONF_PORT
from homeassistant.util import Throttle

MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -65,7 +61,6 @@ def scan_devices(self):

return self.last_results

@Throttle(MIN_TIME_BETWEEN_SCANS)
def _update_info(self):
"""
Ensure the information from the Cisco router is up to date.
Expand Down
Loading

0 comments on commit f86bd15

Please sign in to comment.