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))