diff --git a/OmniKit/Model/FaultEventCode.swift b/OmniKit/Model/FaultEventCode.swift index d70767015..160dbe23f 100644 --- a/OmniKit/Model/FaultEventCode.swift +++ b/OmniKit/Model/FaultEventCode.swift @@ -10,7 +10,7 @@ import Foundation public struct FaultEventCode: CustomStringConvertible, Equatable { - let rawValue: UInt8 + public let rawValue: UInt8 public enum FaultEventType: UInt8 { case noFaults = 0x00 @@ -387,4 +387,24 @@ public struct FaultEventCode: CustomStringConvertible, Equatable { } return String(format: "Fault Event Code 0x%02x: %@", rawValue, faultDescription) } + + public var localizedDescription: String { + if let faultType = faultType { + switch faultType { + case .reservoirEmpty: + return LocalizedString("Empty reservoir", comment: "Description for Empty reservoir pod fault") + case .exceededMaximumPodLife80Hrs: + return LocalizedString("Pod expired", comment: "Description for Pod expired pod fault") + case .occluded, + .occlusionCheckValueTooHigh, .occlusionCheckStartup1, .occlusionCheckStartup2, + .occlusionCheckTimeouts1, .occlusionCheckTimeouts2, .occlusionCheckTimeouts3, + .occlusionCheckPulseIssue, .occlusionCheckBolusProblem, .occlusionCheckAboveThreshold: + return LocalizedString("Occlusion detected", comment: "Description for Occlusion detected pod fault") + default: + return String(format: LocalizedString("Internal pod fault %1$03d", comment: "The format string for Internal pod fault (1: The fault code value)"), rawValue) + } + } else { + return String(format: LocalizedString("Unknown pod fault %1$03d", comment: "The format string for Unknown pod fault (1: The fault code value)"), rawValue) + } + } } diff --git a/OmniKitUI/ViewControllers/ReplacePodViewController.swift b/OmniKitUI/ViewControllers/ReplacePodViewController.swift index 19b6df104..b8e1bcc34 100644 --- a/OmniKitUI/ViewControllers/ReplacePodViewController.swift +++ b/OmniKitUI/ViewControllers/ReplacePodViewController.swift @@ -15,28 +15,25 @@ class ReplacePodViewController: SetupTableViewController { enum PodReplacementReason { case normal - case fault + case fault(_ faultCode: FaultEventCode) case canceledPairingBeforeApplication case canceledPairing } var replacementReason: PodReplacementReason = .normal { didSet { - if oldValue != replacementReason { - switch replacementReason { - case .normal: - break // Text set in interface builder - case .fault: - instructionsLabel.text = LocalizedString("The pod has detected an internal fault. Insulin delivery has stopped. Please remove pod and then deactivate it.", comment: "Instructions when replacing pod due to a fault") - case .canceledPairingBeforeApplication: - instructionsLabel.text = LocalizedString("Incompletely setup pod must be deactivated before pairing with a new one. Deactivate and discard pod.", comment: "Instructions when deactivating pod that has been paired, but not attached.") - case .canceledPairing: - instructionsLabel.text = LocalizedString("Incompletely setup pod must be deactivated before pairing with a new one. Please remove the pod and then deactivate it.", comment: "Instructions when deactivating pod that has been paired and possibly attached.") - break - } - - tableView.reloadData() + switch replacementReason { + case .normal: + break // Text set in interface builder + case .fault(let faultCode): + instructionsLabel.text = String(format: LocalizedString("%1$@. Insulin delivery has stopped. Please deactivate and remove pod.", comment: "Format string providing instructions for replacing pod due to a fault. (1: The fault description)"), faultCode.localizedDescription) + case .canceledPairingBeforeApplication: + instructionsLabel.text = LocalizedString("Incompletely set up pod must be deactivated before pairing with a new one. Please deactivate and discard pod.", comment: "Instructions when deactivating pod that has been paired, but not attached.") + case .canceledPairing: + instructionsLabel.text = LocalizedString("Incompletely set up pod must be deactivated before pairing with a new one. Please deactivate and remove pod.", comment: "Instructions when deactivating pod that has been paired and possibly attached.") } + + tableView.reloadData() } } @@ -44,8 +41,8 @@ class ReplacePodViewController: SetupTableViewController { didSet { pumpManager.getPodState { (podState) in DispatchQueue.main.async { - if podState?.fault != nil { - self.replacementReason = .fault + if let podFault = podState?.fault { + self.replacementReason = .fault(podFault.currentStatus) } else if podState?.setupProgress.primingNeeded == true { self.replacementReason = .canceledPairingBeforeApplication } else if podState?.setupProgress.needsCannulaInsertion == true {