From 999be0cb081cda23478e8ab434eb81f94f857022 Mon Sep 17 00:00:00 2001 From: Jochen Zink Date: Sat, 27 Jan 2024 23:32:52 +0100 Subject: [PATCH] #23 - Fixed training mode --- .../easyrscp/api/service/model/Battery.kt | 22 +++++++++++++++++-- .../easyrscp/service/DefaultBatteryService.kt | 12 ++++++++-- .../service/DefaultBatteryServiceTest.kt | 4 ++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/api/src/main/kotlin/de/jnkconsulting/e3dc/easyrscp/api/service/model/Battery.kt b/api/src/main/kotlin/de/jnkconsulting/e3dc/easyrscp/api/service/model/Battery.kt index 23923193..0c0ee3f0 100644 --- a/api/src/main/kotlin/de/jnkconsulting/e3dc/easyrscp/api/service/model/Battery.kt +++ b/api/src/main/kotlin/de/jnkconsulting/e3dc/easyrscp/api/service/model/Battery.kt @@ -62,7 +62,7 @@ data class DCBSpec( * Contains information on the current status of the battery * * @param index ID of the battery in the E3DC system - * @param trainingModeActive Information on whether the battery is in training mode + * @param trainingModeActive Information on whether the battery is in training mode. Deprecated in 2.2. Use [trainingMode] instead * @param connected Information on whether the battery is connected to the system (battery disconnect switch on the home power station) * @param working Information on whether the battery is working correctly * @param inService Information on whether the battery is in maintenance mode @@ -70,11 +70,16 @@ data class DCBSpec( * @param realRsoc Current charge level as a percentage of the battery without taking into account the reserve for absolute deep discharge and theoretically possible full charge. The value should therefore never reach completely 0 and never completely 1 * @param voltage Current battery voltage * @param dcbStatus Status of the individual battery modules + * @param trainingMode Current status of the training mode * * @since 2.1 + * @since 2.2 + * - new property [trainingMode] + * - deprecated property [trainingModeActive] -> Will be removed in 2.4 */ data class BatteryStatus( val index: Short, + @Deprecated("Use trainingMode Parameter instead. Will be removed in version 2.4") val trainingModeActive: Boolean, val connected: Boolean, val working: Boolean, @@ -82,7 +87,8 @@ data class BatteryStatus( val asoc: Float, val realRsoc: Float, val voltage: Float, - val dcbStatus: List + val dcbStatus: List, + val trainingMode: TrainingMode ) /** @@ -105,3 +111,15 @@ data class DCBStatus( val currentAVG30s: Float, val temperaturesCelsius: List ) + +/** + * Contains the status value of the battery training + * + * @since 2.2 + */ +enum class TrainingMode { + NOT_IN_TRAINING, + TRAINING_DISCHARGE, + TRAINING_CHARGE, + UNKNOWN +} diff --git a/service/src/main/kotlin/de/jnkconsulting/e3dc/easyrscp/service/DefaultBatteryService.kt b/service/src/main/kotlin/de/jnkconsulting/e3dc/easyrscp/service/DefaultBatteryService.kt index 18375caf..82e48019 100644 --- a/service/src/main/kotlin/de/jnkconsulting/e3dc/easyrscp/service/DefaultBatteryService.kt +++ b/service/src/main/kotlin/de/jnkconsulting/e3dc/easyrscp/service/DefaultBatteryService.kt @@ -112,17 +112,25 @@ class DefaultBatteryService( } )) } + val trainingModeRAW = batInfoResponse.byteByTag(BatTag.TRAINING_MODE, BatTag.DATA) + val trainingMode = when(trainingModeRAW) { + 0.toByte() -> TrainingMode.NOT_IN_TRAINING + 1.toByte() -> TrainingMode.TRAINING_DISCHARGE + 2.toByte() -> TrainingMode.TRAINING_CHARGE + else -> TrainingMode.UNKNOWN + } result.add( BatteryStatus( index = batIndex.toShort(), - trainingModeActive = batInfoResponse.byteByTag(BatTag.TRAINING_MODE, BatTag.DATA) != 0.toByte(), + trainingModeActive = trainingMode != TrainingMode.NOT_IN_TRAINING, connected = batInfoResponse.booleanByTag(BatTag.DEVICE_CONNECTED, BatTag.DATA, BatTag.DEVICE_STATE), working = batInfoResponse.booleanByTag(BatTag.DEVICE_WORKING, BatTag.DATA, BatTag.DEVICE_STATE), inService = batInfoResponse.booleanByTag(BatTag.DEVICE_IN_SERVICE, BatTag.DATA, BatTag.DEVICE_STATE), asoc = batInfoResponse.floatByTag(BatTag.ASOC, BatTag.DATA) / 100.0f, realRsoc = batInfoResponse.floatByTag(BatTag.RSOC_REAL, BatTag.DATA) / 100.0f, voltage = batInfoResponse.floatByTag(BatTag.MODULE_VOLTAGE, BatTag.DATA), - dcbStatus = dcbStatus + dcbStatus = dcbStatus, + trainingMode = trainingMode )) } result diff --git a/service/src/test/kotlin/de/jnkconsulting/e3dc/easyrscp/service/DefaultBatteryServiceTest.kt b/service/src/test/kotlin/de/jnkconsulting/e3dc/easyrscp/service/DefaultBatteryServiceTest.kt index 32d023a6..6da8f07d 100644 --- a/service/src/test/kotlin/de/jnkconsulting/e3dc/easyrscp/service/DefaultBatteryServiceTest.kt +++ b/service/src/test/kotlin/de/jnkconsulting/e3dc/easyrscp/service/DefaultBatteryServiceTest.kt @@ -5,7 +5,7 @@ import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable class DefaultBatteryServiceTest: IntegrationTestBase() { - @Test +// @Test @EnabledIfEnvironmentVariable(named = "E3DC_HOST", matches = ".*\\S+.*") @EnabledIfEnvironmentVariable(named = "E3DC_USER", matches = ".*\\S+.*") @EnabledIfEnvironmentVariable(named = "RSCP_PASSWORD", matches = ".*\\S+.*") @@ -16,7 +16,7 @@ class DefaultBatteryServiceTest: IntegrationTestBase() { println(result) } - //@Test + @Test @EnabledIfEnvironmentVariable(named = "E3DC_HOST", matches = ".*\\S+.*") @EnabledIfEnvironmentVariable(named = "E3DC_USER", matches = ".*\\S+.*") @EnabledIfEnvironmentVariable(named = "RSCP_PASSWORD", matches = ".*\\S+.*")