Skip to content

Commit

Permalink
[homekit] get min/max/step values from state description if possible (o…
Browse files Browse the repository at this point in the history
…penhab#13510)

this helps to auto-configure if the binding is providing the necessary info

metadata config still overrides

Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer authored and andan67 committed Nov 5, 2022
1 parent c512d8a commit 3353002
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;

Expand Down Expand Up @@ -283,7 +284,27 @@ public boolean isMemberOfAccessoryGroup() {
@SuppressWarnings({ "null", "unchecked" })
public <T> 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;
Expand Down

0 comments on commit 3353002

Please sign in to comment.