Indigo2 claim option

This commit is contained in:
Stian Fredrik Aune
2023-04-01 06:57:50 +02:00
parent 43b7627cee
commit e516c32ede
3 changed files with 5 additions and 3 deletions
+1 -2
View File
@@ -1,6 +1,5 @@
import {useContext, useEffect, useReducer} from "react"; import {useContext, useEffect, useReducer} from "react";
import RuntimeContext from "../contexts/RuntimeContext"; import RuntimeContext from "../contexts/RuntimeContext";
import {Values} from "../models/Shared";
import {WorkoutState} from "../models/Workouts"; import {WorkoutState} from "../models/Workouts";
interface UseKpmReducerState { interface UseKpmReducerState {
@@ -28,7 +27,7 @@ export function useKpm() {
return { return {
lastStates: [...inRange, newState], lastStates: [...inRange, newState],
kpm: inRange.length > 30 kpm: duration >= 30
? Math.round(((newState.calories || 0) - (first.calories || 0)) * 60 / duration) ? Math.round(((newState.calories || 0) - (first.calories || 0)) * 60 / duration)
: 0, : 0,
} }
@@ -26,6 +26,7 @@ class Indigo2(
private val oidcTokenEndpoint: String, private val oidcTokenEndpoint: String,
private val oidcClientId: String, private val oidcClientId: String,
private val oidcClientSecret: String, private val oidcClientSecret: String,
private val autoClaim: Boolean,
) : ExportTarget { ) : ExportTarget {
private val om = jacksonObjectMapper().apply { private val om = jacksonObjectMapper().apply {
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
@@ -67,7 +68,7 @@ class Indigo2(
"kind" to "ExerciseBike", "kind" to "ExerciseBike",
"measurements" to tm(chunks.first()), "measurements" to tm(chunks.first()),
), ),
"claimed" to true, "claimed" to autoClaim,
"date" to workout.date.toString(), "date" to workout.date.toString(),
"tags" to listOfNotNull( "tags" to listOfNotNull(
tag("ykonsole:Version", "2"), tag("ykonsole:Version", "2"),
@@ -111,12 +111,14 @@ private data class RepositorySet(
val tokenEndpoint = strEnv("INDIGO2_OIDC_TOKEN_ENDPOINT") val tokenEndpoint = strEnv("INDIGO2_OIDC_TOKEN_ENDPOINT")
val clientId = strEnv("INDIGO2_OIDC_CLIENT_ID") val clientId = strEnv("INDIGO2_OIDC_CLIENT_ID")
val clientSecret = strEnv("INDIGO2_OIDC_CLIENT_SECRET") val clientSecret = strEnv("INDIGO2_OIDC_CLIENT_SECRET")
val autoClaim = optStrEnv("INDIGO2_OIDC_AUTO_CLAIM").lowercase() in arrayOf("yes", "1", "true")
return Indigo2( return Indigo2(
indigoHost = indigo2Endpoint, indigoHost = indigo2Endpoint,
oidcTokenEndpoint = tokenEndpoint, oidcTokenEndpoint = tokenEndpoint,
oidcClientId = clientId, oidcClientId = clientId,
oidcClientSecret = clientSecret, oidcClientSecret = clientSecret,
autoClaim = autoClaim,
) )
} }