@@ -4,13 +4,14 @@ import asyncio
|
||||
|
||||
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.singleton import Singleton
|
||||
from app.src.gen3plus.connection_g3p import ConnectionG3P
|
||||
from app.src.gen3plus.inverter_g3p import InverterG3P
|
||||
from app.src.gen3plus.infos_g3p import InfosG3P
|
||||
|
||||
from app.src.infos import Infos
|
||||
from app.tests.test_modbus_tcp import patch_mqtt_err, patch_mqtt_except, test_port, test_hostname
|
||||
|
||||
|
||||
pytest_plugins = ('pytest_asyncio',)
|
||||
@@ -20,7 +21,22 @@ Infos.static_init()
|
||||
|
||||
@pytest.fixture
|
||||
def config_conn():
|
||||
Config.act_config = {'solarman':{'enabled': True, 'host': 'test_cloud.local', 'port': 1234}, 'inverters':{'allow_all':True}}
|
||||
Config.act_config = {
|
||||
'mqtt':{
|
||||
'host': test_hostname,
|
||||
'port': test_port,
|
||||
'user': '',
|
||||
'passwd': ''
|
||||
},
|
||||
'ha':{
|
||||
'auto_conf_prefix': 'homeassistant',
|
||||
'discovery_prefix': 'homeassistant',
|
||||
'entity_prefix': 'tsun',
|
||||
'proxy_node_id': 'test_1',
|
||||
'proxy_unique_id': ''
|
||||
},
|
||||
'solarman':{'enabled': True, 'host': 'test_cloud.local', 'port': 1234}, 'inverters':{'allow_all':True}
|
||||
}
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def module_init():
|
||||
@@ -112,16 +128,9 @@ async def test_remote_conn(config_conn, patch_open_connection, patch_conn_close)
|
||||
assert asyncio.get_running_loop()
|
||||
|
||||
spy1 = patch_conn_close
|
||||
reader = FakeReader()
|
||||
writer = FakeWriter()
|
||||
|
||||
addr = ('proxy.local', 10000)
|
||||
|
||||
inverter = InverterG3P(reader, writer, addr, client_mode=False)
|
||||
inverter.l_addr = ''
|
||||
inverter.r_addr = ''
|
||||
inverter.node_id = 'Test'
|
||||
inverter.db = InfosG3P(client_mode= False)
|
||||
inverter = InverterG3P(FakeReader(), FakeWriter(), ('proxy.local', 10000), client_mode=False)
|
||||
|
||||
await inverter.async_create_remote()
|
||||
await asyncio.sleep(0)
|
||||
assert inverter.remote_stream
|
||||
@@ -135,19 +144,12 @@ async def test_remote_except(config_conn, patch_open_connection, patch_conn_clos
|
||||
assert asyncio.get_running_loop()
|
||||
|
||||
spy1 = patch_conn_close
|
||||
reader = FakeReader()
|
||||
writer = FakeWriter()
|
||||
|
||||
addr = ('proxy.local', 10000)
|
||||
|
||||
global test
|
||||
test = TestType.RD_TEST_TIMEOUT
|
||||
|
||||
inverter = InverterG3P(reader, writer, addr, client_mode=False)
|
||||
inverter.l_addr = ''
|
||||
inverter.r_addr = ''
|
||||
inverter.node_id = 'Test'
|
||||
inverter.db = InfosG3P(client_mode= False)
|
||||
test = TestType.RD_TEST_TIMEOUT
|
||||
inverter = InverterG3P(FakeReader(), FakeWriter(), ('proxy.local', 10000), client_mode=False)
|
||||
|
||||
await inverter.async_create_remote()
|
||||
await asyncio.sleep(0)
|
||||
assert inverter.remote_stream==None
|
||||
@@ -158,3 +160,77 @@ async def test_remote_except(config_conn, patch_open_connection, patch_conn_clos
|
||||
assert inverter.remote_stream==None
|
||||
inverter.close()
|
||||
spy1.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mqtt_publish(config_conn, patch_open_connection, patch_conn_close):
|
||||
_ = config_conn
|
||||
_ = patch_open_connection
|
||||
assert asyncio.get_running_loop()
|
||||
|
||||
spy1 = patch_conn_close
|
||||
|
||||
Inverter.class_init()
|
||||
|
||||
inverter = InverterG3P(FakeReader(), FakeWriter(), ('proxy.local', 10000), client_mode=False)
|
||||
inverter._SolarmanV5__set_serial_no(snr= 123344)
|
||||
|
||||
inverter.new_data['inverter'] = True
|
||||
inverter.db.db['inverter'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['inverter'] == False
|
||||
|
||||
inverter.new_data['env'] = True
|
||||
inverter.db.db['env'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['env'] == False
|
||||
|
||||
Infos.new_stat_data['proxy'] = True
|
||||
await inverter.async_publ_mqtt()
|
||||
assert Infos.new_stat_data['proxy'] == False
|
||||
|
||||
inverter.close()
|
||||
spy1.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mqtt_err(config_conn, patch_open_connection, patch_mqtt_err, patch_conn_close):
|
||||
_ = config_conn
|
||||
_ = patch_open_connection
|
||||
_ = patch_mqtt_err
|
||||
assert asyncio.get_running_loop()
|
||||
|
||||
spy1 = patch_conn_close
|
||||
|
||||
Inverter.class_init()
|
||||
|
||||
inverter = InverterG3P(FakeReader(), FakeWriter(), ('proxy.local', 10000), client_mode=False)
|
||||
inverter._SolarmanV5__set_serial_no(snr= 123344)
|
||||
|
||||
inverter.new_data['inverter'] = True
|
||||
inverter.db.db['inverter'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['inverter'] == True
|
||||
|
||||
inverter.close()
|
||||
spy1.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mqtt_except(config_conn, patch_open_connection, patch_mqtt_except, patch_conn_close):
|
||||
_ = config_conn
|
||||
_ = patch_open_connection
|
||||
_ = patch_mqtt_except
|
||||
assert asyncio.get_running_loop()
|
||||
|
||||
spy1 = patch_conn_close
|
||||
|
||||
Inverter.class_init()
|
||||
|
||||
inverter = InverterG3P(FakeReader(), FakeWriter(), ('proxy.local', 10000), client_mode=False)
|
||||
inverter._SolarmanV5__set_serial_no(snr= 123344)
|
||||
|
||||
inverter.new_data['inverter'] = True
|
||||
inverter.db.db['inverter'] = {}
|
||||
await inverter.async_publ_mqtt()
|
||||
assert inverter.new_data['inverter'] == True
|
||||
|
||||
inverter.close()
|
||||
spy1.assert_called_once()
|
||||
|
||||
Reference in New Issue
Block a user