refactor: change Percent-Charged header from Double to Int

- Update TrmnlApiService to accept Int? instead of Double?
- Update TrmnlDeviceUpdateRequest percentCharged field to Int?
- Remove .toDouble() conversions in TrmnlDisplayRepository
- Update test assertions to use Int values
- Eliminates unnecessary type conversions since battery level is already an Int
This commit is contained in:
Hossain Khan
2026-02-05 20:08:25 -05:00
parent 834b8fc77a
commit 073961f4ae
4 changed files with 15 additions and 15 deletions
@@ -86,7 +86,7 @@ class TrmnlDisplayRepository
// https://github.com/usetrmnl/trmnl-android/issues/252
// https://github.com/usetrmnl/trmnl-android/issues/239
// https://discord.com/channels/1281055965508141100/1466030731770855434/1469103763846463620
androidDeviceInfoProvider.getBatteryLevel()?.toDouble()
androidDeviceInfoProvider.getBatteryLevel()
} else {
null
},
@@ -434,7 +434,7 @@ class TrmnlDisplayRepository
sleepModeEnabled = false,
sleepStartTime = 1320,
sleepEndTime = 480,
percentCharged = 100.0,
percentCharged = 100,
wifiStrength = 100.0,
)
@@ -567,7 +567,7 @@ class TrmnlDisplayRepository
return Result.success(Unit)
}
val updateRequest = TrmnlDeviceUpdateRequest(percentCharged = batteryPercent.toDouble())
val updateRequest = TrmnlDeviceUpdateRequest(percentCharged = batteryPercent)
val apiUrl = constructApiUrl(config.apiBaseUrl, DEVICE_API_PATH.replace("{id}", deviceId.toString()))
val result =
@@ -105,7 +105,7 @@ interface TrmnlApiService {
@Header("ID") deviceMacId: String? = null,
@Header("BASE64") useBase64: Boolean? = null,
@Header("RSSI") rssi: Int? = null,
@Header("Percent-Charged") percentCharged: Double? = null,
@Header("Percent-Charged") percentCharged: Int? = null,
): ApiResult<TrmnlDisplayResponse, Unit>
/**
@@ -38,5 +38,5 @@ data class TrmnlDeviceUpdateRequest(
@Json(name = "sleep_mode_enabled") val sleepModeEnabled: Boolean? = null,
@Json(name = "sleep_start_time") val sleepStartTime: Int? = null,
@Json(name = "sleep_end_time") val sleepEndTime: Int? = null,
@Json(name = "percent_charged") val percentCharged: Double? = null,
@Json(name = "percent_charged") val percentCharged: Int? = null,
)
@@ -630,7 +630,7 @@ class TrmnlDisplayRepositoryTest {
userApiService.updateDevice(
fullApiUrl = expectedApiUrl,
accessToken = "Bearer user_test_token",
updateRequest = match { it.percentCharged == 75.0 },
updateRequest = match { it.percentCharged == 75 },
)
}
}
@@ -724,7 +724,7 @@ class TrmnlDisplayRepositoryTest {
deviceMacId = any(),
useBase64 = any(),
rssi = expectedRssi,
percentCharged = expectedBattery.toDouble(),
percentCharged = expectedBattery,
)
} returns ApiResult.success(mockk(relaxed = true))
@@ -740,7 +740,7 @@ class TrmnlDisplayRepositoryTest {
deviceMacId = any(),
useBase64 = any(),
rssi = expectedRssi,
percentCharged = expectedBattery.toDouble(),
percentCharged = expectedBattery,
)
}
}
@@ -773,7 +773,7 @@ class TrmnlDisplayRepositoryTest {
deviceMacId = any(),
useBase64 = any(),
rssi = null,
percentCharged = expectedBattery.toDouble(),
percentCharged = expectedBattery,
)
}
}
@@ -858,7 +858,7 @@ class TrmnlDisplayRepositoryTest {
deviceMacId = any(),
useBase64 = any(),
rssi = any(),
percentCharged = 75.0,
percentCharged = 75,
)
} returns ApiResult.success(mockk(relaxed = true))
@@ -874,7 +874,7 @@ class TrmnlDisplayRepositoryTest {
deviceMacId = any(),
useBase64 = any(),
rssi = any(),
percentCharged = 75.0,
percentCharged = 75,
)
}
}
@@ -1035,7 +1035,7 @@ class TrmnlDisplayRepositoryTest {
deviceMacId = any(),
useBase64 = any(),
rssi = strongSignal,
percentCharged = expectedBattery.toDouble(),
percentCharged = expectedBattery,
)
} returns ApiResult.success(mockk(relaxed = true))
@@ -1050,7 +1050,7 @@ class TrmnlDisplayRepositoryTest {
deviceMacId = any(),
useBase64 = any(),
rssi = strongSignal,
percentCharged = expectedBattery.toDouble(),
percentCharged = expectedBattery,
)
}
}
@@ -1073,7 +1073,7 @@ class TrmnlDisplayRepositoryTest {
deviceMacId = any(),
useBase64 = any(),
rssi = weakSignal,
percentCharged = expectedBattery.toDouble(),
percentCharged = expectedBattery,
)
} returns ApiResult.success(mockk(relaxed = true))
@@ -1088,7 +1088,7 @@ class TrmnlDisplayRepositoryTest {
deviceMacId = any(),
useBase64 = any(),
rssi = weakSignal,
percentCharged = expectedBattery.toDouble(),
percentCharged = expectedBattery,
)
}
}