From 3c01cd2678d6c408918f25223beec21e6ca513cf Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Tue, 15 Jan 2019 11:09:49 -0500 Subject: [PATCH] Set timeout for IOT api calls Set timeout to 1.25 secs for IOT API - Some commands (Move) never return a status, so this allows things to continue moving along without waiting too long --- sucks/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sucks/__init__.py b/sucks/__init__.py index 272763f..cbd0026 100644 --- a/sucks/__init__.py +++ b/sucks/__init__.py @@ -209,8 +209,18 @@ class EcoVacsAPI: params = {} params.update(args) + url = (EcoVacsAPI.PORTAL_URL_FORMAT + "/" + api).format(continent=self.continent, **self.meta) - response = requests.post(url, json=params) + response = None + if not api == self.IOTDEVMANAGERAPI: + response = requests.post(url, json=params) + else: + try: #IOT Device sometimes doesnt provide a response depending on command, reduce timeout to 1.25 to accomodate and make requests faster + response = requests.post(url, json=params, timeout=1.25) #May think about having timeout as an arg that could be provided in the future + except requests.exceptions.ReadTimeout: + _LOGGER.debug("call to {} failed with ReadTimeout".format(function)) + return {} + json = response.json() _LOGGER.debug("got {}".format(json)) if api == self.USERSAPI: