fix timout calculation
This commit is contained in:
@@ -17,8 +17,10 @@ class AsyncStream():
|
|||||||
'''maximum processing time for a received msg in sec'''
|
'''maximum processing time for a received msg in sec'''
|
||||||
MAX_START_TIME = 400
|
MAX_START_TIME = 400
|
||||||
'''maximum time without a received msg in sec'''
|
'''maximum time without a received msg in sec'''
|
||||||
MAX_IDLE_TIME = 90
|
MAX_INV_IDLE_TIME = 90
|
||||||
'''maximum time without a received msg in sec'''
|
'''maximum time without a received msg from the inverter in sec'''
|
||||||
|
MAX_CLOUD_IDLE_TIME = 360
|
||||||
|
'''maximum time without a received msg from cloud side in sec'''
|
||||||
|
|
||||||
def __init__(self, reader: StreamReader, writer: StreamWriter,
|
def __init__(self, reader: StreamReader, writer: StreamWriter,
|
||||||
addr) -> None:
|
addr) -> None:
|
||||||
@@ -32,11 +34,15 @@ class AsyncStream():
|
|||||||
self.proc_start = None # start processing start timestamp
|
self.proc_start = None # start processing start timestamp
|
||||||
self.proc_max = 0
|
self.proc_max = 0
|
||||||
|
|
||||||
def __timeout(self):
|
def __timeout(self) -> int:
|
||||||
if self.state == State.init:
|
if self.state == State.init:
|
||||||
self.MAX_START_TIME
|
to = self.MAX_START_TIME
|
||||||
else:
|
else:
|
||||||
self.MAX_IDLE_TIME
|
if self.server_side:
|
||||||
|
to = self.MAX_INV_IDLE_TIME
|
||||||
|
else:
|
||||||
|
to = self.MAX_CLOUD_IDLE_TIME
|
||||||
|
return to
|
||||||
|
|
||||||
async def server_loop(self, addr: str) -> None:
|
async def server_loop(self, addr: str) -> None:
|
||||||
'''Loop for receiving messages from the inverter (server-side)'''
|
'''Loop for receiving messages from the inverter (server-side)'''
|
||||||
@@ -92,9 +98,9 @@ class AsyncStream():
|
|||||||
if proc > self.proc_max:
|
if proc > self.proc_max:
|
||||||
self.proc_max = proc
|
self.proc_max = proc
|
||||||
self.proc_start = None
|
self.proc_start = None
|
||||||
|
dead_conn_to = self.__timeout()
|
||||||
await asyncio.wait_for(self.__async_read(),
|
await asyncio.wait_for(self.__async_read(),
|
||||||
self.__timeout())
|
dead_conn_to)
|
||||||
|
|
||||||
if self.unique_id:
|
if self.unique_id:
|
||||||
await self.async_write()
|
await self.async_write()
|
||||||
@@ -103,7 +109,8 @@ class AsyncStream():
|
|||||||
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
logger.warning(f'[{self.node_id}:{self.conn_no}] Dead '
|
logger.warning(f'[{self.node_id}:{self.conn_no}] Dead '
|
||||||
f'connection timeout for {self.l_addr}')
|
f'connection timeout ({dead_conn_to}s) '
|
||||||
|
f'for {self.l_addr}')
|
||||||
await self.disc()
|
await self.disc()
|
||||||
self.close()
|
self.close()
|
||||||
return self
|
return self
|
||||||
|
|||||||
Reference in New Issue
Block a user