Skip to content

Commit

Permalink
Add heap field (#147)
Browse files Browse the repository at this point in the history
* Add heap

* Add test
  • Loading branch information
edenhaus authored Feb 8, 2024
1 parent f8bcf29 commit de28ca5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 16 deletions.
1 change: 1 addition & 0 deletions aioecowitt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,5 @@ class EcoWittMapping:
),
"runtime": EcoWittMapping("Runtime", EcoWittSensorTypes.INTERNAL),
"interval": EcoWittMapping("Interval", EcoWittSensorTypes.INTERNAL),
"heap": EcoWittMapping("Memory heap", EcoWittSensorTypes.INTERNAL),
}
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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))
33 changes: 33 additions & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
26 changes: 26 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""Test ecowitt sensor module."""
import pytest

from aioecowitt import server

from .const import GW2000A_V3_DATA
from aioecowitt import sensor


Expand Down Expand Up @@ -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"]
16 changes: 0 additions & 16 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit de28ca5

Please sign in to comment.