Skip to content

Commit 466afba

Browse files
committed
Update relay storage considerations
1 parent 521a490 commit 466afba

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

opensensor/collection_apis.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def _record_data_to_ts_collection(
140140
if value is not None:
141141
if key == "unit":
142142
doc_to_insert[column_name + "_unit"] = value
143+
elif key == "relays":
144+
doc_to_insert[column_name] = json.dumps(value)
143145
else:
144146
doc_to_insert[column_name] = str(value)
145147

@@ -580,11 +582,14 @@ def sample_and_paginate_collection(
580582
relays = []
581583
for item in raw_data:
582584
for relay in item["relays"]:
583-
if isinstance(relay, str):
584-
relay = json.loads(relay)
585-
if isinstance(relay, list):
586-
relay = relay[0]
587-
relays.append(RelayStatus(**relay))
585+
try:
586+
if isinstance(relay, str):
587+
relay = json.loads(relay)
588+
if isinstance(relay, list):
589+
relay = relay[0]
590+
relays.append(RelayStatus(**relay))
591+
except Exception:
592+
pass # Ignore invalid relay data
588593
relay_board = RelayBoard(relays=relays)
589594
data.append(relay_board)
590595
else:

0 commit comments

Comments
 (0)