NSCv3: process Carbs
This commit is contained in:
parent
23cc3c9c3e
commit
10ca0773d9
|
@ -4,14 +4,14 @@ import info.nightscout.sdk.localmodel.entry.NsUnits
|
|||
|
||||
data class NSCarbs(
|
||||
override val date: Long,
|
||||
override val device: String?,
|
||||
override val device: String? = null,
|
||||
override val identifier: String?,
|
||||
override val units: NsUnits?,
|
||||
override val srvModified: Long?,
|
||||
override val srvCreated: Long?,
|
||||
override val units: NsUnits? = null,
|
||||
override val srvModified: Long? = null,
|
||||
override val srvCreated: Long? = null,
|
||||
override val utcOffset: Long,
|
||||
override val subject: String?,
|
||||
override var isReadOnly: Boolean,
|
||||
override val subject: String? = null,
|
||||
override var isReadOnly: Boolean = false,
|
||||
override val isValid: Boolean,
|
||||
override val eventType: EventType,
|
||||
override val notes: String?,
|
||||
|
@ -21,5 +21,5 @@ data class NSCarbs(
|
|||
override val pumpSerial: String?,
|
||||
override var app: String? = null,
|
||||
val carbs: Double,
|
||||
val duration: Long
|
||||
val duration: Long?
|
||||
) : NSTreatment
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.plugins.sync.nsclient.extensions
|
||||
|
||||
import info.nightscout.database.entities.Carbs
|
||||
import info.nightscout.database.entities.TherapyEvent
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.interfaces.utils.JsonHelper
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
|
@ -8,7 +9,7 @@ import org.json.JSONObject
|
|||
|
||||
fun Carbs.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject =
|
||||
JSONObject()
|
||||
.put("eventType", if (amount < 12) info.nightscout.database.entities.TherapyEvent.Type.CARBS_CORRECTION.text else info.nightscout.database.entities.TherapyEvent.Type.MEAL_BOLUS.text)
|
||||
.put("eventType", if (amount < 12) TherapyEvent.Type.CARBS_CORRECTION.text else TherapyEvent.Type.MEAL_BOLUS.text)
|
||||
.put("carbs", amount)
|
||||
.put("notes", notes)
|
||||
.put("created_at", dateUtil.toISOString(timestamp))
|
||||
|
|
|
@ -34,6 +34,7 @@ import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
|
|||
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGUI
|
||||
import info.nightscout.plugins.sync.nsclient.NsClientReceiverDelegate
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSBolus
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSCarbs
|
||||
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSEffectiveProfileSwitch
|
||||
import info.nightscout.plugins.sync.nsclientV3.workers.LoadBgWorker
|
||||
import info.nightscout.plugins.sync.nsclientV3.workers.LoadLastModificationWorker
|
||||
|
@ -319,7 +320,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
}
|
||||
when (dataPair) {
|
||||
is DataSyncSelector.PairBolus -> dataPair.value.toNSBolus()
|
||||
// is DataSyncSelector.PairCarbs -> dataPair.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairCarbs -> dataPair.value.toNSCarbs()
|
||||
// is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
||||
// is DataSyncSelector.PairTemporaryTarget -> dataPair.value.toJson(false, profileFunction.getUnits(), dateUtil)
|
||||
// is DataSyncSelector.PairFood -> dataPair.value.toJson(false)
|
||||
|
@ -358,7 +359,14 @@ class NSClientV3Plugin @Inject constructor(
|
|||
}
|
||||
dataSyncSelector.confirmLastBolusIdIfGreater(dataPair.id)
|
||||
}
|
||||
// is DataSyncSelector.PairCarbs -> dataPair.value.toJson(false, dateUtil)
|
||||
is DataSyncSelector.PairCarbs -> {
|
||||
if (result.response == 201) { // created
|
||||
dataPair.value.interfaceIDs.nightscoutId = result.identifier
|
||||
storeDataForDb.nsIdCarbs.add(dataPair.value)
|
||||
storeDataForDb.scheduleNsIdUpdate()
|
||||
}
|
||||
dataSyncSelector.confirmLastCarbsIdIfGreater(dataPair.id)
|
||||
}
|
||||
// is DataSyncSelector.PairBolusCalculatorResult -> dataPair.value.toJson(false, dateUtil, profileFunction)
|
||||
// is DataSyncSelector.PairTemporaryTarget -> dataPair.value.toJson(false, profileFunction.getUnits(), dateUtil)
|
||||
// is DataSyncSelector.PairFood -> dataPair.value.toJson(false)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.database.entities.Carbs
|
||||
import info.nightscout.database.entities.TherapyEvent
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.sdk.localmodel.treatment.EventType
|
||||
import info.nightscout.sdk.localmodel.treatment.NSCarbs
|
||||
|
||||
fun NSCarbs.toCarbs(): Carbs =
|
||||
|
@ -11,6 +13,22 @@ fun NSCarbs.toCarbs(): Carbs =
|
|||
utcOffset = utcOffset,
|
||||
amount = carbs,
|
||||
notes = notes,
|
||||
duration = duration,
|
||||
duration = duration ?: 0L,
|
||||
interfaceIDs_backing = InterfaceIDs(nightscoutId = identifier, pumpId = pumpId, pumpType = InterfaceIDs.PumpType.fromString(pumpType), pumpSerial = pumpSerial, endId = endId)
|
||||
)
|
||||
|
||||
fun Carbs.toNSCarbs(): NSCarbs =
|
||||
NSCarbs(
|
||||
eventType = EventType.fromString(if (amount < 12) TherapyEvent.Type.CARBS_CORRECTION.text else TherapyEvent.Type.MEAL_BOLUS.text),
|
||||
isValid = isValid,
|
||||
date = timestamp,
|
||||
utcOffset = utcOffset,
|
||||
carbs = amount,
|
||||
notes = notes,
|
||||
duration = if (duration != 0L) duration else null,
|
||||
identifier = interfaceIDs.nightscoutId,
|
||||
pumpId = interfaceIDs.pumpId,
|
||||
pumpType = interfaceIDs.pumpType?.name,
|
||||
pumpSerial = interfaceIDs.pumpSerial,
|
||||
endId = interfaceIDs.endId
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue