S allius/issue131 (#132)

* Make __publish_outstanding_mqtt public

* update proxy counter

- on client mode connection establishment or
  disconnecting update tje counection counter
This commit is contained in:
Stefan Allius
2024-07-23 21:54:01 +02:00
committed by GitHub
parent dc4728122e
commit 7f81799dd9
2 changed files with 5 additions and 3 deletions

View File

@@ -44,7 +44,7 @@ class AsyncStream():
to = self.MAX_CLOUD_IDLE_TIME
return to
async def __publish_outstanding_mqtt(self):
async def publish_outstanding_mqtt(self):
'''Publish all outstanding MQTT topics'''
try:
if self.unique_id:
@@ -58,10 +58,10 @@ class AsyncStream():
logger.info(f'[{self.node_id}:{self.conn_no}] '
f'Accept connection from {addr}')
self.inc_counter('Inverter_Cnt')
await self.__publish_outstanding_mqtt()
await self.publish_outstanding_mqtt()
await self.loop()
self.dec_counter('Inverter_Cnt')
await self.__publish_outstanding_mqtt()
await self.publish_outstanding_mqtt()
logger.info(f'[{self.node_id}:{self.conn_no}] Server loop stopped for'
f' r{self.r_addr}')

View File

@@ -24,10 +24,12 @@ class ModbusConn():
logging.info(f'[{self.stream.node_id}:{self.stream.conn_no}] '
f'Connected to {self.addr}')
self.stream.inc_counter('Inverter_Cnt')
await self.stream.publish_outstanding_mqtt()
return self.stream
async def __aexit__(self, exc_type, exc, tb):
self.stream.dec_counter('Inverter_Cnt')
await self.stream.publish_outstanding_mqtt()
class ModbusTcp():