diff --git a/aioecowitt/sensor.py b/aioecowitt/sensor.py index 3df5da2..cd57261 100644 --- a/aioecowitt/sensor.py +++ b/aioecowitt/sensor.py @@ -459,4 +459,5 @@ class EcoWittMapping: ), "runtime": EcoWittMapping("Runtime", EcoWittSensorTypes.INTERNAL), "interval": EcoWittMapping("Interval", EcoWittSensorTypes.INTERNAL), + "heap": EcoWittMapping("Memory heap", EcoWittSensorTypes.INTERNAL), } diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..82f16ea --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,19 @@ +import pytest + +from aioecowitt import server + + +@pytest.fixture +def ecowitt_server(): + """EcoWitt server fixture.""" + ecowitt_server = server.EcoWittListener() + yield ecowitt_server + + +@pytest.fixture +def ecowitt_http(event_loop, aiohttp_raw_server, aiohttp_client, ecowitt_server): + """EcoWitt HTTP fixture.""" + raw_server = event_loop.run_until_complete( + aiohttp_raw_server(ecowitt_server.handler) + ) + return event_loop.run_until_complete(aiohttp_client(raw_server)) diff --git a/tests/const.py b/tests/const.py index 47f052b..e83d525 100644 --- a/tests/const.py +++ b/tests/const.py @@ -60,3 +60,36 @@ "freq": "868M", "model": "GW2000A", } + +GW2000A_V3_DATA = { + "PASSKEY": "345544D8EAF42E1B8824A86D8250D5A3", + "stationtype": "GW2000A_V3.1.0", + "runtime": "158060", + "heap": "124256", + "dateutc": "2024-02-08 10: 36: 28", + "tempinf": "69.44", + "humidityin": "36", + "baromrelin": "26.175", + "baromabsin": "26.175", + "tempf": "64.76", + "humidity": "48", + "winddir": "293", + "windspeedmph": "0.00", + "windgustmph": "0.00", + "maxdailygust": "1.34", + "solarradiation": "3.87", + "uv": "0", + "rrain_piezo": "0.000", + "erain_piezo": "0.000", + "hrain_piezo": "0.000", + "drain_piezo": "0.000", + "wrain_piezo": "0.000", + "mrain_piezo": "0.000", + "yrain_piezo": "0.000", + "ws90cap_volt": "1.3", + "ws90_ver": "133", + "wh90batt": "2.90", + "freq": "868M", + "model": "GW2000A", + "interval": "60", +} diff --git a/tests/test_sensor.py b/tests/test_sensor.py index f4477b2..8300e9a 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -1,5 +1,9 @@ """Test ecowitt sensor module.""" +import pytest +from aioecowitt import server + +from .const import GW2000A_V3_DATA from aioecowitt import sensor @@ -27,3 +31,25 @@ def on_change() -> None: ecowit_sensor.update_value(11, 0, 0) assert called + + +@pytest.mark.asyncio +async def test_heap_field(ecowitt_server, ecowitt_http) -> None: + """Test handling of heap field.""" + heap_sensor = None + + def on_change(sensor: server.EcoWittSensor) -> None: + """Test callback.""" + if sensor.key == "heap": + nonlocal heap_sensor + heap_sensor = sensor + + ecowitt_server.new_sensor_cb.append(on_change) + + resp = await ecowitt_http.post("/", data=GW2000A_V3_DATA) + assert resp.status == 200 + text = await resp.text() + assert text == "OK" + + assert heap_sensor + assert heap_sensor.value == GW2000A_V3_DATA["heap"] diff --git a/tests/test_server.py b/tests/test_server.py index 38365ce..39e70e8 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -9,22 +9,6 @@ # pylint: disable=redefined-outer-name -@pytest.fixture -def ecowitt_server(): - """EcoWitt server fixture.""" - ecowitt_server = server.EcoWittListener() - yield ecowitt_server - - -@pytest.fixture -def ecowitt_http(event_loop, aiohttp_raw_server, aiohttp_client, ecowitt_server): - """EcoWitt HTTP fixture.""" - raw_server = event_loop.run_until_complete( - aiohttp_raw_server(ecowitt_server.handler) - ) - return event_loop.run_until_complete(aiohttp_client(raw_server)) - - @pytest.mark.asyncio async def test_server_start(ecowitt_server, ecowitt_http) -> None: """Test server start."""