|
@@ -143,7 +143,7 @@ extension NightscoutConfig {
|
|
|
let fetchedProfileStore = try jsonDecoder.decode([FetchedNightscoutProfileStore].self, from: data)
|
|
let fetchedProfileStore = try jsonDecoder.decode([FetchedNightscoutProfileStore].self, from: data)
|
|
|
guard let fetchedProfile: ScheduledNightscoutProfile = fetchedProfileStore.first?.store["default"]
|
|
guard let fetchedProfile: ScheduledNightscoutProfile = fetchedProfileStore.first?.store["default"]
|
|
|
else {
|
|
else {
|
|
|
- error = "Can't find the default Nightscout Profile."
|
|
|
|
|
|
|
+ error = "\nCan't find the default Nightscout Profile."
|
|
|
group.leave()
|
|
group.leave()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -153,7 +153,7 @@ extension NightscoutConfig {
|
|
|
.nightscout,
|
|
.nightscout,
|
|
|
"Mismatching glucose units in Nightscout and Pump Settings. Import settings aborted."
|
|
"Mismatching glucose units in Nightscout and Pump Settings. Import settings aborted."
|
|
|
)
|
|
)
|
|
|
- error = "Mismatching glucose units in Nightscout and Pump Settings. Import settings aborted."
|
|
|
|
|
|
|
+ error = "\nMismatching glucose units in Nightscout and Pump Settings. Import settings aborted."
|
|
|
group.leave()
|
|
group.leave()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -167,14 +167,23 @@ extension NightscoutConfig {
|
|
|
) }
|
|
) }
|
|
|
let carbratiosProfile = CarbRatios(units: CarbUnit.grams, schedule: carbratios)
|
|
let carbratiosProfile = CarbRatios(units: CarbUnit.grams, schedule: carbratios)
|
|
|
|
|
|
|
|
|
|
+ var areBasalsOK = true
|
|
|
let basals = fetchedProfile.basal
|
|
let basals = fetchedProfile.basal
|
|
|
.map { basal -> BasalProfileEntry in
|
|
.map { basal -> BasalProfileEntry in
|
|
|
- BasalProfileEntry(
|
|
|
|
|
|
|
+ if basal.value <= 0 || basal.value >= self.maxBasal {
|
|
|
|
|
+ error =
|
|
|
|
|
+ "\nInvalid Nightcsout Basal Settings. \n\nImport aborted. Please check your Nightscout Profile Basal Settings!"
|
|
|
|
|
+ areBasalsOK = false
|
|
|
|
|
+ }
|
|
|
|
|
+ return BasalProfileEntry(
|
|
|
start: basal.time,
|
|
start: basal.time,
|
|
|
minutes: (basal.timeAsSeconds ?? self.offset(basal.time)) / 60,
|
|
minutes: (basal.timeAsSeconds ?? self.offset(basal.time)) / 60,
|
|
|
rate: basal.value
|
|
rate: basal.value
|
|
|
) }
|
|
) }
|
|
|
-
|
|
|
|
|
|
|
+ guard areBasalsOK else {
|
|
|
|
|
+ group.leave()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
let sensitivities = fetchedProfile.sens.map { sensitivity -> InsulinSensitivityEntry in
|
|
let sensitivities = fetchedProfile.sens.map { sensitivity -> InsulinSensitivityEntry in
|
|
|
InsulinSensitivityEntry(
|
|
InsulinSensitivityEntry(
|
|
|
sensitivity: self.units == .mmolL ? sensitivity.value : sensitivity.value.asMgdL,
|
|
sensitivity: self.units == .mmolL ? sensitivity.value : sensitivity.value.asMgdL,
|
|
@@ -200,7 +209,6 @@ extension NightscoutConfig {
|
|
|
userPrefferedUnits: self.units,
|
|
userPrefferedUnits: self.units,
|
|
|
targets: targets
|
|
targets: targets
|
|
|
)
|
|
)
|
|
|
-
|
|
|
|
|
// IS THERE A PUMP?
|
|
// IS THERE A PUMP?
|
|
|
guard let pump = self.apsManager.pumpManager else {
|
|
guard let pump = self.apsManager.pumpManager else {
|
|
|
self.storage.save(carbratiosProfile, as: OpenAPS.Settings.carbRatios)
|
|
self.storage.save(carbratiosProfile, as: OpenAPS.Settings.carbRatios)
|
|
@@ -211,13 +219,15 @@ extension NightscoutConfig {
|
|
|
.service,
|
|
.service,
|
|
|
"Settings were imported but the Basals couldn't be saved to pump (No pump). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings"
|
|
"Settings were imported but the Basals couldn't be saved to pump (No pump). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings"
|
|
|
)
|
|
)
|
|
|
|
|
+ error =
|
|
|
|
|
+ "\nSettings were imported but the Basals couldn't be saved to pump (No pump). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings"
|
|
|
|
|
+ group.leave()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
let syncValues = basals.map {
|
|
let syncValues = basals.map {
|
|
|
RepeatingScheduleValue(startTime: TimeInterval($0.minutes * 60), value: Double($0.rate))
|
|
RepeatingScheduleValue(startTime: TimeInterval($0.minutes * 60), value: Double($0.rate))
|
|
|
}
|
|
}
|
|
|
- // SAVE TO STORAGE
|
|
|
|
|
- // SAVE TO PUMP (LoopKit)
|
|
|
|
|
|
|
+ // SSAVE TO STORAGE. SAVE TO PUMP (LoopKit)
|
|
|
pump.syncBasalRateSchedule(items: syncValues) { result in
|
|
pump.syncBasalRateSchedule(items: syncValues) { result in
|
|
|
switch result {
|
|
switch result {
|
|
|
case .success:
|
|
case .success:
|
|
@@ -226,23 +236,29 @@ extension NightscoutConfig {
|
|
|
self.storage.save(sensitivitiesProfile, as: OpenAPS.Settings.insulinSensitivities)
|
|
self.storage.save(sensitivitiesProfile, as: OpenAPS.Settings.insulinSensitivities)
|
|
|
self.storage.save(targetsProfile, as: OpenAPS.Settings.bgTargets)
|
|
self.storage.save(targetsProfile, as: OpenAPS.Settings.bgTargets)
|
|
|
debug(.service, "Settings have been imported and the Basals saved to pump!")
|
|
debug(.service, "Settings have been imported and the Basals saved to pump!")
|
|
|
|
|
+ // DIA. Save if changed.
|
|
|
|
|
+ let dia = fetchedProfile.dia
|
|
|
|
|
+ if dia != self.dia {
|
|
|
|
|
+ let file = PumpSettings(
|
|
|
|
|
+ insulinActionCurve: dia,
|
|
|
|
|
+ maxBolus: self.maxBolus,
|
|
|
|
|
+ maxBasal: self.maxBasal
|
|
|
|
|
+ )
|
|
|
|
|
+ self.storage.save(file, as: OpenAPS.Settings.settings)
|
|
|
|
|
+ debug(.nightscout, "DIA setting updated to " + dia.description + " after a NS import.")
|
|
|
|
|
+ }
|
|
|
|
|
+ group.leave()
|
|
|
case .failure:
|
|
case .failure:
|
|
|
error =
|
|
error =
|
|
|
- "Settings were imported but the Basals couldn't be saved to pump (communication error). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings"
|
|
|
|
|
|
|
+ "\nSettings were imported but the Basals couldn't be saved to pump (communication error). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings"
|
|
|
debug(.service, "Basals couldn't be save to pump")
|
|
debug(.service, "Basals couldn't be save to pump")
|
|
|
|
|
+ group.leave()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // DIA. Save if changed.
|
|
|
|
|
- let dia = fetchedProfile.dia
|
|
|
|
|
- if dia != self.dia {
|
|
|
|
|
- let file = PumpSettings(insulinActionCurve: dia, maxBolus: self.maxBolus, maxBasal: self.maxBasal)
|
|
|
|
|
- self.storage.save(file, as: OpenAPS.Settings.settings)
|
|
|
|
|
- debug(.nightscout, "DIA setting updated to " + dia.description + " after a NS import.")
|
|
|
|
|
- }
|
|
|
|
|
- group.leave()
|
|
|
|
|
} catch let parsingError {
|
|
} catch let parsingError {
|
|
|
print(parsingError)
|
|
print(parsingError)
|
|
|
|
|
+ error = parsingError.localizedDescription
|
|
|
|
|
+ group.leave()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|