NSCv3: simplify enums

This commit is contained in:
Milos Kozak 2022-12-26 23:11:34 +01:00
parent c2e314bd42
commit 04e103848c
4 changed files with 7 additions and 54 deletions

View file

@ -18,12 +18,7 @@ fun NSBolus.toBolus(): Bolus =
) )
fun NSBolus.BolusType?.toBolusType(): Bolus.Type = fun NSBolus.BolusType?.toBolusType(): Bolus.Type =
when (this) { Bolus.Type.fromString(this?.name)
NSBolus.BolusType.NORMAL -> Bolus.Type.NORMAL
NSBolus.BolusType.SMB -> Bolus.Type.SMB
NSBolus.BolusType.PRIMING -> Bolus.Type.PRIMING
null -> Bolus.Type.NORMAL
}
fun Bolus.toNSBolus(): NSBolus = fun Bolus.toNSBolus(): NSBolus =
NSBolus( NSBolus(
@ -43,9 +38,4 @@ fun Bolus.toNSBolus(): NSBolus =
) )
fun Bolus.Type?.toBolusType(): NSBolus.BolusType = fun Bolus.Type?.toBolusType(): NSBolus.BolusType =
when (this) { NSBolus.BolusType.fromString(this?.name)
Bolus.Type.NORMAL -> NSBolus.BolusType.NORMAL
Bolus.Type.SMB -> NSBolus.BolusType.SMB
Bolus.Type.PRIMING -> NSBolus.BolusType.PRIMING
null -> NSBolus.BolusType.NORMAL
}

View file

@ -15,11 +15,4 @@ fun NSOfflineEvent.toOfflineEvent(): OfflineEvent =
) )
fun NSOfflineEvent.Reason?.toReason(): OfflineEvent.Reason = fun NSOfflineEvent.Reason?.toReason(): OfflineEvent.Reason =
when (this) { OfflineEvent.Reason.fromString(this?.name)
NSOfflineEvent.Reason.DISCONNECT_PUMP -> OfflineEvent.Reason.DISCONNECT_PUMP
NSOfflineEvent.Reason.SUSPEND -> OfflineEvent.Reason.SUSPEND
NSOfflineEvent.Reason.DISABLE_LOOP -> OfflineEvent.Reason.DISABLE_LOOP
NSOfflineEvent.Reason.SUPER_BOLUS -> OfflineEvent.Reason.SUPER_BOLUS
NSOfflineEvent.Reason.OTHER -> OfflineEvent.Reason.OTHER
null -> OfflineEvent.Reason.OTHER
}

View file

@ -20,14 +20,7 @@ fun NSTemporaryBasal.toTemporaryBasal(): TemporaryBasal =
) )
fun NSTemporaryBasal.Type?.toType(): TemporaryBasal.Type = fun NSTemporaryBasal.Type?.toType(): TemporaryBasal.Type =
when (this) { TemporaryBasal.Type.fromString(this?.name)
NSTemporaryBasal.Type.NORMAL -> TemporaryBasal.Type.NORMAL
NSTemporaryBasal.Type.EMULATED_PUMP_SUSPEND -> TemporaryBasal.Type.EMULATED_PUMP_SUSPEND
NSTemporaryBasal.Type.PUMP_SUSPEND -> TemporaryBasal.Type.PUMP_SUSPEND
NSTemporaryBasal.Type.SUPERBOLUS -> TemporaryBasal.Type.SUPERBOLUS
NSTemporaryBasal.Type.FAKE_EXTENDED -> TemporaryBasal.Type.FAKE_EXTENDED
null -> TemporaryBasal.Type.NORMAL
}
fun TemporaryBasal.toNSTemporaryBasal(profile: Profile): NSTemporaryBasal = fun TemporaryBasal.toNSTemporaryBasal(profile: Profile): NSTemporaryBasal =
NSTemporaryBasal( NSTemporaryBasal(
@ -49,11 +42,4 @@ fun TemporaryBasal.toNSTemporaryBasal(profile: Profile): NSTemporaryBasal =
) )
fun TemporaryBasal.Type?.toType(): NSTemporaryBasal.Type = fun TemporaryBasal.Type?.toType(): NSTemporaryBasal.Type =
when (this) { NSTemporaryBasal.Type.fromString(this?.name)
TemporaryBasal.Type.NORMAL -> NSTemporaryBasal.Type.NORMAL
TemporaryBasal.Type.EMULATED_PUMP_SUSPEND -> NSTemporaryBasal.Type.EMULATED_PUMP_SUSPEND
TemporaryBasal.Type.PUMP_SUSPEND -> NSTemporaryBasal.Type.PUMP_SUSPEND
TemporaryBasal.Type.SUPERBOLUS -> NSTemporaryBasal.Type.SUPERBOLUS
TemporaryBasal.Type.FAKE_EXTENDED -> NSTemporaryBasal.Type.FAKE_EXTENDED
null -> NSTemporaryBasal.Type.NORMAL
}

View file

@ -19,15 +19,7 @@ fun NSTemporaryTarget.toTemporaryTarget(): TemporaryTarget =
) )
fun NSTemporaryTarget.Reason?.toReason(): TemporaryTarget.Reason = fun NSTemporaryTarget.Reason?.toReason(): TemporaryTarget.Reason =
when (this) { TemporaryTarget.Reason.fromString(this?.text)
NSTemporaryTarget.Reason.CUSTOM -> TemporaryTarget.Reason.CUSTOM
NSTemporaryTarget.Reason.HYPOGLYCEMIA -> TemporaryTarget.Reason.HYPOGLYCEMIA
NSTemporaryTarget.Reason.ACTIVITY -> TemporaryTarget.Reason.ACTIVITY
NSTemporaryTarget.Reason.EATING_SOON -> TemporaryTarget.Reason.EATING_SOON
NSTemporaryTarget.Reason.AUTOMATION -> TemporaryTarget.Reason.AUTOMATION
NSTemporaryTarget.Reason.WEAR -> TemporaryTarget.Reason.WEAR
null -> TemporaryTarget.Reason.CUSTOM
}
fun TemporaryTarget.toNSTemporaryTarget(): NSTemporaryTarget = fun TemporaryTarget.toNSTemporaryTarget(): NSTemporaryTarget =
NSTemporaryTarget( NSTemporaryTarget(
@ -48,12 +40,4 @@ fun TemporaryTarget.toNSTemporaryTarget(): NSTemporaryTarget =
) )
fun TemporaryTarget.Reason?.toReason(): NSTemporaryTarget.Reason = fun TemporaryTarget.Reason?.toReason(): NSTemporaryTarget.Reason =
when (this) { NSTemporaryTarget.Reason.fromString(this?.text)
TemporaryTarget.Reason.CUSTOM -> NSTemporaryTarget.Reason.CUSTOM
TemporaryTarget.Reason.HYPOGLYCEMIA -> NSTemporaryTarget.Reason.HYPOGLYCEMIA
TemporaryTarget.Reason.ACTIVITY -> NSTemporaryTarget.Reason.ACTIVITY
TemporaryTarget.Reason.EATING_SOON -> NSTemporaryTarget.Reason.EATING_SOON
TemporaryTarget.Reason.AUTOMATION -> NSTemporaryTarget.Reason.AUTOMATION
TemporaryTarget.Reason.WEAR -> NSTemporaryTarget.Reason.WEAR
null -> NSTemporaryTarget.Reason.CUSTOM
}