|
|
@@ -162,22 +162,51 @@ extension Home {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- var tempBasalString: String? {
|
|
|
- guard let lastTempBasal = state.tempBasals.last?.tempBasal, let tempRate = lastTempBasal.rate else {
|
|
|
+ var basalString: String? {
|
|
|
+ var rate: NSNumber = 0
|
|
|
+ var manualBasalString = ""
|
|
|
+
|
|
|
+ guard let apsManager = state.apsManager else {
|
|
|
return nil
|
|
|
}
|
|
|
- let rateString = Formatter.decimalFormatterWithTwoFractionDigits.string(from: tempRate as NSNumber) ?? "0"
|
|
|
- var manualBasalString = ""
|
|
|
|
|
|
- if let apsManager = state.apsManager, apsManager.isManualTempBasal {
|
|
|
- manualBasalString = String(
|
|
|
- localized:
|
|
|
- " - Manual Basal ⚠️",
|
|
|
- comment: "Manual Temp basal"
|
|
|
- )
|
|
|
+ if apsManager.isScheduledBasal == true {
|
|
|
+ guard let scheduledRate = scheduledBasalDeliveryRate(at: Date()) else {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ rate = scheduledRate
|
|
|
+ } else {
|
|
|
+ guard let lastTempBasal = state.tempBasals.last?.tempBasal, let tempRate = lastTempBasal.rate else {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ if apsManager.isManualTempBasal {
|
|
|
+ manualBasalString = String(
|
|
|
+ localized: " - Manual Basal ⚠️",
|
|
|
+ comment: "Manual Temp basal"
|
|
|
+ )
|
|
|
+ }
|
|
|
+ rate = tempRate
|
|
|
}
|
|
|
|
|
|
- return rateString + String(localized: " U/hr", comment: "Unit per hour with space") + manualBasalString
|
|
|
+ let rateString = Formatter.decimalFormatterWithTwoFractionDigits.string(from: rate) ?? "0"
|
|
|
+ return rateString + String(localized: " U/hr", comment: "Unit per hour with space") +
|
|
|
+ manualBasalString
|
|
|
+ }
|
|
|
+
|
|
|
+ // Returns the scheduled basal rate for the current time based on the saved basal scheduled.
|
|
|
+ // Would be better if in the future BasalDeliveryStatus could be updated to include this info.
|
|
|
+ func scheduledBasalDeliveryRate(at when: Date) -> NSNumber? {
|
|
|
+ let calendar = Calendar(identifier: .gregorian)
|
|
|
+ // calendar.timeZone = timeZone /// should come from pumpManager in case it's different!
|
|
|
+
|
|
|
+ let hours = calendar.component(.hour, from: when)
|
|
|
+ let minutes = calendar.component(.minute, from: when)
|
|
|
+ let totalMinutes = hours * 60 + minutes
|
|
|
+
|
|
|
+ if let rate = findBasalRateForOffset(for: totalMinutes, in: state.basalProfile) {
|
|
|
+ return NSDecimalNumber(decimal: rate)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
var overrideString: String? {
|
|
|
@@ -467,31 +496,34 @@ extension Home {
|
|
|
.font(.callout)
|
|
|
} else {
|
|
|
HStack {
|
|
|
- if state.pumpSuspended {
|
|
|
- Text("Pump suspended")
|
|
|
- .font(.callout).fontWeight(.bold).fontDesign(.rounded)
|
|
|
- .foregroundColor(.loopGray)
|
|
|
- } else if let tempBasalString = tempBasalString {
|
|
|
+ /// Only display the insulin delivery rate info if the pump is not
|
|
|
+ /// suspended and is available (e.g., pod is paired & not faulted).
|
|
|
+ let pumpAvailable = state.apsManager.isScheduledBasal != nil
|
|
|
+ if !state.apsManager.isSuspended && pumpAvailable {
|
|
|
Image(systemName: "drop.circle")
|
|
|
.font(.callout)
|
|
|
.foregroundColor(.insulinTintColor)
|
|
|
- if tempBasalString.count > 5 {
|
|
|
- Text(tempBasalString)
|
|
|
- .font(.callout).fontWeight(.bold).fontDesign(.rounded)
|
|
|
- .lineLimit(1)
|
|
|
- .minimumScaleFactor(0.85)
|
|
|
- .truncationMode(.tail)
|
|
|
- .allowsTightening(true)
|
|
|
+ if let basalString = self.basalString {
|
|
|
+ /// Adjust opacity when displaying a scheduled basal rate
|
|
|
+ let opacity = state.apsManager?.isScheduledBasal == true ? 0.6 : 1.0
|
|
|
+ if basalString.count > 5 {
|
|
|
+ Text(basalString)
|
|
|
+ .font(.callout).fontWeight(.bold).fontDesign(.rounded)
|
|
|
+ .lineLimit(1)
|
|
|
+ .minimumScaleFactor(0.85)
|
|
|
+ .truncationMode(.tail)
|
|
|
+ .allowsTightening(true)
|
|
|
+ .opacity(opacity)
|
|
|
+ } else {
|
|
|
+ // Short strings can just display normally
|
|
|
+ Text(basalString)
|
|
|
+ .font(.callout).fontWeight(.bold).fontDesign(.rounded)
|
|
|
+ .opacity(opacity)
|
|
|
+ }
|
|
|
} else {
|
|
|
- // Short strings can just display normally
|
|
|
- Text(tempBasalString).font(.callout).fontWeight(.bold).fontDesign(.rounded)
|
|
|
+ Text("No Data")
|
|
|
+ .font(.callout).fontWeight(.bold).fontDesign(.rounded)
|
|
|
}
|
|
|
- } else {
|
|
|
- Image(systemName: "drop.circle")
|
|
|
- .font(.callout)
|
|
|
- .foregroundColor(.insulinTintColor)
|
|
|
- Text("No Data")
|
|
|
- .font(.callout).fontWeight(.bold).fontDesign(.rounded)
|
|
|
}
|
|
|
}
|
|
|
}
|