Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyrisco/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from pyrisco.local import RiscoLocal
from pyrisco.cloud import RiscoCloud
from .common import CannotConnectError, OperationError, UnauthorizedError
from .common import CannotConnectError, ConnectionError, OperationError, UnauthorizedError
2 changes: 2 additions & 0 deletions pyrisco/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class UnauthorizedError(Exception):
class CannotConnectError(Exception):
"""Exception to indicate an error in authorization."""

class ConnectionError(Exception):
"""Exception to indicate an error with the connection."""

class OperationError(Exception):
"""Exception to indicate an error in operation."""
4 changes: 2 additions & 2 deletions pyrisco/local/risco_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .zone import Zone
from .system import System
from .risco_socket import RiscoSocket
from pyrisco.common import OperationError, GROUP_ID_TO_NAME
from pyrisco.common import OperationError, ConnectionError, GROUP_ID_TO_NAME


class RiscoLocal:
Expand Down Expand Up @@ -204,7 +204,7 @@ async def _listen(self, queue):
item = await queue.get()
if isinstance(item, Exception):
self._error(item)
if isinstance(item, ConnectionResetError):
if isinstance(item, ConnectionError):
await self.disconnect()
break
continue
Expand Down
23 changes: 16 additions & 7 deletions pyrisco/local/risco_socket.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from .risco_crypt import RiscoCrypt, ESCAPED_END, END
from pyrisco.common import UnauthorizedError, CannotConnectError, OperationError
from pyrisco.common import UnauthorizedError, CannotConnectError, ConnectionError, OperationError

MIN_CMD_ID = 1
MAX_CMD_ID = 49
Expand All @@ -12,7 +12,8 @@ def __init__(self, host, port, code, **kwargs):
self._code = code
self._encoding = kwargs.get('encoding', 'utf-8')
self._max_concurrency = kwargs.get('concurrency', 4)
self._communication_delay = kwargs.get('communication_delay', 0)
self._communication_delay = kwargs.get('communication_delay', 1)
self._max_timeout_keep_alive_subseq = kwargs.get('max_timeout_subseq', 3)
self._reader = None
self._writer = None
self._crypt = None
Expand Down Expand Up @@ -77,9 +78,6 @@ async def _listen(self):
future.set_result(command)
else:
await self._handle_incoming(cmd_id, command, crc)
except ConnectionResetError as error:
await self._queue.put(error)
break
except Exception as error:
await self._queue.put(error)

Expand All @@ -89,8 +87,19 @@ async def _keep_alive(self):
try:
await self.send_result_command("CLOCK")
except OperationError as error:
await self._queue.put(error)

timeout_keep_alive_subseq += 1
try:
if self._max_timeout_keep_alive_subseq > 0:
if timeout_keep_alive_subseq >= self._max_timeout_keep_alive_subseq:
raise ConnectionError
except Exception as error:
await self._queue.put(error)
break
else:
await self._queue.put(error)
else:
timeout_keep_alive_subseq = 0

await asyncio.sleep(5)

async def send_ack_command(self, command):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
EMAIL = 'onfreund@gmail.com'
AUTHOR = 'On Freund'
REQUIRES_PYTHON = '>=3.7.0'
VERSION = '0.6.4'
VERSION = '0.6.5'

REQUIRED = ['aiohttp']

Expand Down