Skip to content

Commit

Permalink
Refactor response timeout and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
rrooggiieerr committed May 17, 2023
1 parent 89d76e8 commit 3e244ae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion benqprojector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
@author: Rogier van Staveren
"""
__version__ = "0.0.12.2"
__version__ = "0.0.12.3"

from benqprojector.benqprojector import BAUD_RATES, BenQProjector
13 changes: 9 additions & 4 deletions benqprojector/benqprojector.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def __init__(self, command=None, action=None, response=None):

class ResponseTimeoutError(BenQProjectorError):
"""
Invalid response error.
Response timeout error.
If the response format does not match the expected format.
If the response takes to long to receive.
"""

def __init__(self, command=None, action=None, response=None):
Expand Down Expand Up @@ -414,7 +414,7 @@ def _wait_for_prompt(self) -> bool:
def _read_response(self) -> str:
response = b""
last_response = datetime.now()
while (datetime.now() - last_response).total_seconds() < _RESPONSE_TIMEOUT:
while True:
_response = self._connection.readline()
if len(_response) > 0:
response += _response
Expand All @@ -427,7 +427,12 @@ def _read_response(self) -> str:
return response
last_response = datetime.now()

raise ResponseTimeoutError(response = response)
if (datetime.now() - last_response).total_seconds() > _RESPONSE_TIMEOUT:
logger.error("Timeout while waiting for response")
raise ResponseTimeoutError(response = response)

logger.debug("Waiting for response")
self._sleep(0.01)

def _send_raw_command(self, command: str) -> str:
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "benqprojector"
version = "0.0.12.2"
version = "0.0.12.3"
license = {text = "Apache-2.0"}
authors = [
{ name="Rogier van Staveren" }
Expand Down

0 comments on commit 3e244ae

Please sign in to comment.