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
This commit is contained in:
Brian Martin
2019-01-15 11:09:49 -05:00
parent 335ac6a7e1
commit 3c01cd2678
+10
View File
@@ -209,8 +209,18 @@ class EcoVacsAPI:
params = {}
params.update(args)
url = (EcoVacsAPI.PORTAL_URL_FORMAT + "/" + api).format(continent=self.continent, **self.meta)
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: