]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homematic] Better OH3 compatibility (#9102)
authorMartin Herbst <develop@mherbst.de>
Mon, 23 Nov 2020 10:10:08 +0000 (11:10 +0100)
committerGitHub <noreply@github.com>
Mon, 23 Nov 2020 10:10:08 +0000 (11:10 +0100)
* Max value and format pattern were not correct for dimmers (Fixes #8799)
* Fixed calls to deprecates methods/constructors
* Make sure channelLinked is executed at restart (see also: https://github.com/openhab/openhab-core/issues/1707)

Signed-off-by: Martin Herbst <develop@mherbst.de>
bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/HomematicBindingConstants.java
bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java
bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/HomematicTypeGeneratorImpl.java
bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java

index d27ec1759c1739c50e40caaa3df0cb7b3a8e6106..b1f69aaaa0b29dc6806f9151ed467b8bbefefd54 100644 (file)
@@ -58,7 +58,6 @@ public class HomematicBindingConstants {
     public static final String CATEGORY_ENERGY = "Energy";
     public static final String CATEGORY_BLINDS = "Blinds";
     public static final String CATEGORY_CONTACT = "Contact";
-    public static final String CATEGORY_DIMMABLE_LIGHT = "DimmableLight";
     public static final String CATEGORY_SWITCH = "Switch";
 
     public static final String PROPERTY_BATTERY_TYPE = "batteryType";
index 788001f2562e2d1bc7a3887b37995c8414007083..47e8b336fc69cd2a4e971d7ff4aa1fcafa089d44 100644 (file)
@@ -150,6 +150,12 @@ public class HomematicThingHandler extends BaseThingHandler {
         if (updateDynamicChannelList(device, thingChannels)) {
             updateThing(editThing().withChannels(thingChannels).build());
         }
+
+        thingChannels.forEach(channel -> {
+            if (isLinked(channel.getUID())) {
+                channelLinked(channel.getUID());
+            }
+        });
     }
 
     /**
index 948ca9179f7bda96f5fa965fd472eb31df4f36c1..f946032e09499989297e4a1041aad2c5a7758002 100644 (file)
@@ -37,6 +37,7 @@ import org.openhab.core.config.core.ConfigDescriptionBuilder;
 import org.openhab.core.config.core.ConfigDescriptionParameter;
 import org.openhab.core.config.core.ConfigDescriptionParameterBuilder;
 import org.openhab.core.config.core.ConfigDescriptionParameterGroup;
+import org.openhab.core.config.core.ConfigDescriptionParameterGroupBuilder;
 import org.openhab.core.config.core.ParameterOption;
 import org.openhab.core.thing.DefaultSystemChannelTypeProvider;
 import org.openhab.core.thing.Thing;
@@ -277,10 +278,17 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
             if (dp.isNumberType()) {
                 BigDecimal min = MetadataUtils.createBigDecimal(dp.getMinValue());
                 BigDecimal max = MetadataUtils.createBigDecimal(dp.getMaxValue());
-
                 BigDecimal step = MetadataUtils.createBigDecimal(dp.getStep());
-                if (step == null) {
-                    step = MetadataUtils.createBigDecimal(dp.isFloatType() ? new Float(0.1) : new Long(1L));
+                if (ITEM_TYPE_DIMMER.equals(itemType) && dp.getMaxValue().doubleValue() == 1.01d) {
+                    // For dimmers with a max value of 1.01 the values must be corrected
+                    min = MetadataUtils.createBigDecimal(0);
+                    max = MetadataUtils.createBigDecimal(100);
+                    step = MetadataUtils.createBigDecimal(1);
+                } else {
+                    if (step == null) {
+                        step = MetadataUtils
+                                .createBigDecimal(dp.isFloatType() ? Float.valueOf(0.1f) : Long.valueOf(1L));
+                    }
                 }
                 stateFragment.withMinimum(min).withMaximum(max).withStep(step)
                         .withPattern(MetadataUtils.getStatePattern(dp)).withReadOnly(dp.isReadOnly());
@@ -305,7 +313,7 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
                         .withEventDescription(eventDescription);
             } else {
                 channelTypeBuilder = ChannelTypeBuilder.state(channelTypeUID, label, itemType)
-                        .withStateDescription(stateFragment.build().toStateDescription());
+                        .withStateDescriptionFragment(stateFragment.build());
             }
             channelType = channelTypeBuilder.isAdvanced(!MetadataUtils.isStandard(dp)).withDescription(description)
                     .withCategory(category).withConfigDescriptionURI(configDescriptionUriChannel).build();
@@ -320,7 +328,7 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
         for (HmChannel channel : device.getChannels()) {
             String groupName = "HMG_" + channel.getNumber();
             String groupLabel = MetadataUtils.getDescription("CHANNEL_NAME") + " " + channel.getNumber();
-            groups.add(new ConfigDescriptionParameterGroup(groupName, null, false, groupLabel, null));
+            groups.add(ConfigDescriptionParameterGroupBuilder.create(groupName).withLabel(groupLabel).build());
 
             for (HmDatapoint dp : channel.getDatapoints()) {
                 if (dp.getParamsetType() == HmParamsetType.MASTER) {
@@ -346,8 +354,8 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
                     if (dp.isNumberType()) {
                         builder.withMinimum(MetadataUtils.createBigDecimal(dp.getMinValue()));
                         builder.withMaximum(MetadataUtils.createBigDecimal(dp.getMaxValue()));
-                        builder.withStepSize(
-                                MetadataUtils.createBigDecimal(dp.isFloatType() ? new Float(0.1) : new Long(1L)));
+                        builder.withStepSize(MetadataUtils
+                                .createBigDecimal(dp.isFloatType() ? Float.valueOf(0.1f) : Long.valueOf(1L)));
                         builder.withUnitLabel(MetadataUtils.getUnit(dp));
                     }
 
index ec92206021de468ac0817be6bce29c5f7df8bcdb..25a29017208f89233618882e57bb3b894893c4b3 100644 (file)
@@ -166,6 +166,9 @@ public class MetadataUtils {
      */
     public static String getStatePattern(HmDatapoint dp) {
         String unit = getUnit(dp);
+        if ("%%".equals(unit)) {
+            return "%d %%";
+        }
         if (unit != null && unit != "") {
             String pattern = getPattern(dp);
             if (pattern != null) {
@@ -388,7 +391,7 @@ public class MetadataUtils {
         } else if (itemType.equals(ITEM_TYPE_CONTACT)) {
             return CATEGORY_CONTACT;
         } else if (itemType.equals(ITEM_TYPE_DIMMER)) {
-            return CATEGORY_DIMMABLE_LIGHT;
+            return "";
         } else if (itemType.equals(ITEM_TYPE_SWITCH)) {
             return CATEGORY_SWITCH;
         } else {