Skip to content

Commit

Permalink
#23 - Fixed training mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jnk-cons committed Jan 27, 2024
1 parent f6d3fdd commit 999be0c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,33 @@ 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
* @param asoc Percentage value that includes the condition of the battery taking ageing into account. A new battery theoretically has a value of 1.0 (100%)
* @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,
val inService: Boolean,
val asoc: Float,
val realRsoc: Float,
val voltage: Float,
val dcbStatus: List<DCBStatus>
val dcbStatus: List<DCBStatus>,
val trainingMode: TrainingMode
)

/**
Expand All @@ -105,3 +111,15 @@ data class DCBStatus(
val currentAVG30s: Float,
val temperaturesCelsius: List<Float>
)

/**
* Contains the status value of the battery training
*
* @since 2.2
*/
enum class TrainingMode {
NOT_IN_TRAINING,
TRAINING_DISCHARGE,
TRAINING_CHARGE,
UNKNOWN
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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+.*")
Expand All @@ -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+.*")
Expand Down

0 comments on commit 999be0c

Please sign in to comment.