From 514b8eddb9d7ab94c726887f350ab36a9a14b3c5 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Mon, 7 Sep 2015 19:19:11 +0200 Subject: [PATCH] Update docstring (config file) and attempt to honor PEP0257 --- .../components/device_tracker/actiontec.py | 25 ++++++----- .../components/device_tracker/aruba.py | 18 ++++---- .../components/device_tracker/asuswrt.py | 20 +++++---- .../components/device_tracker/ddwrt.py | 19 +++++---- .../components/device_tracker/luci.py | 20 +++++---- .../components/device_tracker/netgear.py | 14 ++++--- .../components/device_tracker/nmap_tracker.py | 16 +++---- .../components/device_tracker/thomson.py | 13 +++--- .../components/device_tracker/tomato.py | 3 +- .../components/device_tracker/tplink.py | 42 +++++++++++-------- 10 files changed, 109 insertions(+), 81 deletions(-) diff --git a/homeassistant/components/device_tracker/actiontec.py b/homeassistant/components/device_tracker/actiontec.py index a922da9fe88..f926b182983 100644 --- a/homeassistant/components/device_tracker/actiontec.py +++ b/homeassistant/components/device_tracker/actiontec.py @@ -1,6 +1,6 @@ """ homeassistant.components.device_tracker.actiontec -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Device tracker platform that supports scanning an Actiontec MI424WR (Verizon FIOS) router for device presence. @@ -9,10 +9,9 @@ This device tracker needs telnet to be enabled on the router. Configuration: To use the Actiontec tracker you will need to add something like the -following to your config/configuration.yaml. If you experience disconnects +following to your configuration.yaml file. If you experience disconnects you can modify the home_interval variable. - device_tracker: platform: actiontec host: YOUR_ROUTER_IP @@ -69,7 +68,7 @@ _LEASES_REGEX = re.compile( # pylint: disable=unused-argument def get_scanner(hass, config): - """ Validates config and returns a DD-WRT scanner. """ + """ Validates config and returns an Actiontec scanner. """ if not validate_config(config, {DOMAIN: [CONF_HOST, CONF_USERNAME, CONF_PASSWORD]}, _LOGGER): @@ -83,8 +82,9 @@ Device = namedtuple("Device", ["mac", "ip", "last_update"]) class ActiontecDeviceScanner(object): - """ This class queries a an actiontec router - for connected devices. Adapted from DD-WRT scanner. + """ + This class queries a an actiontec router for connected devices. + Adapted from DD-WRT scanner. """ def __init__(self, config): @@ -106,8 +106,9 @@ class ActiontecDeviceScanner(object): _LOGGER.info("home_interval set to: %s", self.home_interval) def scan_devices(self): - """ Scans for new devices and return a - list containing found device ids. """ + """ + Scans for new devices and return a list containing found device ids. + """ self._update_info() return [client.mac for client in self.last_results] @@ -123,8 +124,10 @@ class ActiontecDeviceScanner(object): @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): - """ Ensures the information from the Actiontec MI424WR router is up - to date. Returns boolean if scanning successful. """ + """ + Ensures the information from the Actiontec MI424WR router is up + to date. Returns boolean if scanning successful. + """ _LOGGER.info("Scanning") if not self.success_init: return False @@ -155,7 +158,7 @@ class ActiontecDeviceScanner(object): return True def get_actiontec_data(self): - """ Retrieve data from Actiontec MI424WR and return parsed result. """ + """ Retrieve data from Actiontec MI424WR and return parsed result. """ try: telnet = telnetlib.Telnet(self.host) telnet.read_until(b'Username: ') diff --git a/homeassistant/components/device_tracker/aruba.py b/homeassistant/components/device_tracker/aruba.py index 5ee7b69e693..68ff8390216 100644 --- a/homeassistant/components/device_tracker/aruba.py +++ b/homeassistant/components/device_tracker/aruba.py @@ -9,8 +9,8 @@ This device tracker needs telnet to be enabled on the router. Configuration: To use the Aruba tracker you will need to add something like the following -to your config/configuration.yaml. You also need to enable Telnet in the -configuration pages. +to your configuration.yaml file. You also need to enable Telnet in the +configuration page of your router. device_tracker: platform: aruba @@ -83,8 +83,9 @@ class ArubaDeviceScanner(object): self.success_init = data is not None def scan_devices(self): - """ Scans for new devices and return a list containing found device - ids. """ + """ + Scans for new devices and return a list containing found device IDs. + """ self._update_info() return [client['mac'] for client in self.last_results] @@ -100,8 +101,10 @@ class ArubaDeviceScanner(object): @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): - """ Ensures the information from the Aruba Access Point is up to date. - Returns boolean if scanning successful. """ + """ + Ensures the information from the Aruba Access Point is up to date. + Returns boolean if scanning successful. + """ if not self.success_init: return False @@ -114,8 +117,7 @@ class ArubaDeviceScanner(object): return True def get_aruba_data(self): - """ Retrieve data from Aruba Access Point and return parsed - result. """ + """ Retrieve data from Aruba Access Point and return parsed result. """ try: telnet = telnetlib.Telnet(self.host) telnet.read_until(b'User: ') diff --git a/homeassistant/components/device_tracker/asuswrt.py b/homeassistant/components/device_tracker/asuswrt.py index fdf2ca70eaa..c0b29ab420f 100644 --- a/homeassistant/components/device_tracker/asuswrt.py +++ b/homeassistant/components/device_tracker/asuswrt.py @@ -9,7 +9,7 @@ This device tracker needs telnet to be enabled on the router. Configuration: To use the ASUSWRT tracker you will need to add something like the following -to your config/configuration.yaml +to your configuration.yaml file. device_tracker: platform: asuswrt @@ -63,7 +63,7 @@ _IP_NEIGH_REGEX = re.compile( # pylint: disable=unused-argument def get_scanner(hass, config): - """ Validates config and returns a DD-WRT scanner. """ + """ Validates config and returns an ASUS-WRT scanner. """ if not validate_config(config, {DOMAIN: [CONF_HOST, CONF_USERNAME, CONF_PASSWORD]}, _LOGGER): @@ -75,7 +75,8 @@ def get_scanner(hass, config): class AsusWrtDeviceScanner(object): - """ This class queries a router running ASUSWRT firmware + """ + This class queries a router running ASUSWRT firmware for connected devices. Adapted from DD-WRT scanner. """ @@ -93,8 +94,9 @@ class AsusWrtDeviceScanner(object): self.success_init = data is not None def scan_devices(self): - """ Scans for new devices and return a - list containing found device ids. """ + """ + Scans for new devices and return a list containing found device IDs. + """ self._update_info() return [client['mac'] for client in self.last_results] @@ -110,8 +112,10 @@ class AsusWrtDeviceScanner(object): @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): - """ Ensures the information from the ASUSWRT router is up to date. - Returns boolean if scanning successful. """ + """ + Ensures the information from the ASUSWRT router is up to date. + Returns boolean if scanning successful. + """ if not self.success_init: return False @@ -129,7 +133,7 @@ class AsusWrtDeviceScanner(object): return True def get_asuswrt_data(self): - """ Retrieve data from ASUSWRT and return parsed result. """ + """ Retrieve data from ASUSWRT and return parsed result. """ try: telnet = telnetlib.Telnet(self.host) telnet.read_until(b'login: ') diff --git a/homeassistant/components/device_tracker/ddwrt.py b/homeassistant/components/device_tracker/ddwrt.py index 2c69746fab0..a9a4ac8e3f5 100644 --- a/homeassistant/components/device_tracker/ddwrt.py +++ b/homeassistant/components/device_tracker/ddwrt.py @@ -1,14 +1,13 @@ """ homeassistant.components.device_tracker.ddwrt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Device tracker platform that supports scanning a DD-WRT router for device presence. Configuration: To use the DD-WRT tracker you will need to add something like the following -to your config/configuration.yaml +to your configuration.yaml file. device_tracker: platform: ddwrt @@ -64,7 +63,8 @@ def get_scanner(hass, config): # pylint: disable=too-many-instance-attributes class DdWrtDeviceScanner(object): - """ This class queries a wireless router running DD-WRT firmware + """ + This class queries a wireless router running DD-WRT firmware for connected devices. Adapted from Tomato scanner. """ @@ -85,8 +85,9 @@ class DdWrtDeviceScanner(object): self.success_init = data is not None def scan_devices(self): - """ Scans for new devices and return a - list containing found device ids. """ + """ + Scans for new devices and return a list containing found device ids. + """ self._update_info() @@ -124,8 +125,10 @@ class DdWrtDeviceScanner(object): @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): - """ Ensures the information from the DD-WRT router is up to date. - Returns boolean if scanning successful. """ + """ + Ensures the information from the DD-WRT router is up to date. + Returns boolean if scanning successful. + """ if not self.success_init: return False @@ -163,7 +166,7 @@ class DdWrtDeviceScanner(object): return False def get_ddwrt_data(self, url): - """ Retrieve data from DD-WRT and return parsed result. """ + """ Retrieve data from DD-WRT and return parsed result. """ try: response = requests.get( url, diff --git a/homeassistant/components/device_tracker/luci.py b/homeassistant/components/device_tracker/luci.py index 893c9070526..4cbc6a2d492 100644 --- a/homeassistant/components/device_tracker/luci.py +++ b/homeassistant/components/device_tracker/luci.py @@ -1,18 +1,16 @@ """ homeassistant.components.device_tracker.luci ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Device tracker platform that supports scanning a OpenWRT router for device presence. - It's required that the luci RPC package is installed on the OpenWRT router: # opkg install luci-mod-rpc Configuration: To use the Luci tracker you will need to add something like the following -to your config/configuration.yaml +to your configuration.yaml file. device_tracker: platform: luci @@ -66,7 +64,8 @@ def get_scanner(hass, config): # pylint: disable=too-many-instance-attributes class LuciDeviceScanner(object): - """ This class queries a wireless router running OpenWrt firmware + """ + This class queries a wireless router running OpenWrt firmware for connected devices. Adapted from Tomato scanner. # opkg install luci-mod-rpc @@ -95,8 +94,9 @@ class LuciDeviceScanner(object): self.success_init = self.token is not None def scan_devices(self): - """ Scans for new devices and return a - list containing found device ids. """ + """ + Scans for new devices and return a list containing found device ids. + """ self._update_info() @@ -124,8 +124,10 @@ class LuciDeviceScanner(object): @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): - """ Ensures the information from the Luci router is up to date. - Returns boolean if scanning successful. """ + """ + Ensures the information from the Luci router is up to date. + Returns boolean if scanning successful. + """ if not self.success_init: return False @@ -179,6 +181,6 @@ def _req_json_rpc(url, method, *args, **kwargs): def _get_token(host, username, password): - """ Get authentication token for the given host+username+password """ + """ Get authentication token for the given host+username+password. """ url = 'http://{}/cgi-bin/luci/rpc/auth'.format(host) return _req_json_rpc(url, 'login', username, password) diff --git a/homeassistant/components/device_tracker/netgear.py b/homeassistant/components/device_tracker/netgear.py index 346fbb37d37..88fd7aed78a 100644 --- a/homeassistant/components/device_tracker/netgear.py +++ b/homeassistant/components/device_tracker/netgear.py @@ -1,14 +1,13 @@ """ homeassistant.components.device_tracker.netgear ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Device tracker platform that supports scanning a Netgear router for device presence. Configuration: To use the Netgear tracker you will need to add something like the following -to your config/configuration.yaml +to your configuration.yaml file. device_tracker: platform: netgear @@ -90,8 +89,9 @@ class NetgearDeviceScanner(object): _LOGGER.error("Failed to Login") def scan_devices(self): - """ Scans for new devices and return a - list containing found device ids. """ + """ + Scans for new devices and return a list containing found device ids. + """ self._update_info() return (device.mac for device in self.last_results) @@ -106,8 +106,10 @@ class NetgearDeviceScanner(object): @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): - """ Retrieves latest information from the Netgear router. - Returns boolean if scanning successful. """ + """ + Retrieves latest information from the Netgear router. + Returns boolean if scanning successful. + """ if not self.success_init: return diff --git a/homeassistant/components/device_tracker/nmap_tracker.py b/homeassistant/components/device_tracker/nmap_tracker.py index 484574b312f..5c619e001a3 100644 --- a/homeassistant/components/device_tracker/nmap_tracker.py +++ b/homeassistant/components/device_tracker/nmap_tracker.py @@ -1,13 +1,12 @@ """ homeassistant.components.device_tracker.nmap ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Device tracker platform that supports scanning a network with nmap. Configuration: To use the nmap tracker you will need to add something like the following -to your config/configuration.yaml +to your configuration.yaml file. device_tracker: platform: nmap_tracker @@ -74,7 +73,7 @@ def _arp(ip_address): class NmapDeviceScanner(object): - """ This class scans for devices using nmap """ + """ This class scans for devices using nmap. """ def __init__(self, config): self.last_results = [] @@ -87,8 +86,9 @@ class NmapDeviceScanner(object): _LOGGER.info("nmap scanner initialized") def scan_devices(self): - """ Scans for new devices and return a - list containing found device ids. """ + """ + Scans for new devices and return a list containing found device ids. + """ self._update_info() @@ -107,8 +107,10 @@ class NmapDeviceScanner(object): @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): - """ Scans the network for devices. - Returns boolean if scanning successful. """ + """ + Scans the network for devices. + Returns boolean if scanning successful. + """ _LOGGER.info("Scanning") from nmap import PortScanner, PortScannerError diff --git a/homeassistant/components/device_tracker/thomson.py b/homeassistant/components/device_tracker/thomson.py index ffe1a7f64c2..408daa94d81 100644 --- a/homeassistant/components/device_tracker/thomson.py +++ b/homeassistant/components/device_tracker/thomson.py @@ -9,7 +9,7 @@ This device tracker needs telnet to be enabled on the router. Configuration: To use the THOMSON tracker you will need to add something like the following -to your config/configuration.yaml +to your configuration.yaml file. device_tracker: platform: thomson @@ -71,7 +71,8 @@ def get_scanner(hass, config): class ThomsonDeviceScanner(object): - """ This class queries a router running THOMSON firmware + """ + This class queries a router running THOMSON firmware for connected devices. Adapted from ASUSWRT scanner. """ @@ -107,8 +108,10 @@ class ThomsonDeviceScanner(object): @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): - """ Ensures the information from the THOMSON router is up to date. - Returns boolean if scanning successful. """ + """ + Ensures the information from the THOMSON router is up to date. + Returns boolean if scanning successful. + """ if not self.success_init: return False @@ -125,7 +128,7 @@ class ThomsonDeviceScanner(object): return True def get_thomson_data(self): - """ Retrieve data from THOMSON and return parsed result. """ + """ Retrieve data from THOMSON and return parsed result. """ try: telnet = telnetlib.Telnet(self.host) telnet.read_until(b'Username : ') diff --git a/homeassistant/components/device_tracker/tomato.py b/homeassistant/components/device_tracker/tomato.py index 1a189a08396..a23b7b80ff0 100644 --- a/homeassistant/components/device_tracker/tomato.py +++ b/homeassistant/components/device_tracker/tomato.py @@ -1,14 +1,13 @@ """ homeassistant.components.device_tracker.tomato ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Device tracker platform that supports scanning a Tomato router for device presence. Configuration: To use the Tomato tracker you will need to add something like the following -to your config/configuration.yaml +to your configuration.yaml file. device_tracker: platform: tomato diff --git a/homeassistant/components/device_tracker/tplink.py b/homeassistant/components/device_tracker/tplink.py index 8e556e47e8a..6b12000cf45 100755 --- a/homeassistant/components/device_tracker/tplink.py +++ b/homeassistant/components/device_tracker/tplink.py @@ -1,14 +1,13 @@ """ homeassistant.components.device_tracker.tplink ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Device tracker platform that supports scanning a TP-Link router for device presence. Configuration: To use the TP-Link tracker you will need to add something like the following -to your config/configuration.yaml +to your configuration.yaml file. device_tracker: platform: tplink @@ -29,7 +28,6 @@ The username of an user with administrative privileges, usually 'admin'. password *Required The password for your given admin account. - """ import base64 import logging @@ -65,7 +63,8 @@ def get_scanner(hass, config): class TplinkDeviceScanner(object): - """ This class queries a wireless router running TP-Link firmware + """ + This class queries a wireless router running TP-Link firmware for connected devices. """ @@ -85,8 +84,9 @@ class TplinkDeviceScanner(object): self.success_init = self._update_info() def scan_devices(self): - """ Scans for new devices and return a - list containing found device ids. """ + """ + Scans for new devices and return a list containing found device ids. + """ self._update_info() @@ -94,15 +94,18 @@ class TplinkDeviceScanner(object): # pylint: disable=no-self-use def get_device_name(self, device): - """ The TP-Link firmware doesn't save the name of the wireless - device. """ + """ + The TP-Link firmware doesn't save the name of the wireless device. + """ return None @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): - """ Ensures the information from the TP-Link router is up to date. - Returns boolean if scanning successful. """ + """ + Ensures the information from the TP-Link router is up to date. + Returns boolean if scanning successful. + """ with self.lock: _LOGGER.info("Loading wireless clients...") @@ -122,28 +125,33 @@ class TplinkDeviceScanner(object): class Tplink2DeviceScanner(TplinkDeviceScanner): - """ This class queries a wireless router running newer version of TP-Link + """ + This class queries a wireless router running newer version of TP-Link firmware for connected devices. """ def scan_devices(self): - """ Scans for new devices and return a - list containing found device ids. """ + """ + Scans for new devices and return a list containing found device ids. + """ self._update_info() return self.last_results.keys() # pylint: disable=no-self-use def get_device_name(self, device): - """ The TP-Link firmware doesn't save the name of the wireless - device. """ + """ + The TP-Link firmware doesn't save the name of the wireless device. + """ return self.last_results.get(device) @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): - """ Ensures the information from the TP-Link router is up to date. - Returns boolean if scanning successful. """ + """ + Ensures the information from the TP-Link router is up to date. + Returns boolean if scanning successful. + """ with self.lock: _LOGGER.info("Loading wireless clients...")