From 7443a5f9636fdc913551c403e24f448f7b0e78d8 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 23 Oct 2013 23:58:48 +0100 Subject: [PATCH] Timeout if Tomato router does not respond for 1 sec --- homeassistant/observers.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/observers.py b/homeassistant/observers.py index 1f00f76798d..ab4bac20f4b 100644 --- a/homeassistant/observers.py +++ b/homeassistant/observers.py @@ -318,7 +318,7 @@ class TomatoDeviceScanner(object): self.logger.info("Tomato:Scanning") try: - response = requests.Session().send(self.req) + response = requests.Session().send(self.req, timeout=1) # Calling and parsing the Tomato api here. We only need the # wldev and dhcpd_lease values. For API description see: @@ -343,11 +343,19 @@ class TomatoDeviceScanner(object): return False - except requests.ConnectionError: + except requests.exceptions.ConnectionError: # We get this if we could not connect to the router or # an invalid http_id was supplied self.logger.exception(("Tomato:Failed to connect to the router" - "or invalid http_id supplied")) + " or invalid http_id supplied")) + + return False + + except requests.exceptions.Timeout: + # We get this if we could not connect to the router or + # an invalid http_id was supplied + self.logger.exception(("Tomato:Connection to the router " + "timed out")) return False