Skip to content

Commit c8c16f0

Browse files
implememt as enum
Signed-off-by: Holger Friedrich <[email protected]>
1 parent dcae562 commit c8c16f0

File tree

1 file changed

+20
-3
lines changed
  • mobile/src/main/java/org/openhab/habdroid/model

1 file changed

+20
-3
lines changed

mobile/src/main/java/org/openhab/habdroid/model/Widget.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ data class Widget(
6565
val legend: Boolean?,
6666
val forceAsItem: Boolean,
6767
val yAxisDecimalPattern: String?,
68-
val interpolation: String?,
68+
val interpolation: Interpolation?,
6969
val switchSupport: Boolean,
7070
val releaseOnly: Boolean?,
7171
val height: Int,
@@ -150,6 +150,15 @@ data class Widget(
150150
Datetime
151151
}
152152

153+
enum class Interpolation {
154+
Linear,
155+
Step
156+
157+
override fun toString(): String {
158+
return name.lowercase()
159+
}
160+
}
161+
153162
enum class LabelSource {
154163
Unknown,
155164
ItemLabel,
@@ -186,7 +195,7 @@ data class Widget(
186195
chartTheme?.let { chartUrl.appendQueryParameter("theme", it.toString()) }
187196
forcedLegend?.let { chartUrl.appendQueryParameter("legend", it) }
188197
yAxisDecimalPattern?.let { chartUrl.appendQueryParameter("yAxisDecimalPattern", it) }
189-
interpolation?.let { chartUrl.appendQueryParameter("interpolation", it) }
198+
interpolation?.let { chartUrl.appendQueryParameter("interpolation", it.toString()) }
190199

191200
if (width > 0) {
192201
chartUrl.appendQueryParameter("w", width / resDivider)
@@ -277,6 +286,14 @@ fun String?.toInputHint(): Widget.InputTypeHint? = this?.let { value ->
277286
}
278287
}
279288

289+
fun String?.toInterpolation(): Widget.Interplation? = this?.let { value ->
290+
try {
291+
return Interpolation.valueOf(value.lowercase().replaceFirstChar { c -> c.uppercase() })
292+
} catch (e: IllegalArgumentException) {
293+
return null
294+
}
295+
}
296+
280297
fun String?.toLabelSource(): Widget.LabelSource = when (this) {
281298
"SITEMAP_WIDGET" -> Widget.LabelSource.SitemapDefinition
282299
"ITEM_LABEL" -> Widget.LabelSource.ItemLabel
@@ -436,7 +453,7 @@ fun JSONObject.collectWidgets(parent: Widget?): List<Widget> {
436453
legend = optBooleanOrNull("legend"),
437454
forceAsItem = optBoolean("forceAsItem", false),
438455
yAxisDecimalPattern = optString("yAxisDecimalPattern"),
439-
interpolation = optString("interpolation"),
456+
interpolation = optString("interpolation").toInterpolation(),
440457
switchSupport = optBoolean("switchSupport", false),
441458
releaseOnly = optBooleanOrNull("releaseOnly"),
442459
height = optInt("height"),

0 commit comments

Comments
 (0)