From: maniac103 Date: Sat, 17 Jul 2021 21:33:08 +0000 (+0200) Subject: [homematic] Fix UI enumeration of HM-MOD-EM-8 channels (#10907) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=d8aacd86a099695d2730b2a9492e489f3ca2b197;p=openhab-addons.git [homematic] Fix UI enumeration of HM-MOD-EM-8 channels (#10907) The set of available HM-MOD-EM-8 channels varies depending on the function a given channel is configured to use, which is why for those devices we can't determine a static ThingType, but instead must populate the thing channels on initialization. The existing code already handled that case, but missed registering channel types for the dynamically generated channels, which is why those channels were not shown in main UI. Signed-off-by: Danny Baumann --- 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 7b749f2764..39899a5d65 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 @@ -41,6 +41,7 @@ import org.openhab.binding.homematic.internal.model.HmDatapointConfig; import org.openhab.binding.homematic.internal.model.HmDatapointInfo; import org.openhab.binding.homematic.internal.model.HmDevice; import org.openhab.binding.homematic.internal.model.HmParamsetType; +import org.openhab.binding.homematic.internal.type.HomematicChannelTypeProvider; import org.openhab.binding.homematic.internal.type.HomematicTypeGeneratorImpl; import org.openhab.binding.homematic.internal.type.MetadataUtils; import org.openhab.binding.homematic.internal.type.UidUtils; @@ -57,6 +58,8 @@ import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.thing.binding.ThingHandler; import org.openhab.core.thing.binding.builder.ChannelBuilder; +import org.openhab.core.thing.type.ChannelType; +import org.openhab.core.thing.type.ChannelTypeUID; import org.openhab.core.types.Command; import org.openhab.core.types.RefreshType; import org.openhab.core.types.State; @@ -70,12 +73,14 @@ import org.slf4j.LoggerFactory; */ public class HomematicThingHandler extends BaseThingHandler { private final Logger logger = LoggerFactory.getLogger(HomematicThingHandler.class); + private final HomematicChannelTypeProvider channelTypeProvider; private Future initFuture; private final Object initLock = new Object(); private volatile boolean deviceDeletionPending = false; - public HomematicThingHandler(Thing thing) { + public HomematicThingHandler(Thing thing, HomematicChannelTypeProvider channelTypeProvider) { super(thing); + this.channelTypeProvider = channelTypeProvider; } @Override @@ -196,10 +201,17 @@ public class HomematicThingHandler extends BaseThingHandler { Map channelProps = new HashMap<>(); channelProps.put(propertyName, expectedFunction); + ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(dp); + ChannelType channelType = channelTypeProvider.getInternalChannelType(channelTypeUID); + if (channelType == null) { + channelType = HomematicTypeGeneratorImpl.createChannelType(dp, channelTypeUID); + channelTypeProvider.addChannelType(channelType); + } + Channel thingChannel = ChannelBuilder.create(channelUID, MetadataUtils.getItemType(dp)) .withProperties(channelProps).withLabel(MetadataUtils.getLabel(dp)) - .withDescription(MetadataUtils.getDatapointDescription(dp)) - .withType(UidUtils.generateChannelTypeUID(dp)).build(); + .withDescription(MetadataUtils.getDatapointDescription(dp)).withType(channelType.getUID()) + .build(); thingChannels.add(thingChannel); changed = true; } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandlerFactory.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandlerFactory.java index 517bc4fdeb..874ddc63f3 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandlerFactory.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandlerFactory.java @@ -17,6 +17,7 @@ import static org.openhab.binding.homematic.internal.HomematicBindingConstants.* import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; +import org.openhab.binding.homematic.internal.type.HomematicChannelTypeProvider; import org.openhab.binding.homematic.internal.type.HomematicTypeGenerator; import org.openhab.core.io.net.http.HttpClientFactory; import org.openhab.core.net.NetworkAddressService; @@ -40,13 +41,16 @@ import org.osgi.service.component.annotations.Reference; public class HomematicThingHandlerFactory extends BaseThingHandlerFactory { private final HomematicTypeGenerator typeGenerator; + private final HomematicChannelTypeProvider channelTypeProvider; private final NetworkAddressService networkAddressService; private final HttpClient httpClient; @Activate public HomematicThingHandlerFactory(@Reference HomematicTypeGenerator typeGenerator, + @Reference HomematicChannelTypeProvider channelTypeProvider, @Reference NetworkAddressService networkAddressService, @Reference HttpClientFactory httpClientFactory) { this.typeGenerator = typeGenerator; + this.channelTypeProvider = channelTypeProvider; this.networkAddressService = networkAddressService; this.httpClient = httpClientFactory.getCommonHttpClient(); } @@ -62,7 +66,7 @@ public class HomematicThingHandlerFactory extends BaseThingHandlerFactory { return new HomematicBridgeHandler((Bridge) thing, typeGenerator, networkAddressService.getPrimaryIpv4HostAddress(), httpClient); } else { - return new HomematicThingHandler(thing); + return new HomematicThingHandler(thing, channelTypeProvider); } } } 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 6577cb77f1..9c42597baa 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 @@ -250,7 +250,7 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator { /** * Creates the ChannelType for the given datapoint. */ - private ChannelType createChannelType(HmDatapoint dp, ChannelTypeUID channelTypeUID) { + public static ChannelType createChannelType(HmDatapoint dp, ChannelTypeUID channelTypeUID) { ChannelType channelType; if (dp.getName().equals(DATAPOINT_NAME_LOWBAT) || dp.getName().equals(DATAPOINT_NAME_LOWBAT_IP)) { channelType = DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_LOW_BATTERY;