rename class Inverter into Proxy

This commit is contained in:
Stefan Allius
2024-10-04 23:37:05 +02:00
parent 3a94afb48d
commit 00e9a4534d
14 changed files with 300 additions and 232 deletions

View File

@@ -7,7 +7,7 @@ from mock import patch
from enum import Enum
from app.src.infos import Infos
from app.src.config import Config
from app.src.inverter import Inverter
from app.src.proxy import Proxy
from app.src.inverter_base import InverterBase
from app.src.singleton import Singleton
from app.src.gen3.inverter_g3 import InverterG3
@@ -126,14 +126,14 @@ async def test_remote_conn(config_conn, patch_open_connection):
assert asyncio.get_running_loop()
with InverterG3(FakeReader(), FakeWriter()) as inverter:
await inverter.async_create_remote()
await inverter.create_remote()
await asyncio.sleep(0)
assert inverter.remote.stream
del inverter
cnt = 0
for inv in InverterBase:
print(f'Inverter refs:{gc.get_referrers(inv)}')
print(f'InverterBase refs:{gc.get_referrers(inv)}')
cnt += 1
assert cnt == 0
@@ -147,12 +147,12 @@ async def test_remote_except(config_conn, patch_open_connection):
test = TestType.RD_TEST_TIMEOUT
with InverterG3(FakeReader(), FakeWriter()) as inverter:
await inverter.async_create_remote()
await inverter.create_remote()
await asyncio.sleep(0)
assert inverter.remote.stream==None
test = TestType.RD_TEST_EXCEPT
await inverter.async_create_remote()
await inverter.create_remote()
await asyncio.sleep(0)
assert inverter.remote.stream==None
del inverter
@@ -169,7 +169,7 @@ async def test_mqtt_publish(config_conn, patch_open_connection):
_ = patch_open_connection
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
with InverterG3(FakeReader(), FakeWriter()) as inverter:
stream = inverter.local.stream
@@ -197,7 +197,7 @@ async def test_mqtt_err(config_conn, patch_open_connection, patch_mqtt_err):
_ = patch_mqtt_err
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
with InverterG3(FakeReader(), FakeWriter()) as inverter:
stream = inverter.local.stream
@@ -214,7 +214,7 @@ async def test_mqtt_except(config_conn, patch_open_connection, patch_mqtt_except
_ = patch_mqtt_except
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
with InverterG3(FakeReader(), FakeWriter()) as inverter:
stream = inverter.local.stream

View File

@@ -6,7 +6,7 @@ from mock import patch
from enum import Enum
from app.src.infos import Infos
from app.src.config import Config
from app.src.inverter import Inverter
from app.src.proxy import Proxy
from app.src.inverter_base import InverterBase
from app.src.singleton import Singleton
from app.src.gen3plus.inverter_g3p import InverterG3P
@@ -110,7 +110,7 @@ async def test_remote_conn(config_conn, patch_open_connection):
assert asyncio.get_running_loop()
with InverterG3P(FakeReader(), FakeWriter(), client_mode=False) as inverter:
await inverter.async_create_remote()
await inverter.create_remote()
await asyncio.sleep(0)
assert inverter.remote.stream
@@ -124,12 +124,12 @@ async def test_remote_except(config_conn, patch_open_connection):
test = TestType.RD_TEST_TIMEOUT
with InverterG3P(FakeReader(), FakeWriter(), client_mode=False) as inverter:
await inverter.async_create_remote()
await inverter.create_remote()
await asyncio.sleep(0)
assert inverter.remote.stream==None
test = TestType.RD_TEST_EXCEPT
await inverter.async_create_remote()
await inverter.create_remote()
await asyncio.sleep(0)
assert inverter.remote.stream==None
@@ -139,7 +139,7 @@ async def test_mqtt_publish(config_conn, patch_open_connection):
_ = patch_open_connection
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
with InverterG3P(FakeReader(), FakeWriter(), client_mode=False) as inverter:
stream = inverter.local.stream
@@ -167,7 +167,7 @@ async def test_mqtt_err(config_conn, patch_open_connection, patch_mqtt_err):
_ = patch_mqtt_err
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
with InverterG3P(FakeReader(), FakeWriter(), client_mode=False) as inverter:
stream = inverter.local.stream
@@ -184,7 +184,7 @@ async def test_mqtt_except(config_conn, patch_open_connection, patch_mqtt_except
_ = patch_mqtt_except
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
with InverterG3P(FakeReader(), FakeWriter(), client_mode=False) as inverter:
stream = inverter.local.stream

View File

@@ -10,7 +10,7 @@ from app.src.config import Config
from app.src.infos import Infos
from app.src.mqtt import Mqtt
from app.src.messages import Message, State
from app.src.inverter import Inverter
from app.src.proxy import Proxy
from app.src.modbus_tcp import ModbusConn, ModbusTcp
@@ -175,7 +175,7 @@ async def test_modbus_cnf1(config_conn, patch_open):
_ = patch_open
global test
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
test = TestType.RD_TEST_TIMEOUT
assert Infos.stat['proxy']['Inverter_Cnt'] == 0
@@ -196,7 +196,7 @@ async def test_modbus_cnf2(config_conn, patch_no_mqtt, patch_open):
_ = patch_no_mqtt
global test
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
test = TestType.RD_TEST_0_BYTES
assert Infos.stat['proxy']['Inverter_Cnt'] == 0
@@ -222,7 +222,7 @@ async def test_modbus_cnf3(config_conn, patch_no_mqtt, patch_open):
_ = patch_no_mqtt
global test
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
test = TestType.RD_TEST_0_BYTES
assert Infos.stat['proxy']['Inverter_Cnt'] == 0
@@ -255,7 +255,7 @@ async def test_mqtt_err(config_conn, patch_mqtt_err, patch_open):
_ = patch_mqtt_err
global test
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
test = TestType.RD_TEST_0_BYTES
assert Infos.stat['proxy']['Inverter_Cnt'] == 0
@@ -288,7 +288,7 @@ async def test_mqtt_except(config_conn, patch_mqtt_except, patch_open):
_ = patch_mqtt_except
global test
assert asyncio.get_running_loop()
Inverter.class_init()
Proxy.class_init()
test = TestType.RD_TEST_0_BYTES
assert Infos.stat['proxy']['Inverter_Cnt'] == 0

View File

@@ -6,7 +6,7 @@ import logging
from mock import patch, Mock
from app.src.singleton import Singleton
from app.src.inverter import Inverter
from app.src.proxy import Proxy
from app.src.mqtt import Mqtt
from app.src.gen3plus.solarman_v5 import SolarmanV5
from app.src.config import Config
@@ -63,13 +63,13 @@ def config_conn(test_hostname, test_port):
async def test_inverter_cb(config_conn):
_ = config_conn
with patch.object(Inverter, '_cb_mqtt_is_up', wraps=Inverter._cb_mqtt_is_up) as spy:
print('call Inverter.class_init')
Inverter.class_init()
assert 'homeassistant/' == Inverter.discovery_prfx
assert 'tsun/' == Inverter.entity_prfx
assert 'test_1/' == Inverter.proxy_node_id
await Inverter._cb_mqtt_is_up()
with patch.object(Proxy, '_cb_mqtt_is_up', wraps=Proxy._cb_mqtt_is_up) as spy:
print('call Proxy.class_init')
Proxy.class_init()
assert 'homeassistant/' == Proxy.discovery_prfx
assert 'tsun/' == Proxy.entity_prfx
assert 'test_1/' == Proxy.proxy_node_id
await Proxy._cb_mqtt_is_up()
spy.assert_called_once()
@pytest.mark.asyncio
@@ -77,8 +77,8 @@ async def test_mqtt_is_up(config_conn):
_ = config_conn
with patch.object(Mqtt, 'publish') as spy:
Inverter.class_init()
await Inverter._cb_mqtt_is_up()
Proxy.class_init()
await Proxy._cb_mqtt_is_up()
spy.assert_called()
@pytest.mark.asyncio
@@ -86,6 +86,6 @@ async def test_mqtt_proxy_statt_invalid(config_conn):
_ = config_conn
with patch.object(Mqtt, 'publish') as spy:
Inverter.class_init()
await Inverter._async_publ_mqtt_proxy_stat('InValId_kEy')
Proxy.class_init()
await Proxy._async_publ_mqtt_proxy_stat('InValId_kEy')
spy.assert_not_called()

View File

@@ -682,6 +682,7 @@ def config_tsun_inv1():
Config.act_config = {'solarman':{'enabled': True},'inverters':{'Y170000000000001':{'monitor_sn': 2070233889, 'node_id':'inv1', 'modbus_polling': True, 'suggested_area':'roof', 'sensor_list': 688}}}
def test_read_message(device_ind_msg):
Config.act_config = {'solarman':{'enabled': True}}
m = MemoryStream(device_ind_msg, (0,))
m.read() # read complete msg, and dispatch msg
assert not m.header_valid # must be invalid, since msg was handled and buffer flushed