-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
114 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
import unittest | ||
|
||
from nibe_mqtt.config import schema | ||
|
||
|
||
class ConfigTestCase(unittest.TestCase): | ||
def test_nibegw(self): | ||
config = schema( | ||
{ | ||
"mqtt": {"host": "192.168.1.2"}, | ||
"nibe": { | ||
"nibegw": {"ip": "192.168.1.3"}, | ||
"model": "F1255", | ||
"poll": {"coils": ["bt50-room-temp-s1-40033", 40033]}, | ||
}, | ||
} | ||
) | ||
|
||
print(config) | ||
|
||
def test_modbus(self): | ||
config = schema( | ||
{ | ||
"mqtt": {"host": "192.168.1.2"}, | ||
"nibe": { | ||
"modbus": {"url": "tcp://127.0.0.1:502", "slave_id": 1}, | ||
"model": "F1255", | ||
"poll": {"coils": ["bt50-room-temp-s1-40033", 40033]}, | ||
}, | ||
} | ||
) | ||
|
||
print(config) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() | ||
def test_nibegw(): | ||
config = schema( | ||
{ | ||
"mqtt": {"host": "192.168.1.2"}, | ||
"nibe": { | ||
"nibegw": {"ip": "192.168.1.3"}, | ||
"model": "F1255", | ||
"poll": {"coils": ["bt50-room-temp-s1-40033", 40033]}, | ||
}, | ||
} | ||
) | ||
|
||
assert "modbus" not in config["nibe"] | ||
assert config["nibe"]["poll"]["interval"] == 60 | ||
|
||
print(config) | ||
|
||
def test_modbus(): | ||
config = schema( | ||
{ | ||
"mqtt": {"host": "192.168.1.2"}, | ||
"nibe": { | ||
"modbus": {"url": "tcp://127.0.0.1:502", "slave_id": 1}, | ||
"model": "F1255", | ||
"poll": {"coils": ["bt50-room-temp-s1-40033", 40033]}, | ||
}, | ||
} | ||
) | ||
|
||
assert "nibegw" not in config["nibe"] | ||
assert config["nibe"]["poll"]["interval"] == 60 | ||
|
||
print(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
|
||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from nibe_mqtt.config import schema | ||
from nibe_mqtt.service import Service | ||
|
||
|
||
@pytest.fixture | ||
def nibegw_config(): | ||
return schema({ | ||
"mqtt": {"host": "127.0.0.1"}, | ||
"nibe": { | ||
"nibegw": {"ip": "127.0.0.1"}, | ||
"model": "F1255" | ||
}, | ||
}) | ||
|
||
@pytest.fixture | ||
def modbus_config(): | ||
return schema({ | ||
"mqtt": {"host": "127.0.0.1"}, | ||
"nibe": { | ||
"modbus": {"url": "tcp://127.0.0.1:502", "slave_id": 1}, | ||
"model": "S2125" | ||
}, | ||
}) | ||
|
||
@pytest.fixture(name="nibegw_connection", autouse=True) | ||
def nibegw_connection(): | ||
from nibe.connection.nibegw import NibeGW | ||
return mock.Mock(spec=NibeGW) | ||
|
||
|
||
@pytest.fixture(name="modbus_connection", autouse=True) | ||
def modbus_connection(): | ||
from nibe.connection.modbus import Modbus | ||
return mock.Mock(spec=Modbus) | ||
|
||
|
||
@pytest.fixture(name="mqtt_connection", autouse=True) | ||
def mqtt_connection(): | ||
from nibe_mqtt.mqtt import MqttConnection | ||
return mock.Mock(spec=MqttConnection) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_service_nibegw(nibegw_config): | ||
service = Service(nibegw_config) | ||
|
||
await service.start() | ||
|
||
assert len(service.heatpump.get_coils()) > 0 | ||
|
||
outdoor_temperature = service.heatpump.get_coil_by_address(40004) | ||
outdoor_temperature.value = 10 | ||
service.on_coil_update(outdoor_temperature) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_service_modbus(modbus_config): | ||
service = Service(modbus_config) | ||
|
||
await service.start() | ||
|
||
assert len(service.heatpump.get_coils()) > 0 | ||
|
||
outdoor_temperature = service.heatpump.get_coil_by_address(30002) | ||
outdoor_temperature.value = 10 | ||
service.on_coil_update(outdoor_temperature) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters