mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Better documentation of TomatoDeviceScanner
This commit is contained in:
parent
97e82b3808
commit
9026a78a66
@ -179,12 +179,12 @@ class TomatoDeviceScanner(object):
|
|||||||
|
|
||||||
def _update_tomato_info(self):
|
def _update_tomato_info(self):
|
||||||
""" Ensures the information from the Tomato router is up to date.
|
""" Ensures the information from the Tomato router is up to date.
|
||||||
Returns boolean if successful. """
|
Returns boolean if scanning successful. """
|
||||||
|
|
||||||
|
self.lock.acquire()
|
||||||
|
|
||||||
# if date_updated is not defined (update has never ran) or the date is too old we scan for new data
|
# if date_updated is not defined (update has never ran) or the date is too old we scan for new data
|
||||||
if self.date_updated is None or datetime.now() - self.date_updated > TOMATO_MIN_TIME_BETWEEN_SCANS:
|
if self.date_updated is None or datetime.now() - self.date_updated > TOMATO_MIN_TIME_BETWEEN_SCANS:
|
||||||
self.lock.acquire()
|
|
||||||
|
|
||||||
self.logger.info("Tomato:Scanning")
|
self.logger.info("Tomato:Scanning")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -192,28 +192,8 @@ class TomatoDeviceScanner(object):
|
|||||||
data={'_http_id':self.http_id, 'exec':'devlist'},
|
data={'_http_id':self.http_id, 'exec':'devlist'},
|
||||||
auth=requests.auth.HTTPBasicAuth(self.username, self.password))
|
auth=requests.auth.HTTPBasicAuth(self.username, self.password))
|
||||||
|
|
||||||
"""
|
# Calling and parsing the Tomato api here. We only need the wldev and dhcpd_lease values.
|
||||||
Tomato API:
|
# See http://paulusschoutsen.nl/blog/2013/10/tomato-api-documentation/ for what's going on here.
|
||||||
arplist contains a list of lists with items:
|
|
||||||
- ip (string)
|
|
||||||
- mac (string)
|
|
||||||
- iface (string)
|
|
||||||
|
|
||||||
wldev contains list of lists with items:
|
|
||||||
- iface (string)
|
|
||||||
- mac (string)
|
|
||||||
- rssi (int)
|
|
||||||
- tx (int)
|
|
||||||
- rx (int)
|
|
||||||
- quality (int)
|
|
||||||
- unknown_num (int)
|
|
||||||
|
|
||||||
dhcpd_lease contains a list of lists with items:
|
|
||||||
- name (string)
|
|
||||||
- ip (string)
|
|
||||||
- mac (string)
|
|
||||||
- lease_age (string)
|
|
||||||
"""
|
|
||||||
self.last_results = {param: json.loads(value.replace("'",'"'))
|
self.last_results = {param: json.loads(value.replace("'",'"'))
|
||||||
for param, value in re.findall(r"(?P<param>\w*) = (?P<value>.*);", req.text)
|
for param, value in re.findall(r"(?P<param>\w*) = (?P<value>.*);", req.text)
|
||||||
if param in ["wldev","dhcpd_lease"]}
|
if param in ["wldev","dhcpd_lease"]}
|
||||||
@ -234,11 +214,19 @@ class TomatoDeviceScanner(object):
|
|||||||
self.known_devices[mac] = {'name':name, 'track': '0'}
|
self.known_devices[mac] = {'name':name, 'track': '0'}
|
||||||
|
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
self.logger.exception("Tomato:Scanning failed")
|
# If we could not connect to the router
|
||||||
|
self.logger.exception("Tomato:Failed to connect to the router")
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
# If json decoder could not parse the response
|
||||||
|
self.logger.exception("Tomato:Failed to parse response from router")
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except IOError:
|
except IOError:
|
||||||
|
# If scanning was successful but we failed to be able to write to the known devices file
|
||||||
self.logger.exception("Tomato:Updating {} failed".format(TOMATO_KNOWN_DEVICES_FILE))
|
self.logger.exception("Tomato:Updating {} failed".format(TOMATO_KNOWN_DEVICES_FILE))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -246,5 +234,9 @@ class TomatoDeviceScanner(object):
|
|||||||
finally:
|
finally:
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
|
else:
|
||||||
|
# We acquired the lock before the IF check, release it before we return True
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user