Skip to content

Commit

Permalink
Don't force on/yes/y/off/no/n to booleans for service button (home-as…
Browse files Browse the repository at this point in the history
…sistant#3858)

- Relax string conversion to boolean as this breaks other use cases.
  • Loading branch information
jpelgrom authored Sep 13, 2023
1 parent fb1bdc0 commit 50a8b9e
Showing 1 changed file with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,9 @@ class WidgetDynamicFieldAdapter(
}
}

private fun String.toBooleanOrNull(): Boolean? {
// Parse all valid YAML boolean values
return when (this.trim().lowercase(Locale.getDefault())) {
"true" -> true
"on" -> true
"yes" -> true
"y" -> true

"false" -> false
"off" -> false
"no" -> false
"n" -> false

// If it's not a valid YAML boolean, return null
else -> null
}
private fun String.toBooleanOrNull(): Boolean? = when (lowercase()) {
"true" -> true
"false" -> false
else -> null
}
}

0 comments on commit 50a8b9e

Please sign in to comment.