Skip to content

Commit d43b78f

Browse files
committed
Remove lock on request
Reverted the lock for request back, issue with this is that it might block request for open/close if getting status is timing out.
1 parent 59f4345 commit d43b78f

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

pymyq/api.py

+27-29
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def __init__(self, brand: str, websession: ClientSession) -> None:
6262
self._last_update = None
6363
self._websession = websession
6464
self._update_lock = asyncio.Lock()
65-
self._request_lock = asyncio.Lock()
6665

6766
async def _request(
6867
self,
@@ -88,34 +87,33 @@ async def _request(
8887

8988
start_request_time = datetime.time(datetime.now())
9089
_LOGGER.debug('%s Initiating request to %s', start_request_time, url)
91-
async with self._request_lock:
92-
timeout = DEFAULT_TIMEOUT
93-
# Repeat twice amount of max requests retries for timeout errors.
94-
for attempt in range(0, (DEFAULT_REQUEST_RETRIES * 2) - 1):
95-
try:
96-
async with self._websession.request(
97-
method, url, headers=headers, params=params,
98-
data=data, json=json, timeout=timeout,
99-
**kwargs) as resp:
100-
resp.raise_for_status()
101-
return await resp.json(content_type=None)
102-
except asyncio.TimeoutError:
103-
timeout = timeout * 2
104-
_LOGGER.warning('%s Timeout requesting from %s',
105-
start_request_time, endpoint)
106-
except ClientError as err:
107-
if attempt == DEFAULT_REQUEST_RETRIES - 1:
108-
raise RequestError('{} Client Error while requesting '
109-
'data from {}: {}'.format(
110-
start_request_time, endpoint,
111-
err))
112-
113-
_LOGGER.warning('%s Error requesting from %s; retrying: '
114-
'%s', start_request_time, endpoint, err)
115-
await asyncio.sleep(5)
116-
117-
raise RequestError('{} Constant timeouts while requesting data '
118-
'from {}'.format(start_request_time, endpoint))
90+
timeout = DEFAULT_TIMEOUT
91+
# Repeat twice amount of max requests retries for timeout errors.
92+
for attempt in range(0, (DEFAULT_REQUEST_RETRIES * 2) - 1):
93+
try:
94+
async with self._websession.request(
95+
method, url, headers=headers, params=params,
96+
data=data, json=json, timeout=timeout,
97+
**kwargs) as resp:
98+
resp.raise_for_status()
99+
return await resp.json(content_type=None)
100+
except asyncio.TimeoutError:
101+
timeout = timeout * 2
102+
_LOGGER.warning('%s Timeout requesting from %s',
103+
start_request_time, endpoint)
104+
except ClientError as err:
105+
if attempt == DEFAULT_REQUEST_RETRIES - 1:
106+
raise RequestError('{} Client Error while requesting '
107+
'data from {}: {}'.format(
108+
start_request_time, endpoint,
109+
err))
110+
111+
_LOGGER.warning('%s Error requesting from %s; retrying: '
112+
'%s', start_request_time, endpoint, err)
113+
await asyncio.sleep(5)
114+
115+
raise RequestError('{} Constant timeouts while requesting data '
116+
'from {}'.format(start_request_time, endpoint))
119117

120118
async def _update_device_state(self) -> None:
121119
async with self._update_lock:

0 commit comments

Comments
 (0)