]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homematic] Fix updating enum config values (#14213)
authormaniac103 <dannybaumann@web.de>
Fri, 13 Jan 2023 15:25:26 +0000 (16:25 +0100)
committerGitHub <noreply@github.com>
Fri, 13 Jan 2023 15:25:26 +0000 (16:25 +0100)
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 <dannybaumann@web.de>
bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java

index f04a1d8ddd7c3892513332bb09a94096310b6c18..542fac8073e2a9e0b37c23f6911c164714a503c2 100644 (file)
@@ -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);
                                 }
                             }