comboctl-main: Fix missing entry #1 in TDD history

Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
Carlos Rafael Giani 2022-11-04 22:33:12 +01:00
parent 9aff10537e
commit 01560f45be

View file

@ -1661,22 +1661,15 @@ class Pump(
val currentSystemTimeZone = TimeZone.currentSystemDefault()
val currentLocalDate = currentSystemDateTime.toLocalDateTime(currentSystemTimeZone).date
navigateToRTScreen(rtNavigationContext, ParsedScreen.MyDataDailyTotalsScreen::class, pumpSuspended)
longPressRTButtonUntil(rtNavigationContext, RTNavigationButton.DOWN) { parsedScreen ->
if (parsedScreen !is ParsedScreen.MyDataDailyTotalsScreen) {
logger(LogLevel.DEBUG) { "Got a non-TDD screen ($parsedScreen) ; stopping TDD history scan" }
return@longPressRTButtonUntil LongPressRTButtonsCommand.ReleaseButton
}
fun processTDDScreen(dailyTotalsScreen: ParsedScreen.MyDataDailyTotalsScreen) {
val historyEntry = TDDHistoryEntry(
// Fix the date since the Combo does not show years in TDD screens.
date = parsedScreen.date.withFixedYearFrom(currentLocalDate).atStartOfDayIn(currentPumpUtcOffset!!.asTimeZone()),
totalDailyAmount = parsedScreen.totalDailyAmount
date = dailyTotalsScreen.date.withFixedYearFrom(currentLocalDate).atStartOfDayIn(currentPumpUtcOffset!!.asTimeZone()),
totalDailyAmount = dailyTotalsScreen.totalDailyAmount
)
logger(LogLevel.DEBUG) {
"Got TDD history entry ${parsedScreen.index} / ${parsedScreen.totalNumEntries} ; " +
"Got TDD history entry ${dailyTotalsScreen.index} / ${dailyTotalsScreen.totalNumEntries} ; " +
"date = ${historyEntry.date} ; " +
"TDD = ${historyEntry.totalDailyAmount.toStringWithDecimal(3)}"
}
@ -1684,8 +1677,26 @@ class Pump(
tddHistoryEntries.add(historyEntry)
tddHistoryProgressReporter.setCurrentProgressStage(
RTCommandProgressStage.FetchingTDDHistory(parsedScreen.index, parsedScreen.totalNumEntries)
RTCommandProgressStage.FetchingTDDHistory(dailyTotalsScreen.index, dailyTotalsScreen.totalNumEntries)
)
}
// Navigate to the TDD screens and process the very first shown TDD screen. We
// process the first screeen separately since the longPressRTButtonUntil() function
// uses the supplied block as a predicate to check if it should _continue_ pressing
// the button, meaning that it will always press the button at least initially,
// moving to entry #2 in the TDD history. Thus, if we don't look at the screen now,
// we miss entry #1, which is the current day.
val firstTDDScreen = navigateToRTScreen(rtNavigationContext, ParsedScreen.MyDataDailyTotalsScreen::class, pumpSuspended) as ParsedScreen.MyDataDailyTotalsScreen
processTDDScreen(firstTDDScreen)
longPressRTButtonUntil(rtNavigationContext, RTNavigationButton.DOWN) { parsedScreen ->
if (parsedScreen !is ParsedScreen.MyDataDailyTotalsScreen) {
logger(LogLevel.DEBUG) { "Got a non-TDD screen ($parsedScreen) ; stopping TDD history scan" }
return@longPressRTButtonUntil LongPressRTButtonsCommand.ReleaseButton
}
processTDDScreen(parsedScreen)
return@longPressRTButtonUntil if (parsedScreen.index >= parsedScreen.totalNumEntries)
LongPressRTButtonsCommand.ReleaseButton