combov2: Restrict contents of "status" label in JSON pump status
Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
parent
01560f45be
commit
c447df3599
1 changed files with 19 additions and 1 deletions
|
@ -1032,13 +1032,31 @@ class ComboV2Plugin @Inject constructor (
|
||||||
// NOTE: This is called "status" because this is what the
|
// NOTE: This is called "status" because this is what the
|
||||||
// Nightscout pump plugin API schema expects. It is not to
|
// Nightscout pump plugin API schema expects. It is not to
|
||||||
// be confused with the "status" in the ComboCtl Pump class.
|
// 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.
|
// See the Nightscout /devicestatus/ API docs for more.
|
||||||
put("status", JSONObject().apply {
|
put("status", JSONObject().apply {
|
||||||
val driverState = driverStateFlow.value
|
val driverState = driverStateFlow.value
|
||||||
val suspended = isSuspended()
|
val suspended = isSuspended()
|
||||||
val bolusing = (driverState is DriverState.ExecutingCommand) &&
|
val bolusing = (driverState is DriverState.ExecutingCommand) &&
|
||||||
(driverState.description is ComboCtlPump.DeliveringBolusCommandDesc)
|
(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("suspended", suspended)
|
||||||
put("bolusing", bolusing)
|
put("bolusing", bolusing)
|
||||||
put("timestamp", dateUtil.toISOString(lastConnectionTimestamp))
|
put("timestamp", dateUtil.toISOString(lastConnectionTimestamp))
|
||||||
|
|
Loading…
Reference in a new issue