comboctl-parser: Parse remaining duration in TBR percentage screen
Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
parent
cc26eb8ed8
commit
e9294c59a0
|
@ -147,7 +147,7 @@ sealed class ParsedScreen(val isBlinkedOut: Boolean = false) {
|
|||
val basalRateNumber: Int
|
||||
) : ParsedScreen(isBlinkedOut = (numUnits == null))
|
||||
|
||||
data class TemporaryBasalRatePercentageScreen(val percentage: Int?) :
|
||||
data class TemporaryBasalRatePercentageScreen(val percentage: Int?, val remainingDurationInMinutes: Int?) :
|
||||
ParsedScreen(isBlinkedOut = (percentage == null))
|
||||
data class TemporaryBasalRateDurationScreen(val durationInMinutes: Int?) :
|
||||
ParsedScreen(isBlinkedOut = (durationInMinutes == null))
|
||||
|
@ -1226,9 +1226,12 @@ class TemporaryBasalRatePercentageScreenParser : Parser() {
|
|||
val parseResult = SequenceParser(
|
||||
listOf(
|
||||
SingleGlyphParser(Glyph.LargeSymbol(LargeSymbol.BASAL)),
|
||||
OptionalParser(IntegerParser()),
|
||||
SingleGlyphParser(Glyph.LargeSymbol(LargeSymbol.PERCENT))
|
||||
)
|
||||
OptionalParser(IntegerParser()), // TBR percentage
|
||||
SingleGlyphParser(Glyph.LargeSymbol(LargeSymbol.PERCENT)),
|
||||
SingleGlyphParser(Glyph.SmallSymbol(SmallSymbol.ARROW)),
|
||||
TimeParser()
|
||||
),
|
||||
allowIncompleteSequences = true
|
||||
).parse(parseContext)
|
||||
|
||||
if (!parseResult.isSuccess)
|
||||
|
@ -1236,8 +1239,17 @@ class TemporaryBasalRatePercentageScreenParser : Parser() {
|
|||
|
||||
parseResult as ParseResult.Sequence
|
||||
|
||||
val remainingTbrDurationParseResult = if (parseResult.size >= 2)
|
||||
parseResult.valueAtOrNull<LocalDateTime>(1)
|
||||
else
|
||||
null
|
||||
val remainingTbrDurationInMinutes = remainingTbrDurationParseResult?.let { it.hour * 60 + it.minute } ?: 0
|
||||
|
||||
return ParseResult.Value(
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(percentage = parseResult.valueAtOrNull<Int>(0))
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(
|
||||
percentage = parseResult.valueAtOrNull<Int>(0),
|
||||
remainingDurationInMinutes = remainingTbrDurationInMinutes
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -360,7 +360,10 @@ class ParsedDisplayFrameStreamTest {
|
|||
val parsedFrameIter = parsedFrameList.listIterator()
|
||||
|
||||
assertEquals(2, parsedFrameList.size)
|
||||
assertEquals(ParsedScreen.TemporaryBasalRatePercentageScreen(percentage = 110), parsedFrameIter.next().parsedScreen)
|
||||
assertEquals(
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(percentage = 110, remainingDurationInMinutes = 30),
|
||||
parsedFrameIter.next().parsedScreen
|
||||
)
|
||||
assertEquals(ParsedScreen.TemporaryBasalRateDurationScreen(durationInMinutes = 30), parsedFrameIter.next().parsedScreen)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -498,8 +498,8 @@ class RTNavigationTest {
|
|||
batteryState = BatteryState.FULL_BATTERY
|
||||
)),
|
||||
ParsedScreen.TemporaryBasalRateMenuScreen,
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(percentage = 110),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(percentage = null),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(percentage = 110, remainingDurationInMinutes = 30),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(percentage = null, remainingDurationInMinutes = null),
|
||||
ParsedScreen.TemporaryBasalRateDurationScreen(durationInMinutes = 45)
|
||||
))
|
||||
|
||||
|
@ -727,18 +727,18 @@ class RTNavigationTest {
|
|||
// using short RT button presses until the target quantity is observed.
|
||||
|
||||
val rtNavigationContext = TestRTNavigationContext(listOf(
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(100),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(110),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(120),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(130),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(140),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(150),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(100, remainingDurationInMinutes = 30),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(110, remainingDurationInMinutes = 30),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(120, remainingDurationInMinutes = 30),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(130, remainingDurationInMinutes = 30),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(140, remainingDurationInMinutes = 30),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(150, remainingDurationInMinutes = 30),
|
||||
// No 160 quantity here, on purpose, to test overshoot handling
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(170),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(170),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(170),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(160),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(160)
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(170, remainingDurationInMinutes = 30),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(170, remainingDurationInMinutes = 30),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(170, remainingDurationInMinutes = 30),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(160, remainingDurationInMinutes = 30),
|
||||
ParsedScreen.TemporaryBasalRatePercentageScreen(160, remainingDurationInMinutes = 30)
|
||||
))
|
||||
|
||||
runBlockingWithWatchdog(6000) {
|
||||
|
|
|
@ -731,6 +731,17 @@ class ParserTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkTemporaryBasalRatePercentageScreenPercentAndDurationParsing() {
|
||||
val testContext = TestContext(testFrameTemporaryBasalRatePercentage110Screen, 0, skipTitleString = true)
|
||||
val result = TemporaryBasalRatePercentageScreenParser().parse(testContext.parseContext)
|
||||
assertEquals(ParseResult.Value::class, result::class)
|
||||
val screen = (result as ParseResult.Value<*>).value as ParsedScreen.TemporaryBasalRatePercentageScreen
|
||||
assertEquals(false, screen.isBlinkedOut)
|
||||
assertEquals(110, screen.percentage)
|
||||
assertEquals(30, screen.remainingDurationInMinutes)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkTemporaryBasalRateDurationScreenParsing() {
|
||||
val testScreens = listOf(
|
||||
|
|
Loading…
Reference in a new issue