comboctl: Apply ktlint based fixes

Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
This commit is contained in:
Carlos Rafael Giani 2022-12-30 22:01:28 +01:00
parent 19871d8f52
commit 8d9e5cc833
17 changed files with 53 additions and 51 deletions

View file

@ -1,8 +1,5 @@
package info.nightscout.comboctl.android package info.nightscout.comboctl.android
import android.bluetooth.BluetoothAdapter as SystemBluetoothAdapter
import android.bluetooth.BluetoothDevice as SystemBluetoothDevice
import android.bluetooth.BluetoothSocket as SystemBluetoothSocket
import android.content.Context import android.content.Context
import info.nightscout.comboctl.base.BluetoothAddress import info.nightscout.comboctl.base.BluetoothAddress
import info.nightscout.comboctl.base.BluetoothDevice import info.nightscout.comboctl.base.BluetoothDevice
@ -12,11 +9,14 @@ import info.nightscout.comboctl.base.ComboIOException
import info.nightscout.comboctl.base.LogLevel import info.nightscout.comboctl.base.LogLevel
import info.nightscout.comboctl.base.Logger import info.nightscout.comboctl.base.Logger
import info.nightscout.comboctl.utils.retryBlocking import info.nightscout.comboctl.utils.retryBlocking
import kotlinx.coroutines.Dispatchers
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
import java.util.Locale import java.util.Locale
import kotlinx.coroutines.Dispatchers import android.bluetooth.BluetoothAdapter as SystemBluetoothAdapter
import android.bluetooth.BluetoothDevice as SystemBluetoothDevice
import android.bluetooth.BluetoothSocket as SystemBluetoothSocket
private val logger = Logger.get("AndroidBluetoothDevice") private val logger = Logger.get("AndroidBluetoothDevice")

View file

@ -1,11 +1,6 @@
package info.nightscout.comboctl.android package info.nightscout.comboctl.android
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.bluetooth.BluetoothAdapter as SystemBluetoothAdapter
import android.bluetooth.BluetoothDevice as SystemBluetoothDevice
import android.bluetooth.BluetoothManager as SystemBluetoothManager
import android.bluetooth.BluetoothServerSocket as SystemBluetoothServerSocket
import android.bluetooth.BluetoothSocket as SystemBluetoothSocket
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
@ -20,6 +15,11 @@ import info.nightscout.comboctl.base.toBluetoothAddress
import java.io.IOException import java.io.IOException
import java.util.concurrent.locks.ReentrantLock import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.thread import kotlin.concurrent.thread
import android.bluetooth.BluetoothAdapter as SystemBluetoothAdapter
import android.bluetooth.BluetoothDevice as SystemBluetoothDevice
import android.bluetooth.BluetoothManager as SystemBluetoothManager
import android.bluetooth.BluetoothServerSocket as SystemBluetoothServerSocket
import android.bluetooth.BluetoothSocket as SystemBluetoothSocket
private val logger = Logger.get("AndroidBluetoothInterface") private val logger = Logger.get("AndroidBluetoothInterface")

View file

@ -138,7 +138,7 @@ class DisplayFrameAssembler {
// frame, this means it contains 8 pixel rows. This in turn means that this // frame, this means it contains 8 pixel rows. This in turn means that this
// layout stores one byte per column. So, the first byte in the display frame row // layout stores one byte per column. So, the first byte in the display frame row
// contains the pixels from (x 95 y 0) to (x 95 y 7). The second byte contains // contains the pixels from (x 95 y 0) to (x 95 y 7). The second byte contains
// pixels from (x 94 y 0) to (x 94 y 7) etc. // pixels from (x 94 y 0) to (x 94 y 7) etc.
for (row in 0 until 4) { for (row in 0 until 4) {
val rtDisplayFrameRow = rtDisplayFrameRows[row]!! val rtDisplayFrameRow = rtDisplayFrameRows[row]!!
for (column in 0 until DISPLAY_FRAME_WIDTH) { for (column in 0 until DISPLAY_FRAME_WIDTH) {

View file

@ -1,8 +1,8 @@
package info.nightscout.comboctl.base package info.nightscout.comboctl.base
import kotlin.reflect.KClassifier
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlin.reflect.KClassifier
private val logger = Logger.get("Pump") private val logger = Logger.get("Pump")

View file

@ -1,11 +1,11 @@
package info.nightscout.comboctl.base package info.nightscout.comboctl.base
import kotlin.math.max
import kotlin.math.min
import kotlinx.datetime.Clock import kotlinx.datetime.Clock
import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.atTime import kotlinx.datetime.atTime
import kotlin.math.max
import kotlin.math.min
// Utility function for cases when only the time and no date is known. // Utility function for cases when only the time and no date is known.
// monthNumber and dayOfMonth are set to 1 instead of 0 since 0 is // monthNumber and dayOfMonth are set to 1 instead of 0 since 0 is

View file

@ -29,10 +29,6 @@ import info.nightscout.comboctl.parser.BatteryState
import info.nightscout.comboctl.parser.MainScreenContent import info.nightscout.comboctl.parser.MainScreenContent
import info.nightscout.comboctl.parser.ParsedScreen import info.nightscout.comboctl.parser.ParsedScreen
import info.nightscout.comboctl.parser.ReservoirState import info.nightscout.comboctl.parser.ReservoirState
import kotlin.math.absoluteValue
import kotlin.time.Duration
import kotlin.time.DurationUnit
import kotlin.time.toDuration
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.NonCancellable
@ -53,6 +49,10 @@ import kotlinx.datetime.atStartOfDayIn
import kotlinx.datetime.offsetAt import kotlinx.datetime.offsetAt
import kotlinx.datetime.toInstant import kotlinx.datetime.toInstant
import kotlinx.datetime.toLocalDateTime import kotlinx.datetime.toLocalDateTime
import kotlin.math.absoluteValue
import kotlin.time.Duration
import kotlin.time.DurationUnit
import kotlin.time.toDuration
private val logger = Logger.get("Pump") private val logger = Logger.get("Pump")
@ -1747,7 +1747,10 @@ class Pump(
// the button, meaning that it will always press the button at least initially, // 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, // 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. // we miss entry #1, which is the current day.
val firstTDDScreen = navigateToRTScreen(rtNavigationContext, ParsedScreen.MyDataDailyTotalsScreen::class, pumpSuspended) as ParsedScreen.MyDataDailyTotalsScreen val firstTDDScreen = navigateToRTScreen(
rtNavigationContext,
ParsedScreen.MyDataDailyTotalsScreen::class,
pumpSuspended) as ParsedScreen.MyDataDailyTotalsScreen
processTDDScreen(firstTDDScreen) processTDDScreen(firstTDDScreen)
longPressRTButtonUntil(rtNavigationContext, RTNavigationButton.DOWN) { parsedScreen -> longPressRTButtonUntil(rtNavigationContext, RTNavigationButton.DOWN) { parsedScreen ->
@ -2523,7 +2526,8 @@ class Pump(
val expectedCurrentTbrPercentage = currentTbrState.tbr.percentage val expectedCurrentTbrPercentage = currentTbrState.tbr.percentage
val actualCurrentTbrPercentage = status.tbrPercentage val actualCurrentTbrPercentage = status.tbrPercentage
val elapsedTimeSinceTbrStart = now - currentTbrState.tbr.timestamp val elapsedTimeSinceTbrStart = now - currentTbrState.tbr.timestamp
val expectedRemainingDurationInMinutes = currentTbrState.tbr.durationInMinutes - elapsedTimeSinceTbrStart.inWholeMinutes.toInt() val expectedRemainingDurationInMinutes =
currentTbrState.tbr.durationInMinutes - elapsedTimeSinceTbrStart.inWholeMinutes.toInt()
val actualRemainingDurationInMinutes = status.remainingTbrDurationInMinutes val actualRemainingDurationInMinutes = status.remainingTbrDurationInMinutes
// The remaining duration check uses a tolerance range of 10 minutes, since // The remaining duration check uses a tolerance range of 10 minutes, since
@ -2765,7 +2769,8 @@ class Pump(
numRetrievedFactors++ numRetrievedFactors++
logger(LogLevel.DEBUG) { logger(LogLevel.DEBUG) {
"Got basal profile factor #$factorIndexOnScreen : $factor; $numRetrievedFactors factor(s) read and $numObservedScreens screen(s) observed thus far" "Got basal profile factor #$factorIndexOnScreen : $factor; $numRetrievedFactors " +
"factor(s) read and $numObservedScreens screen(s) observed thus far"
} }
getBasalProfileReporter.setCurrentProgressStage( getBasalProfileReporter.setCurrentProgressStage(

View file

@ -422,7 +422,7 @@ suspend fun longPressRTButtonUntil(
// that is documented in TransportLayer.IO.sendInternal().) // that is documented in TransportLayer.IO.sendInternal().)
val elapsedTime = getElapsedTimeInMs() - timestampBeforeDisplayFrameRetrieval val elapsedTime = getElapsedTimeInMs() - timestampBeforeDisplayFrameRetrieval
if (elapsedTime < MINIMUM_WAIT_PERIOD_DURING_LONG_RT_BUTTON_PRESS_IN_MS) { if (elapsedTime < MINIMUM_WAIT_PERIOD_DURING_LONG_RT_BUTTON_PRESS_IN_MS) {
val waitingPeriodInMs = MINIMUM_WAIT_PERIOD_DURING_LONG_RT_BUTTON_PRESS_IN_MS - elapsedTime val waitingPeriodInMs = MINIMUM_WAIT_PERIOD_DURING_LONG_RT_BUTTON_PRESS_IN_MS - elapsedTime
logger(LogLevel.VERBOSE) { "Waiting $waitingPeriodInMs milliseconds before continuing button long-press" } logger(LogLevel.VERBOSE) { "Waiting $waitingPeriodInMs milliseconds before continuing button long-press" }
delay(timeMillis = waitingPeriodInMs) delay(timeMillis = waitingPeriodInMs)
} }
@ -449,8 +449,7 @@ suspend fun longPressRTButtonUntil(
// Record the screen we just saw so we can return it. // Record the screen we just saw so we can return it.
lastParsedScreen = parsedScreen lastParsedScreen = parsedScreen
return@startLongButtonPress false return@startLongButtonPress false
} } else
else
return@startLongButtonPress true return@startLongButtonPress true
} }

View file

@ -4,10 +4,10 @@ import info.nightscout.comboctl.base.ComboException
import info.nightscout.comboctl.base.DisplayFrame import info.nightscout.comboctl.base.DisplayFrame
import info.nightscout.comboctl.base.combinedDateTime import info.nightscout.comboctl.base.combinedDateTime
import info.nightscout.comboctl.base.timeWithoutDate import info.nightscout.comboctl.base.timeWithoutDate
import kotlin.reflect.KClassifier
import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.atTime import kotlinx.datetime.atTime
import kotlin.reflect.KClassifier
/***************************************** /*****************************************
*** Screen and screen content classes *** *** Screen and screen content classes ***

View file

@ -3,11 +3,11 @@ package info.nightscout.comboctl.base
import info.nightscout.comboctl.base.testUtils.TestBluetoothDevice import info.nightscout.comboctl.base.testUtils.TestBluetoothDevice
import info.nightscout.comboctl.base.testUtils.TestPumpStateStore import info.nightscout.comboctl.base.testUtils.TestPumpStateStore
import info.nightscout.comboctl.base.testUtils.runBlockingWithWatchdog import info.nightscout.comboctl.base.testUtils.runBlockingWithWatchdog
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.channels.Channel
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.fail import kotlin.test.fail
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.channels.Channel
class PairingSessionTest { class PairingSessionTest {
enum class PacketDirection { enum class PacketDirection {

View file

@ -7,12 +7,12 @@ import info.nightscout.comboctl.base.testUtils.TestRefPacketItem
import info.nightscout.comboctl.base.testUtils.checkTestPacketSequence import info.nightscout.comboctl.base.testUtils.checkTestPacketSequence
import info.nightscout.comboctl.base.testUtils.produceTpLayerPacket import info.nightscout.comboctl.base.testUtils.produceTpLayerPacket
import info.nightscout.comboctl.base.testUtils.runBlockingWithWatchdog import info.nightscout.comboctl.base.testUtils.runBlockingWithWatchdog
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.datetime.LocalDateTime import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.UtcOffset import kotlinx.datetime.UtcOffset
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class PumpIOTest { class PumpIOTest {
// Common test code. // Common test code.

View file

@ -5,6 +5,8 @@ import info.nightscout.comboctl.base.testUtils.TestPumpStateStore
import info.nightscout.comboctl.base.testUtils.WatchdogTimeoutException import info.nightscout.comboctl.base.testUtils.WatchdogTimeoutException
import info.nightscout.comboctl.base.testUtils.coroutineScopeWithWatchdog import info.nightscout.comboctl.base.testUtils.coroutineScopeWithWatchdog
import info.nightscout.comboctl.base.testUtils.runBlockingWithWatchdog import info.nightscout.comboctl.base.testUtils.runBlockingWithWatchdog
import kotlinx.coroutines.Job
import kotlinx.datetime.UtcOffset
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
@ -13,8 +15,6 @@ import kotlin.test.assertIs
import kotlin.test.assertNotEquals import kotlin.test.assertNotEquals
import kotlin.test.assertNotNull import kotlin.test.assertNotNull
import kotlin.test.assertTrue import kotlin.test.assertTrue
import kotlinx.coroutines.Job
import kotlinx.datetime.UtcOffset
class TransportLayerTest { class TransportLayerTest {
@Test @Test

View file

@ -4,7 +4,6 @@ import info.nightscout.comboctl.base.BluetoothAddress
import info.nightscout.comboctl.base.BluetoothDevice import info.nightscout.comboctl.base.BluetoothDevice
import info.nightscout.comboctl.base.ComboFrameParser import info.nightscout.comboctl.base.ComboFrameParser
import info.nightscout.comboctl.base.ComboIO import info.nightscout.comboctl.base.ComboIO
import info.nightscout.comboctl.base.ProgressReporter
import info.nightscout.comboctl.base.byteArrayListOfInts import info.nightscout.comboctl.base.byteArrayListOfInts
import info.nightscout.comboctl.base.toComboFrame import info.nightscout.comboctl.base.toComboFrame
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope

View file

@ -6,8 +6,8 @@ import info.nightscout.comboctl.base.ComboIO
import info.nightscout.comboctl.base.TransportLayer import info.nightscout.comboctl.base.TransportLayer
import info.nightscout.comboctl.base.byteArrayListOfInts import info.nightscout.comboctl.base.byteArrayListOfInts
import info.nightscout.comboctl.base.toTransportLayerPacket import info.nightscout.comboctl.base.toTransportLayerPacket
import kotlin.test.assertNotNull
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlin.test.assertNotNull
class TestComboIO : ComboIO { class TestComboIO : ComboIO {
val sentPacketData = newTestPacketSequence() val sentPacketData = newTestPacketSequence()

View file

@ -4,14 +4,14 @@ import info.nightscout.comboctl.base.Cipher
import info.nightscout.comboctl.base.ComboException import info.nightscout.comboctl.base.ComboException
import info.nightscout.comboctl.base.Nonce import info.nightscout.comboctl.base.Nonce
import info.nightscout.comboctl.base.TransportLayer import info.nightscout.comboctl.base.TransportLayer
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.test.fail
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.test.fail
// Utility function to combine runBlocking() with a watchdog. // Utility function to combine runBlocking() with a watchdog.
// A coroutine is started with runBlocking(), and inside that // A coroutine is started with runBlocking(), and inside that

View file

@ -20,17 +20,17 @@ import info.nightscout.comboctl.parser.testFrameW6CancelTbrWarningScreen
import info.nightscout.comboctl.parser.testTimeAndDateSettingsHourPolishScreen import info.nightscout.comboctl.parser.testTimeAndDateSettingsHourPolishScreen
import info.nightscout.comboctl.parser.testTimeAndDateSettingsHourRussianScreen import info.nightscout.comboctl.parser.testTimeAndDateSettingsHourRussianScreen
import info.nightscout.comboctl.parser.testTimeAndDateSettingsHourTurkishScreen import info.nightscout.comboctl.parser.testTimeAndDateSettingsHourTurkishScreen
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.BeforeAll
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
import kotlin.test.assertIs import kotlin.test.assertIs
import kotlin.test.assertNotNull import kotlin.test.assertNotNull
import kotlin.test.assertNull import kotlin.test.assertNull
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.BeforeAll
class ParsedDisplayFrameStreamTest { class ParsedDisplayFrameStreamTest {
companion object { companion object {

View file

@ -13,13 +13,6 @@ import info.nightscout.comboctl.parser.MainScreenContent
import info.nightscout.comboctl.parser.ParsedScreen import info.nightscout.comboctl.parser.ParsedScreen
import info.nightscout.comboctl.parser.Quickinfo import info.nightscout.comboctl.parser.Quickinfo
import info.nightscout.comboctl.parser.ReservoirState import info.nightscout.comboctl.parser.ReservoirState
import kotlin.reflect.KClassifier
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertIs
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
@ -29,7 +22,14 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.datetime.LocalDateTime import kotlinx.datetime.LocalDateTime
import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeAll
import kotlin.reflect.KClassifier
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
import kotlin.test.assertIs
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
class RTNavigationTest { class RTNavigationTest {
/* RTNavigationContext implementation for testing out RTNavigation functionality. /* RTNavigationContext implementation for testing out RTNavigation functionality.
@ -360,7 +360,6 @@ class RTNavigationTest {
decrementButton = RTNavigationButton.DOWN decrementButton = RTNavigationButton.DOWN
) )
assertEquals(Pair(0, RTNavigationButton.CHECK), result) assertEquals(Pair(0, RTNavigationButton.CHECK), result)
} }
@Test @Test

View file

@ -2,12 +2,12 @@ package info.nightscout.comboctl.parser
import info.nightscout.comboctl.base.DisplayFrame import info.nightscout.comboctl.base.DisplayFrame
import info.nightscout.comboctl.base.timeWithoutDate import info.nightscout.comboctl.base.timeWithoutDate
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertNotNull import kotlin.test.assertNotNull
import kotlin.test.fail import kotlin.test.fail
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
class ParserTest { class ParserTest {
class TestContext(displayFrame: DisplayFrame, tokenOffset: Int, skipTitleString: Boolean = false, parseTopLeftTime: Boolean = false) { class TestContext(displayFrame: DisplayFrame, tokenOffset: Int, skipTitleString: Boolean = false, parseTopLeftTime: Boolean = false) {