Skip to content

Commit

Permalink
Update relay storage considerations
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius committed Oct 6, 2024
1 parent 521a490 commit 466afba
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions opensensor/collection_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def _record_data_to_ts_collection(
if value is not None:
if key == "unit":
doc_to_insert[column_name + "_unit"] = value
elif key == "relays":
doc_to_insert[column_name] = json.dumps(value)
else:
doc_to_insert[column_name] = str(value)

Expand Down Expand Up @@ -580,11 +582,14 @@ def sample_and_paginate_collection(
relays = []
for item in raw_data:
for relay in item["relays"]:
if isinstance(relay, str):
relay = json.loads(relay)
if isinstance(relay, list):
relay = relay[0]
relays.append(RelayStatus(**relay))
try:
if isinstance(relay, str):
relay = json.loads(relay)
if isinstance(relay, list):
relay = relay[0]
relays.append(RelayStatus(**relay))
except Exception:
pass # Ignore invalid relay data
relay_board = RelayBoard(relays=relays)
data.append(relay_board)
else:
Expand Down

0 comments on commit 466afba

Please sign in to comment.