From 573060966591354a3d8bf5e5ed6e31d4157c0157 Mon Sep 17 00:00:00 2001 From: Stian Fredrik Aune Date: Thu, 24 Aug 2023 19:35:39 +0200 Subject: [PATCH] Quick and dirty calorie scale option --- .../aiterp/git/ykonsole2/infrastructure/indigo2/Indigo2.kt | 4 +++- .../src/main/kotlin/net/aiterp/git/ykonsole2/Server.kt | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ykonsole-exporter/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/indigo2/Indigo2.kt b/ykonsole-exporter/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/indigo2/Indigo2.kt index 055a529..4c119a9 100644 --- a/ykonsole-exporter/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/indigo2/Indigo2.kt +++ b/ykonsole-exporter/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/indigo2/Indigo2.kt @@ -20,6 +20,7 @@ import java.time.Instant import java.time.LocalDate import java.time.ZoneId import java.util.* +import kotlin.math.roundToInt class Indigo2( private val indigoHost: String, @@ -27,6 +28,7 @@ class Indigo2( private val oidcClientId: String, private val oidcClientSecret: String, private val autoClaim: Boolean, + private val calorieScale: Double = 1.0, ) : ExportTarget { private val om = jacksonObjectMapper().apply { configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) @@ -162,7 +164,7 @@ class Indigo2( if (ws.time.seconds > 0) mapOf( "seconds" to ws.time.toInt(), "meters" to ws.distance?.toInt(), - "calories" to ws.calories?.toInt(), + "calories" to ws.calories?.toInt()?.let { (it * calorieScale).roundToInt() }, "resistance" to ws.level?.toInt(), "rpmSpeed" to ws.rpmSpeed?.toInt(), "pulse" to ws.pulse?.toInt(), diff --git a/ykonsole-server/src/main/kotlin/net/aiterp/git/ykonsole2/Server.kt b/ykonsole-server/src/main/kotlin/net/aiterp/git/ykonsole2/Server.kt index d77c308..ad27761 100644 --- a/ykonsole-server/src/main/kotlin/net/aiterp/git/ykonsole2/Server.kt +++ b/ykonsole-server/src/main/kotlin/net/aiterp/git/ykonsole2/Server.kt @@ -112,6 +112,7 @@ private data class RepositorySet( val clientId = strEnv("INDIGO2_OIDC_CLIENT_ID") val clientSecret = strEnv("INDIGO2_OIDC_CLIENT_SECRET") val autoClaim = (optStrEnv("INDIGO2_OIDC_AUTO_CLAIM")?.lowercase() ?: "false") in arrayOf("yes", "1", "true") + val calorieScale = (optStrEnv("INDIGO2_EXPORT_CALORIE_SCALE")?.toDoubleOrNull()) ?: 1.0 return Indigo2( indigoHost = indigo2Endpoint, @@ -119,6 +120,7 @@ private data class RepositorySet( oidcClientId = clientId, oidcClientSecret = clientSecret, autoClaim = autoClaim, + calorieScale = calorieScale, ) }