From e516c32edee412fac0b1071a32a42bcb74a180fa Mon Sep 17 00:00:00 2001 From: Stian Fredrik Aune Date: Sat, 1 Apr 2023 06:57:50 +0200 Subject: [PATCH] Indigo2 claim option --- webui-react/src/hooks/kpm.ts | 3 +-- .../net/aiterp/git/ykonsole2/infrastructure/indigo2/Indigo2.kt | 3 ++- .../src/main/kotlin/net/aiterp/git/ykonsole2/Server.kt | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/webui-react/src/hooks/kpm.ts b/webui-react/src/hooks/kpm.ts index 80d386f..fc43309 100644 --- a/webui-react/src/hooks/kpm.ts +++ b/webui-react/src/hooks/kpm.ts @@ -1,6 +1,5 @@ import {useContext, useEffect, useReducer} from "react"; import RuntimeContext from "../contexts/RuntimeContext"; -import {Values} from "../models/Shared"; import {WorkoutState} from "../models/Workouts"; interface UseKpmReducerState { @@ -28,7 +27,7 @@ export function useKpm() { return { lastStates: [...inRange, newState], - kpm: inRange.length > 30 + kpm: duration >= 30 ? Math.round(((newState.calories || 0) - (first.calories || 0)) * 60 / duration) : 0, } 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 672003f..055a529 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 @@ -26,6 +26,7 @@ class Indigo2( private val oidcTokenEndpoint: String, private val oidcClientId: String, private val oidcClientSecret: String, + private val autoClaim: Boolean, ) : ExportTarget { private val om = jacksonObjectMapper().apply { configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) @@ -67,7 +68,7 @@ class Indigo2( "kind" to "ExerciseBike", "measurements" to tm(chunks.first()), ), - "claimed" to true, + "claimed" to autoClaim, "date" to workout.date.toString(), "tags" to listOfNotNull( tag("ykonsole:Version", "2"), 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 b66ba70..dd11c19 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 @@ -111,12 +111,14 @@ private data class RepositorySet( val tokenEndpoint = strEnv("INDIGO2_OIDC_TOKEN_ENDPOINT") val clientId = strEnv("INDIGO2_OIDC_CLIENT_ID") val clientSecret = strEnv("INDIGO2_OIDC_CLIENT_SECRET") + val autoClaim = optStrEnv("INDIGO2_OIDC_AUTO_CLAIM").lowercase() in arrayOf("yes", "1", "true") return Indigo2( indigoHost = indigo2Endpoint, oidcTokenEndpoint = tokenEndpoint, oidcClientId = clientId, oidcClientSecret = clientSecret, + autoClaim = autoClaim, ) }