Skip to content

Commit

Permalink
Add SFA30 to summary and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wason1797 committed Feb 24, 2025
1 parent 2eb6593 commit 9b24cf8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
19 changes: 19 additions & 0 deletions server/app/managers/aiq_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{}
{}
{}
{}
border_router_id: {}
station_id: {}
"""
Expand Down Expand Up @@ -48,6 +49,13 @@
\tgasres: {} Ohm
"""

SFA30_SUMMARY_TEMPLATE = """
SFA30:
\hco: {} ppb
\ttemp: {} C
\thum: {} H%
"""


def _render_summary_template(data: StationData, count: int) -> str:
scd41_summary = (
Expand Down Expand Up @@ -92,13 +100,24 @@ def _render_summary_template(data: StationData, count: int) -> str:
else ""
)

sfa30_summary = (
SFA30_SUMMARY_TEMPLATE.format(
int(data.sfa30_data.hco) / 1000000,
int(data.sfa30_data.temperature) / 1000000,
int(data.sfa30_data.humidity) / 1000000,
)
if data.sfa30_data is not None
else ""
)

return SUMMARY_TEMPLATE.format(
count,
datetime.fromtimestamp(float(data.timestamp), timezone.utc).strftime(r"%d/%m/%Y, %H:%M:%S"),
scd41_summary,
ens160_summary,
svm41_summary,
bme688_summary,
sfa30_summary,
data.border_router_id,
data.station_id,
)
Expand Down
18 changes: 10 additions & 8 deletions server/tests/fixtures/aiq_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ def mock_station_id() -> int:
def mock_aiq_request_scd41_from_br(mock_station_id: int) -> MockRequest:
"""Don't forget to update the signature if you change the data"""

return MockRequest(
payload=f"{json.dumps(_base_data(mock_station_id)).replace(" ", "")}|b7288bcac962668e493e5eaf0feeb965007f4e75|1".encode(
"ascii"
)
)
base_data = json.dumps(_base_data(mock_station_id)).replace(" ", "")

base_data_signed = f"{base_data}|b7288bcac962668e493e5eaf0feeb965007f4e75|1"

return MockRequest(payload=base_data_signed.encode("ascii"))


@pytest.fixture
def mock_aiq_request_scd41_from_end_device(mock_station_id: int) -> MockRequest:
"""Don't forget to update the signature if you change the data"""

return MockRequest(
payload=f"{json.dumps(_base_data(mock_station_id)).replace(" ", "")}|b7288bcac962668e493e5eaf0feeb965007f4e75".encode("ascii")
)
base_data = json.dumps(_base_data(mock_station_id)).replace(" ", "")

base_data_signed = f"{base_data}|b7288bcac962668e493e5eaf0feeb965007f4e75"

return MockRequest(payload=base_data_signed.encode("ascii"))

0 comments on commit 9b24cf8

Please sign in to comment.