From 40c7af40f3d7baee12583cedad1c98cbec0c2f01 Mon Sep 17 00:00:00 2001 From: mueller-ma Date: Mon, 1 Jan 2024 11:15:56 +0100 Subject: [PATCH] Parse 0.1 as brightness 1 Signed-off-by: mueller-ma --- .gitattributes | 2 +- .../java/org/openhab/habdroid/model/ParsedState.kt | 11 ++++++++--- .../org/openhab/habdroid/model/ParsedStateTest.kt | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.gitattributes b/.gitattributes index 24683a7b1c..0da8e1a09f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -.idea/ linguist-generated=false +.idea/* linguist-generated=false diff --git a/mobile/src/main/java/org/openhab/habdroid/model/ParsedState.kt b/mobile/src/main/java/org/openhab/habdroid/model/ParsedState.kt index 6e7893c4a7..5326b184af 100644 --- a/mobile/src/main/java/org/openhab/habdroid/model/ParsedState.kt +++ b/mobile/src/main/java/org/openhab/habdroid/model/ParsedState.kt @@ -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]+)$") diff --git a/mobile/src/test/java/org/openhab/habdroid/model/ParsedStateTest.kt b/mobile/src/test/java/org/openhab/habdroid/model/ParsedStateTest.kt index 61b4fa29b4..bd8a58240d 100644 --- a/mobile/src/test/java/org/openhab/habdroid/model/ParsedStateTest.kt +++ b/mobile/src/test/java/org/openhab/habdroid/model/ParsedStateTest.kt @@ -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))