From 0aa28e5d4065385c228fa822aa5f0ba9f41c0fb0 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Sun, 9 Oct 2022 02:55:32 -0600 Subject: [PATCH] [homekit] get min/max/step values from state description if possible (#13510) this helps to auto-configure if the binding is providing the necessary info metadata config still overrides Signed-off-by: Cody Cutrer --- .../homekit/internal/HomekitTaggedItem.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitTaggedItem.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitTaggedItem.java index 0ba3c2e63..04e3ba31a 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitTaggedItem.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitTaggedItem.java @@ -32,6 +32,7 @@ import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.PercentType; import org.openhab.core.library.types.StringType; import org.openhab.core.types.State; +import org.openhab.core.types.StateDescription; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -283,7 +284,27 @@ public class HomekitTaggedItem { @SuppressWarnings({ "null", "unchecked" }) public T getConfiguration(String key, T defaultValue) { if (configuration != null) { - final @Nullable Object value = configuration.get(key); + @Nullable + Object value = configuration.get(key); + // No explicit configuration, but for certain things we can check the state description + // to see if the binding provided it + if (value == null) { + final @Nullable StateDescription stateDescription = getItem().getStateDescription(); + if (stateDescription != null) { + switch (key) { + case MIN_VALUE: + value = stateDescription.getMinimum(); + break; + case MAX_VALUE: + value = stateDescription.getMaximum(); + break; + case STEP: + value = stateDescription.getStep(); + break; + } + } + } + if (value != null) { if (value.getClass().equals(defaultValue.getClass())) { return (T) value;