8
8
9
9
# API Link: https://documenter.getpostman.com/view/6223391/S1Lu2pSf
10
10
BASEURL = 'https://api.goslide.io/api/{}'
11
+ DEFAULT_TIMEOUT = 30
11
12
12
13
13
14
class GoSlideCloud :
14
15
"""API Wrapper for the Go Slide devices."""
15
16
16
- def __init__ (self , username , password ):
17
+ def __init__ (self , username , password , timeout = DEFAULT_TIMEOUT ):
17
18
"""Create the object with required parameters."""
18
19
self ._username = username
19
20
self ._password = password
21
+ self ._timeout = timeout
20
22
self ._authenticated = False
21
23
self ._accesstoken = ''
22
24
self ._authfailed = False
@@ -35,6 +37,9 @@ async def _dorequest(self, reqtype, urlsuffix, data=None):
35
37
_LOGGER .debug ("REQ: API=%s, type=%s, data=%s" ,
36
38
BASEURL .format (urlsuffix ), reqtype , json .dumps (data ))
37
39
40
+ # Set a reasonable timeout, otherwise it can take > 300 seconds
41
+ atimeout = aiohttp .ClientTimeout (total = self ._timeout )
42
+
38
43
# Known error codes from the Cloud API:
39
44
# 401 - Authentication failed
40
45
# 403 - Forbidden, most likely we want to control a slide
@@ -47,7 +52,8 @@ async def _dorequest(self, reqtype, urlsuffix, data=None):
47
52
async with aiohttp .request (reqtype ,
48
53
BASEURL .format (urlsuffix ),
49
54
headers = headers ,
50
- json = data ) as resp :
55
+ json = data ,
56
+ timeout = atimeout ) as resp :
51
57
if resp .status in [200 , 424 ]:
52
58
textdata = await resp .text ()
53
59
_LOGGER .debug ("RES: API=%s, type=%s, HTTPCode=%s, Data=%s" ,
0 commit comments