Skip to content

Commit

Permalink
Update relays condition to be an array returend
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius committed Oct 6, 2024
1 parent f41e831 commit c2ec1b6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion opensensor/collection_apis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
from datetime import datetime, timedelta, timezone
from typing import Generic, List, Optional, Type, TypeVar, get_args, get_origin
Expand All @@ -21,6 +22,7 @@
Moisture,
Pressure,
RelayBoard,
RelayStatus,
Temperature,
)
from opensensor.db import get_open_sensor_db
Expand Down Expand Up @@ -574,7 +576,14 @@ def sample_and_paginate_collection(
# So, you can directly use it to create the response model instances.
data = [VPD(**item) for item in raw_data]
elif response_model is RelayBoard:
data = [RelayBoard(**item) for item in raw_data]
data = []
relays = []
for item in raw_data:
for relay in item["relays"]:
relay = json.loads(relay)
relays.append(RelayStatus(**relay))
relay_board = RelayBoard(relays=relays)
data.append(relay_board)
else:
data = [create_model_instance(response_model, item, unit) for item in raw_data]

Expand Down

0 comments on commit c2ec1b6

Please sign in to comment.