Skip to content

Commit d8ff25e

Browse files
committed
tools: cloud: output logger sync state
Display the logger synchronisation state when querying information from the cloud. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 9ccbd0d commit d8ff25e

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/infuse_iot/tools/cloud.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
get_device_by_device_id,
2424
get_device_kv_entries_by_device_id,
2525
get_device_last_route_by_device_id,
26+
get_device_logger_states_by_device_id,
2627
get_device_state_by_id,
2728
)
2829
from infuse_iot.api_client.api.organisation import (
@@ -192,6 +193,7 @@ def info(self, client: Client):
192193
board = get_board_by_id.sync(client=client, id=info.board_id)
193194
state = get_device_state_by_id.sync(client=client, id=info.id)
194195
route = get_device_last_route_by_device_id.sync(client=client, device_id=id_str)
196+
logger_states = get_device_logger_states_by_device_id.sync(client=client, device_id=id_str)
195197

196198
table: list[tuple[str, Any]] = [
197199
("UUID", info.id),
@@ -221,6 +223,24 @@ def info(self, client: Client):
221223
if route.bt_adv:
222224
table += [("BT Address", f"{route.bt_adv.address} ({route.bt_adv.type_})")]
223225

226+
if isinstance(logger_states, list) and len(logger_states) > 0:
227+
logger_names = {
228+
0: "Onboard",
229+
1: "Removable",
230+
}
231+
232+
for logger in logger_states:
233+
name = logger_names.get(logger.index, str(logger.index))
234+
table += [
235+
(f"~~~{name} Logger Sync~~~", ""),
236+
("Last Report Time", logger.last_reported_time),
237+
("Last Downloaded Time", logger.last_downloaded_time),
238+
("Reported Block", logger.last_reported_block),
239+
("Downloaded Block", logger.last_downloaded_block),
240+
]
241+
if isinstance(logger.last_reported_block, int) and isinstance(logger.last_downloaded_block, int):
242+
table += [("Block Lag", logger.last_reported_block - logger.last_downloaded_block)]
243+
224244
print(tabulate(table))
225245

226246
def _kv_display(self, table: list[tuple[str, Any]], name_base: str, dictionary: dict):

0 commit comments

Comments
 (0)