Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add heap field #147

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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