From 38876647ad3c31e4d269f9ca4850e1321c8f0c85 Mon Sep 17 00:00:00 2001 From: Martin Herbst Date: Mon, 23 Nov 2020 11:10:08 +0100 Subject: [PATCH] [homematic] Better OH3 compatibility (#9102) * 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 --- .../internal/HomematicBindingConstants.java | 1 - .../handler/HomematicThingHandler.java | 6 +++++ .../type/HomematicTypeGeneratorImpl.java | 22 +++++++++++++------ .../internal/type/MetadataUtils.java | 5 ++++- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/HomematicBindingConstants.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/HomematicBindingConstants.java index d27ec1759..b1f69aaaa 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/HomematicBindingConstants.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/HomematicBindingConstants.java @@ -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"; 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 788001f25..47e8b336f 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 @@ -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()); + } + }); } /** diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/HomematicTypeGeneratorImpl.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/HomematicTypeGeneratorImpl.java index 948ca9179..f946032e0 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/HomematicTypeGeneratorImpl.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/HomematicTypeGeneratorImpl.java @@ -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)); } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java index ec9220602..25a290172 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java @@ -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 {