Merge branch 'dev-0.12' of https://github.com/s-allius/tsun-gen3-proxy into titan-scan

This commit is contained in:
Stefan Allius
2024-10-16 23:33:06 +02:00
4 changed files with 32 additions and 20 deletions

View File

@@ -135,6 +135,8 @@ class Talent(Message):
self.modbus_polling = inv['modbus_polling']
logger.debug(f'SerialNo {serial_no} allowed! area:{self.sug_area}') # noqa: E501
self.db.set_pv_module_details(inv)
if self.mb:
self.mb.set_node_id(self.node_id)
else:
self.node_id = ''
self.sug_area = ''
@@ -590,8 +592,7 @@ class Talent(Message):
return
for key, update, _ in self.mb.recv_resp(self.db, data[
hdr_len:],
self.node_id):
hdr_len:]):
if update:
self._set_mqtt_timestamp(key, self._utc())
self.new_data[key] = True

View File

@@ -225,6 +225,8 @@ class SolarmanV5(Message):
self.sug_area = inv['suggested_area']
self.modbus_polling = inv['modbus_polling']
self.sensor_list = inv['sensor_list']
if self.mb:
self.mb.set_node_id(self.node_id)
def __set_serial_no(self, snr: int):
'''check the serial number and configure the inverter connection'''
@@ -690,8 +692,7 @@ class SolarmanV5(Message):
f'(reg: 0x{self.mb.last_reg:04x}):',
data[14:], modbus_msg_len)
for key, update, _ in self.mb.recv_resp(self.db, data[14:],
self.node_id):
for key, update, _ in self.mb.recv_resp(self.db, data[14:]):
self.modbus_elms += 1
if update:
if key == 'inverter':

View File

@@ -117,6 +117,9 @@ class Modbus():
while not self.que.empty():
self.que.get_nowait()
def set_node_id(self, node_id: str):
self.node_id = node_id
def build_msg(self, addr: int, func: int, reg: int, val: int,
log_lvl=logging.DEBUG) -> None:
"""Build MODBUS RTU request frame and add it to the tx queue
@@ -160,14 +163,13 @@ class Modbus():
return True
def recv_resp(self, info_db, buf: bytes, node_id: str) -> \
def recv_resp(self, info_db, buf: bytes) -> \
Generator[tuple[str, bool, int | float | str], None, None]:
"""Generator which check and parse a received MODBUS response.
Keyword arguments:
info_db: database for info lockups
buf: received Modbus RTU response frame
node_id: string for logging which identifies the slave
Returns on error and set Self.err to:
1: CRC error
@@ -177,7 +179,6 @@ class Modbus():
5: No MODBUS request pending
"""
# logging.info(f'recv_resp: first byte modbus:{buf[0]} len:{len(buf)}')
self.node_id = node_id
fcode = buf[1]
data_available = self.last_addr == self.INV_ADDR and \