Skip to content

Commit

Permalink
Parse 0.1 as brightness 1
Browse files Browse the repository at this point in the history
Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma committed Jan 1, 2024
1 parent 6a9cb4c commit 40c7af4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.idea/ linguist-generated=false
.idea/* linguist-generated=false
11 changes: 8 additions & 3 deletions mobile/src/main/java/org/openhab/habdroid/model/ParsedState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ data class ParsedState internal constructor(
}
}
val stateAsFloat = state.toFloatOrNull() ?: return null
if (stateAsFloat in 0f .. 100f) {
return stateAsFloat.toInt()
return when (stateAsFloat) {
in 1f .. 100f, 0f -> {
stateAsFloat.toInt()
}
in 0f .. 1f -> {
1
}
else -> null
}
return null
}

private val HSB_PATTERN = Pattern.compile("^([0-9]*\\.?[0-9]+),([0-9]*\\.?[0-9]+),([0-9]*\\.?[0-9]+)$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ParsedStateTest {
mapOf(
"100" to 100,
"0" to 0,
"0.1" to 0, // TODO
"0.1" to 1,
"10,20,30" to 30
).forEach {
assertEquals("${it.key} should be parsed as ${it.value}", it.value, ParsedState.parseAsBrightness(it.key))
Expand Down

0 comments on commit 40c7af4

Please sign in to comment.