refactor close handling

This commit is contained in:
Stefan Allius
2024-10-01 19:50:42 +02:00
parent a1441fb4fd
commit 39aba31bbd
15 changed files with 173 additions and 264 deletions

View File

@@ -27,6 +27,7 @@ class ModbusConn():
reader, writer = await connection
self.inverter = InverterG3P(reader, writer, self.addr,
client_mode=True)
self.inverter.__enter__()
stream = self.inverter.local.stream
logging.info(f'[{stream.node_id}:{stream.conn_no}] '
f'Connected to {self.addr}')
@@ -37,7 +38,7 @@ class ModbusConn():
async def __aexit__(self, exc_type, exc, tb):
Infos.dec_counter('Inverter_Cnt')
await self.inverter.local.ifc.publish_outstanding_mqtt()
self.inverter.close()
self.inverter.__exit__(exc_type, exc, tb)
class ModbusTcp():