]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homematic] Fix UI enumeration of HM-MOD-EM-8 channels (#10907)
authormaniac103 <dannybaumann@web.de>
Sat, 17 Jul 2021 21:33:08 +0000 (23:33 +0200)
committerGitHub <noreply@github.com>
Sat, 17 Jul 2021 21:33:08 +0000 (23:33 +0200)
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 <dannybaumann@web.de>
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/handler/HomematicThingHandlerFactory.java
bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/HomematicTypeGeneratorImpl.java

index 7b749f27642f82e98b84ad3f1b9a3e3f3bb1e8b7..39899a5d652cd702d5ee657aee3c2ff17f3df062 100644 (file)
@@ -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<String, String> 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;
             }
index 517bc4fdeb18fafc9837c68d0d4f961747f76bf9..874ddc63f390dd2bedac0e9fbb29232f8a9ca337 100644 (file)
@@ -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);
         }
     }
 }
index 6577cb77f1e8d12deefb2967f0cddfac4963ccab..9c42597baa61326b2d948a810fe55761dc2e0db3 100644 (file)
@@ -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;