forked from LoopKit/G7SensorKit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlgorithmError.swift
More file actions
53 lines (47 loc) · 1.91 KB
/
Copy pathAlgorithmError.swift
File metadata and controls
53 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// AlgorithmError.swift
// G7SensorKit
//
// Created by Pete Schwamb on 11/11/22.
//
import Foundation
enum AlgorithmError: Error {
case unreliableState(AlgorithmState)
}
extension AlgorithmError: LocalizedError {
var errorDescription: String? {
switch self {
case .unreliableState:
return LocalizedString("Glucose data is unavailable", comment: "Error description for unreliable state")
}
}
var failureReason: String? {
switch self {
case .unreliableState(let state):
return state.localizedDescription
}
}
}
extension AlgorithmState {
public var localizedDescription: String {
switch self {
case .known(let state):
switch state {
case .ok:
return LocalizedString("Sensor is OK", comment: "The description of sensor algorithm state when sensor is ok.")
case .stopped:
return LocalizedString("Sensor is stopped", comment: "The description of sensor algorithm state when sensor is stopped.")
case .warmup, .temporarySensorIssue:
return LocalizedString("Sensor is warming up", comment: "The description of sensor algorithm state when sensor is warming up.")
case .expired:
return LocalizedString("Sensor expired", comment: "The description of sensor algorithm state when sensor is expired.")
case .sensorFailed:
return LocalizedString("Sensor failed", comment: "The description of sensor algorithm state when sensor failed.")
default:
return "Sensor state: \(String(describing: state))"
}
case .unknown(let rawValue):
return String(format: LocalizedString("Sensor is in unknown state %1$d", comment: "The description of sensor algorithm state when raw value is unknown. (1: missing data details)"), rawValue)
}
}
}