NSC: fix ProfileSwitch name

This commit is contained in:
Milos Kozak 2022-05-25 19:34:25 +02:00
parent 782591bf75
commit 4debc1b170

View file

@ -31,6 +31,8 @@ fun ProfileSwitch.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject =
JSONObject()
.put("timeshift", timeshift)
.put("percentage", percentage)
.put("profile", getCustomizedName())
.put("originalProfileName", profileName)
.also { // remove customization to store original profileJson in toPureNsJson call
timeshift = 0
percentage = 100
@ -40,7 +42,6 @@ fun ProfileSwitch.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject =
.put("isValid", isValid)
.put("eventType", TherapyEvent.Type.PROFILE_SWITCH.text)
.put("duration", T.msecs(duration).mins())
.put("profile", profileName)
.put("profileJson", ProfileSealed.PS(this).toPureNsJson(dateUtil).toString())
.also {
if (interfaceIDs.pumpId != null) it.put("pumpId", interfaceIDs.pumpId)
@ -70,6 +71,7 @@ fun profileSwitchFromJson(jsonObject: JSONObject, dateUtil: DateUtil, activePlug
val isValid = JsonHelper.safeGetBoolean(jsonObject, "isValid", true)
val id = JsonHelper.safeGetStringAllowNull(jsonObject, "_id", null)
val profileName = JsonHelper.safeGetStringAllowNull(jsonObject, "profile", null) ?: return null
val originalProfileName = JsonHelper.safeGetStringAllowNull(jsonObject, "originalProfileName", null)
val profileJson = JsonHelper.safeGetStringAllowNull(jsonObject, "profileJson", null)
val pumpId = JsonHelper.safeGetLongAllowNull(jsonObject, "pumpId", null)
val pumpType = InterfaceIDs.PumpType.fromString(JsonHelper.safeGetStringAllowNull(jsonObject, "pumpType", null))
@ -91,7 +93,7 @@ fun profileSwitchFromJson(jsonObject: JSONObject, dateUtil: DateUtil, activePlug
icBlocks = profileSealed.icBlocks,
targetBlocks = profileSealed.targetBlocks,
glucoseUnit = ProfileSwitch.GlucoseUnit.fromConstant(profileSealed.units),
profileName = profileName,
profileName = originalProfileName?: profileName,
timeshift = T.hours(timeshift).msecs(),
percentage = percentage,
duration = T.mins(duration).msecs(),