update header
parent
21e2898868
commit
8f5a9859c3
|
@ -1,4 +1,35 @@
|
||||||
""" Supports scanning a DD-WRT router. """
|
"""
|
||||||
|
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
|
||||||
|
|
||||||
|
device_tracker:
|
||||||
|
platform: ddwrt
|
||||||
|
host: YOUR_ROUTER_IP
|
||||||
|
username: YOUR_ADMIN_USERNAME
|
||||||
|
password: YOUR_ADMIN_PASSWORD
|
||||||
|
|
||||||
|
Variables:
|
||||||
|
|
||||||
|
host
|
||||||
|
*Required
|
||||||
|
The IP address of your router, e.g. 192.168.1.1.
|
||||||
|
|
||||||
|
username
|
||||||
|
*Required
|
||||||
|
The username of an user with administrative privileges, usually 'admin'.
|
||||||
|
|
||||||
|
password
|
||||||
|
*Required
|
||||||
|
The password for your given admin account.
|
||||||
|
"""
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import re
|
import re
|
||||||
|
@ -20,7 +51,7 @@ _DDWRT_DATA_REGEX = re.compile(r'\{(\w+)::([^\}]*)\}')
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def get_scanner(hass, config):
|
def get_scanner(hass, config):
|
||||||
""" Validates config and returns a DdWrt scanner. """
|
""" Validates config and returns a DD-WRT scanner. """
|
||||||
if not validate_config(config,
|
if not validate_config(config,
|
||||||
{DOMAIN: [CONF_HOST, CONF_USERNAME, CONF_PASSWORD]},
|
{DOMAIN: [CONF_HOST, CONF_USERNAME, CONF_PASSWORD]},
|
||||||
_LOGGER):
|
_LOGGER):
|
||||||
|
@ -93,7 +124,7 @@ class DdWrtDeviceScanner(object):
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_SCANS)
|
@Throttle(MIN_TIME_BETWEEN_SCANS)
|
||||||
def _update_info(self):
|
def _update_info(self):
|
||||||
""" Ensures the information from the DdWrt router is up to date.
|
""" Ensures the information from the DD-WRT router is up to date.
|
||||||
Returns boolean if scanning successful. """
|
Returns boolean if scanning successful. """
|
||||||
if not self.success_init:
|
if not self.success_init:
|
||||||
return False
|
return False
|
||||||
|
@ -111,8 +142,8 @@ class DdWrtDeviceScanner(object):
|
||||||
self.last_results = []
|
self.last_results = []
|
||||||
active_clients = data.get('active_wireless', None)
|
active_clients = data.get('active_wireless', None)
|
||||||
if active_clients:
|
if active_clients:
|
||||||
# This is really lame, instead of using JSON the ddwrt UI
|
# This is really lame, instead of using JSON the DD-WRT UI
|
||||||
# uses it's own data format for some reason and then
|
# uses its own data format for some reason and then
|
||||||
# regex's out values so I guess I have to do the same,
|
# regex's out values so I guess I have to do the same,
|
||||||
# LAME!!!
|
# LAME!!!
|
||||||
|
|
||||||
|
@ -132,7 +163,7 @@ class DdWrtDeviceScanner(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_ddwrt_data(self, url):
|
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:
|
try:
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
url,
|
url,
|
||||||
|
@ -154,8 +185,7 @@ class DdWrtDeviceScanner(object):
|
||||||
|
|
||||||
|
|
||||||
def _parse_ddwrt_response(data_str):
|
def _parse_ddwrt_response(data_str):
|
||||||
""" Parse the awful DD-WRT data format, why didn't they use JSON????.
|
""" Parse the DD-WRT data format. """
|
||||||
This code is a python version of how they are parsing in the JS """
|
|
||||||
return {
|
return {
|
||||||
key: val for key, val in _DDWRT_DATA_REGEX
|
key: val for key, val in _DDWRT_DATA_REGEX
|
||||||
.findall(data_str)}
|
.findall(data_str)}
|
||||||
|
|
Loading…
Reference in New Issue