From 2e7222e9bb2e005a0af770c1380c84ee4dad2ac0 Mon Sep 17 00:00:00 2001 From: Stefan Allius Date: Sat, 21 Jun 2025 11:47:17 +0200 Subject: [PATCH] change send_modbus_cmd into a synchronous function --- app/src/messages.py | 2 +- app/src/mqtt.py | 2 +- app/tests/test_mqtt.py | 10 +++++----- app/tests/test_solarman.py | 4 ++-- app/tests/test_talent.py | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/messages.py b/app/src/messages.py index 7c04121..1b50972 100644 --- a/app/src/messages.py +++ b/app/src/messages.py @@ -193,7 +193,7 @@ class Message(ProtocolIfc): return self.mb.build_msg(dev_id, func, addr, val, log_lvl) - async def send_modbus_cmd(self, func, addr, val, log_lvl) -> None: + def send_modbus_cmd(self, func, addr, val, log_lvl) -> None: self._send_modbus_cmd(Modbus.INV_ADDR, func, addr, val, log_lvl) def _send_modbus_scan(self): diff --git a/app/src/mqtt.py b/app/src/mqtt.py index c480aae..ae0eecb 100755 --- a/app/src/mqtt.py +++ b/app/src/mqtt.py @@ -195,7 +195,7 @@ class Mqtt(metaclass=Singleton): elif params == 2: addr = int(res[0], base=16) val = int(res[1]) # lenght - await fnc(func, addr, val, logging.INFO) + fnc(func, addr, val, logging.INFO) async def _at_cmd(self, message): payload = message.payload.decode("UTF-8") diff --git a/app/tests/test_mqtt.py b/app/tests/test_mqtt.py index 2266132..623fb01 100755 --- a/app/tests/test_mqtt.py +++ b/app/tests/test_mqtt.py @@ -286,23 +286,23 @@ async def test_mqtt_dispatch(config_mqtt_conn, aiomqtt_mock, spy_modbus_cmd): assert m.ha_restarts == 1 await m.receive(topic= 'tsun/inv_1/rated_load', payload= b'2') - spy.assert_awaited_once_with(Modbus.WRITE_SINGLE_REG, 0x2008, 2, logging.INFO) + spy.assert_called_once_with(Modbus.WRITE_SINGLE_REG, 0x2008, 2, logging.INFO) spy.reset_mock() await m.receive(topic= 'tsun/inv_1/out_coeff', payload= b'100') - spy.assert_awaited_once_with(Modbus.WRITE_SINGLE_REG, 0x202c, 1024, logging.INFO) + spy.assert_called_once_with(Modbus.WRITE_SINGLE_REG, 0x202c, 1024, logging.INFO) spy.reset_mock() await m.receive(topic= 'tsun/inv_1/out_coeff', payload= b'50') - spy.assert_awaited_once_with(Modbus.WRITE_SINGLE_REG, 0x202c, 512, logging.INFO) + spy.assert_called_once_with(Modbus.WRITE_SINGLE_REG, 0x202c, 512, logging.INFO) spy.reset_mock() await m.receive(topic= 'tsun/inv_1/modbus_read_regs', payload= b'0x3000, 10') - spy.assert_awaited_once_with(Modbus.READ_REGS, 0x3000, 10, logging.INFO) + spy.assert_called_once_with(Modbus.READ_REGS, 0x3000, 10, logging.INFO) spy.reset_mock() await m.receive(topic= 'tsun/inv_1/modbus_read_inputs', payload= b'0x3000, 10') - spy.assert_awaited_once_with(Modbus.READ_INPUTS, 0x3000, 10, logging.INFO) + spy.assert_called_once_with(Modbus.READ_INPUTS, 0x3000, 10, logging.INFO) # test dispatching with empty mapping table m.topic_defs.clear() diff --git a/app/tests/test_solarman.py b/app/tests/test_solarman.py index 92874f5..3365703 100755 --- a/app/tests/test_solarman.py +++ b/app/tests/test_solarman.py @@ -1624,7 +1624,7 @@ async def test_msg_build_modbus_req(my_loop, config_tsun_inv1, device_ind_msg, d assert m.ifc.tx_fifo.get()==device_rsp_msg assert m.ifc.fwd_fifo.get()==device_ind_msg - await m.send_modbus_cmd(Modbus.WRITE_SINGLE_REG, 0x2008, 0, logging.DEBUG) + m.send_modbus_cmd(Modbus.WRITE_SINGLE_REG, 0x2008, 0, logging.DEBUG) assert 0 == m.send_msg_ofs assert m.ifc.fwd_fifo.get() == b'' assert m.sent_pdu == b'' # modbus command must be ignore, cause connection is still not up @@ -1642,7 +1642,7 @@ async def test_msg_build_modbus_req(my_loop, config_tsun_inv1, device_ind_msg, d assert m.ifc.tx_fifo.get()==inverter_rsp_msg assert m.ifc.fwd_fifo.get()==inverter_ind_msg - await m.send_modbus_cmd(Modbus.WRITE_SINGLE_REG, 0x2008, 0, logging.DEBUG) + m.send_modbus_cmd(Modbus.WRITE_SINGLE_REG, 0x2008, 0, logging.DEBUG) assert 0 == m.send_msg_ofs assert m.ifc.fwd_fifo.get() == b'' assert m.sent_pdu == msg_modbus_cmd diff --git a/app/tests/test_talent.py b/app/tests/test_talent.py index fa42eed..01ef0fe 100644 --- a/app/tests/test_talent.py +++ b/app/tests/test_talent.py @@ -2411,14 +2411,14 @@ async def test_msg_build_modbus_req(config_tsun_inv1, msg_modbus_cmd): _ = config_tsun_inv1 m = MemoryStream(b'', (0,), True) m.id_str = b"R170000000000001" - await m.send_modbus_cmd(Modbus.WRITE_SINGLE_REG, 0x2008, 0, logging.DEBUG) + m.send_modbus_cmd(Modbus.WRITE_SINGLE_REG, 0x2008, 0, logging.DEBUG) assert 0 == m.send_msg_ofs assert m.ifc.fwd_fifo.get() == b'' assert m.ifc.tx_fifo.get() == b'' assert m.sent_pdu == b'' m.state = State.up - await m.send_modbus_cmd(Modbus.WRITE_SINGLE_REG, 0x2008, 0, logging.DEBUG) + m.send_modbus_cmd(Modbus.WRITE_SINGLE_REG, 0x2008, 0, logging.DEBUG) assert 0 == m.send_msg_ofs assert m.ifc.fwd_fifo.get() == b'' assert m.ifc.tx_fifo.get() == b''