From 020fc731dd3575a62928e920b75d71224c6e082b Mon Sep 17 00:00:00 2001 From: Stefan Allius Date: Sun, 30 Mar 2025 20:12:06 +0200 Subject: [PATCH] move forward_at_cmd_resp into InfosG3P class - the variable is shared between the two connections of an inverter. One is for the TSUN cloud and the other for the device. --- app/src/gen3plus/infos_g3p.py | 10 +++++++++- app/src/gen3plus/solarman_v5.py | 12 ++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/gen3plus/infos_g3p.py b/app/src/gen3plus/infos_g3p.py index 4cbe08c..1cbbc18 100644 --- a/app/src/gen3plus/infos_g3p.py +++ b/app/src/gen3plus/infos_g3p.py @@ -193,11 +193,19 @@ class RegisterSel: class InfosG3P(Infos): - __slots__ = ('client_mode', ) + __slots__ = ('client_mode', 'forward_at_cmd_resp') def __init__(self, client_mode: bool): super().__init__() self.client_mode = client_mode + # shared value between both inverter connections + self.forward_at_cmd_resp = False + '''Flag if response for the last at command must be send to the cloud. + + False: send result only to the MQTT broker, cause the AT+ command + came from there + True: send response packet to the cloud, cause the AT+ command + came from the cloud''' self.set_db_def_value(Register.MANUFACTURER, 'TSUN') self.set_db_def_value(Register.EQUIPMENT_MODEL, 'TSOL-MSxx00') self.set_db_def_value(Register.CHIP_TYPE, 'IGEN TECH') diff --git a/app/src/gen3plus/solarman_v5.py b/app/src/gen3plus/solarman_v5.py index 9b4bee8..3fb2205 100644 --- a/app/src/gen3plus/solarman_v5.py +++ b/app/src/gen3plus/solarman_v5.py @@ -259,7 +259,6 @@ class SolarmanV5(SolarmanBase): mb_timeout=8) self.db = InfosG3P(client_mode) - self.forward_at_cmd_resp = False self.no_forwarding = False '''not allowed to connect to TSUN cloud by connection type''' self.establish_inv_emu = False @@ -519,7 +518,7 @@ class SolarmanV5(SolarmanBase): await Proxy.mqtt.publish(f'{Proxy.entity_prfx}{node_id}{key}', data_json) # noqa: E501 return - self.forward_at_cmd_resp = False + self.db.forward_at_cmd_resp = False self._build_header(0x4510) self.ifc.tx_add(struct.pack(f' int: ftype = self.ifc.rx_peek()[self.header_len] - if ftype == self.AT_CMD: - if self.forward_at_cmd_resp: + if ftype == self.AT_CMD or \ + ftype == self.AT_CMD_RSP: + if self.db.forward_at_cmd_resp: return logging.INFO return logging.DEBUG elif ftype == self.MB_RTU_CMD \ @@ -680,7 +680,7 @@ class SolarmanV5(SolarmanBase): ftype = data[0] if ftype == self.AT_CMD or \ ftype == self.AT_CMD_RSP: - if not self.forward_at_cmd_resp: + if not self.db.forward_at_cmd_resp: data_json = data[14:].decode("utf-8") node_id = self.node_id key = 'at_resp'