Skip to content

Commit

Permalink
Consider mappings or options for displayed state
Browse files Browse the repository at this point in the history
One use case for this are items bound to channels of type
system.signal-strength. Those are number items with a default pattern of
%0.f and options mapping the valid values 0..4 to descriptive strings.
Show those descriptive strings (e.g. 'Excellent') if available instead of
the plain number value ('4').

Signed-off-by: Danny Baumann <[email protected]>
  • Loading branch information
maniac103 committed Mar 11, 2024
1 parent bf596dd commit 617922b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mobile/src/main/java/org/openhab/habdroid/model/Widget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ data class Widget(
val rawInputHint: InputTypeHint?
) : Parcelable {
val label get() = rawLabel.split("[", "]")[0].trim()
val stateFromLabel: String? get() = rawLabel.split("[", "]").getOrNull(1)?.trim()
val stateFromLabel: String? get() {
val value = rawLabel.split("[", "]").getOrNull(1)?.trim()
val optionLabel = mappingsOrItemOptions.find { it.value == value }?.label
return optionLabel ?: value
}

val mappingsOrItemOptions get() = if (mappings.isEmpty() && item?.options != null) item.options else mappings

Expand Down

0 comments on commit 617922b

Please sign in to comment.