From 4dd60bb4428a09bbb69f94943682f3a2340c928d Mon Sep 17 00:00:00 2001 From: maniac103 Date: Fri, 13 Jan 2023 16:25:26 +0100 Subject: [PATCH] [homematic] Fix updating enum config values (#14213) When changing an enum value in the configuration, we used the wrong data type: while the value in the OH config is a string (the 'option value' - see HomematicThingHandler::getValueForConfiguration), internally we use an integer (the 'option index'), so we have to do the option value -> option index conversion when applying the new value. This especially was a problem for HM-MOD-EM-8 devices, which check the CHANNEL_FUNCTION enum value as part of their initialization routine. When disabling/enabling them after changing the CHANNEL_FUNCTION enum value, they went offline, because their initialization failed due to a NumberFormatException (via HomematicThingHandler::doInitializeInBackground -> HmChannel::checkForChannelFunctionChange -> HmChannel::getCurrentFunction) Signed-off-by: Danny Baumann --- .../homematic/internal/handler/HomematicThingHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java index f04a1d8ddd7..542fac8073e 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java @@ -601,8 +601,10 @@ public class HomematicThingHandler extends BaseThingHandler { } else if (dp.isFloatType()) { newValue = decimal.doubleValue(); } + } else if (newValue instanceof String && dp.isEnumType()) { + newValue = dp.getOptionIndex((String) newValue); } - if (!Objects.equals(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(), newValue)) { + if (!Objects.equals(dp.getValue(), newValue)) { sendDatapoint(dp, new HmDatapointConfig(), newValue); } }