split AsyncStream in two classes
This commit is contained in:
@@ -2,10 +2,12 @@ import logging
|
||||
from asyncio import StreamReader, StreamWriter
|
||||
|
||||
if __name__ == "app.src.gen3plus.connection_g3p":
|
||||
from app.src.async_stream import AsyncStream, StreamPtr
|
||||
from app.src.async_stream import AsyncStreamServer
|
||||
from app.src.async_stream import AsyncStreamClient, StreamPtr
|
||||
from app.src.gen3plus.solarman_v5 import SolarmanV5
|
||||
else: # pragma: no cover
|
||||
from async_stream import AsyncStream, StreamPtr
|
||||
from async_stream import AsyncStreamServer
|
||||
from async_stream import AsyncStreamClient, StreamPtr
|
||||
from gen3plus.solarman_v5 import SolarmanV5
|
||||
|
||||
logger = logging.getLogger('conn')
|
||||
@@ -19,10 +21,15 @@ class ConnectionG3P(SolarmanV5):
|
||||
client_mode: bool) -> None:
|
||||
|
||||
self.remote = StreamPtr(rstream)
|
||||
self._ifc = AsyncStream(reader, writer, addr,
|
||||
self.async_publ_mqtt,
|
||||
self.async_create_remote,
|
||||
self.remote)
|
||||
if server_side:
|
||||
self._ifc = AsyncStreamServer(reader, writer, addr,
|
||||
self.async_publ_mqtt,
|
||||
self.async_create_remote,
|
||||
self.remote)
|
||||
else:
|
||||
self._ifc = AsyncStreamClient(reader, writer, addr,
|
||||
self.remote)
|
||||
|
||||
SolarmanV5.__init__(self, server_side, client_mode, self._ifc)
|
||||
|
||||
self.conn_no = self._ifc.get_conn_no()
|
||||
|
||||
@@ -74,7 +74,7 @@ class InverterG3P(Inverter, ConnectionG3P):
|
||||
logging.info(f'[{self.remote.stream.node_id}:'
|
||||
f'{self.remote.stream.conn_no}] '
|
||||
f'Connected to {addr}')
|
||||
asyncio.create_task(self._ifc.client_loop(addr))
|
||||
asyncio.create_task(self.remote.ifc.client_loop(addr))
|
||||
|
||||
except (ConnectionRefusedError, TimeoutError) as error:
|
||||
logging.info(f'{error}')
|
||||
@@ -86,6 +86,9 @@ class InverterG3P(Inverter, ConnectionG3P):
|
||||
|
||||
async def async_publ_mqtt(self) -> None:
|
||||
'''publish data to MQTT broker'''
|
||||
if not self.unique_id:
|
||||
return
|
||||
|
||||
# check if new inverter or collector infos are available or when the
|
||||
# home assistant has changed the status back to online
|
||||
try:
|
||||
@@ -100,7 +103,7 @@ class InverterG3P(Inverter, ConnectionG3P):
|
||||
for key in self.new_data:
|
||||
await self.__async_publ_mqtt_packet(key)
|
||||
for key in Infos.new_stat_data:
|
||||
await self._async_publ_mqtt_proxy_stat(key)
|
||||
await Inverter._async_publ_mqtt_proxy_stat(key)
|
||||
|
||||
except MqttCodeError as error:
|
||||
logging.error(f'Mqtt except: {error}')
|
||||
|
||||
Reference in New Issue
Block a user