From c447df359958d41075be4f5299b471040280005e Mon Sep 17 00:00:00 2001 From: Carlos Rafael Giani Date: Sun, 6 Nov 2022 13:48:02 +0100 Subject: [PATCH] combov2: Restrict contents of "status" label in JSON pump status Signed-off-by: Carlos Rafael Giani --- .../plugins/pump/combov2/ComboV2Plugin.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pump/combov2/src/main/kotlin/info/nightscout/androidaps/plugins/pump/combov2/ComboV2Plugin.kt b/pump/combov2/src/main/kotlin/info/nightscout/androidaps/plugins/pump/combov2/ComboV2Plugin.kt index b26803c5d8..f39c190428 100644 --- a/pump/combov2/src/main/kotlin/info/nightscout/androidaps/plugins/pump/combov2/ComboV2Plugin.kt +++ b/pump/combov2/src/main/kotlin/info/nightscout/androidaps/plugins/pump/combov2/ComboV2Plugin.kt @@ -1032,13 +1032,31 @@ class ComboV2Plugin @Inject constructor ( // NOTE: This is called "status" because this is what the // Nightscout pump plugin API schema expects. It is not to // be confused with the "status" in the ComboCtl Pump class. + // Also not to be confused with the "status" field inside + // this "status" JSON object. // See the Nightscout /devicestatus/ API docs for more. put("status", JSONObject().apply { val driverState = driverStateFlow.value val suspended = isSuspended() val bolusing = (driverState is DriverState.ExecutingCommand) && (driverState.description is ComboCtlPump.DeliveringBolusCommandDesc) - put("status", driverState.label) + // The value of the "status" string isn't well defined. + // Commonly used ones seem to be "normal", "suspended", + // and "bolusing". The latter two are already enforced + // by the corresponding boolean flags, but we set them + // in this string anyway. It may be a legacy feature + // from older Nightscout iterations. Furthermore, we do + // set this to "error" in case of pump errors to alert + // users of Nightscout to possible problems with the pump. + val statusLabel = if (bolusing) + "bolusing" + else if (suspended) + "suspended" + else if (driverState == DriverState.Error) + "error" + else + "normal" + put("status", statusLabel) put("suspended", suspended) put("bolusing", bolusing) put("timestamp", dateUtil.toISOString(lastConnectionTimestamp))