]> git.basschouten.com Git - openhab-addons.git/commitdiff
[miio] Use generic channeltypes if none provided (#8999)
authorMarcel <marcelrv@users.noreply.github.com>
Fri, 13 Nov 2020 23:09:39 +0000 (00:09 +0100)
committerGitHub <noreply@github.com>
Fri, 13 Nov 2020 23:09:39 +0000 (15:09 -0800)
To prevent channels not showing up in OH3 main UI

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoBasicHandler.java
bundles/org.openhab.binding.miio/src/main/resources/OH-INF/thing/commonChannels.xml

index 92df54e41adf4cea0f3d92d885d262263573eea0..f8fadf3b56d50b30f70c8d667eeea5c2c2adafc6 100644 (file)
@@ -12,7 +12,7 @@
  */
 package org.openhab.binding.miio.internal.handler;
 
-import static org.openhab.binding.miio.internal.MiIoBindingConstants.CHANNEL_COMMAND;
+import static org.openhab.binding.miio.internal.MiIoBindingConstants.*;
 
 import java.awt.Color;
 import java.io.IOException;
@@ -452,6 +452,7 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
             thingBuilder.withoutChannel(new ChannelUID(getThing().getUID(), channel));
         }
         ChannelBuilder newChannel = ChannelBuilder.create(channelUID, datatype).withLabel(friendlyName);
+        boolean useGenericChannelType = false;
         if (!channelType.isBlank()) {
             ChannelTypeUID channelTypeUID = new ChannelTypeUID(channelType);
             if (channelTypeRegistry.getChannelType(channelTypeUID) != null) {
@@ -459,7 +460,13 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
             } else {
                 logger.debug("ChannelType '{}' is not available. Check the Json file for {}", channelTypeUID,
                         getThing().getUID());
+                useGenericChannelType = true;
             }
+        } else {
+            useGenericChannelType = true;
+        }
+        if (useGenericChannelType) {
+            newChannel = newChannel.withType(new ChannelTypeUID(BINDING_ID, datatype.toLowerCase()));
         }
         thingBuilder.withChannel(newChannel.build());
         return channelUID;
index 27cbfcbbb55cd58fdd5d95437d56eaf12f7404de..30ee2b821a1cb6266f075e905f88cbfa75ea1305 100644 (file)
                </channels>
        </channel-group-type>
 
+       <!-- Generic channels -->
+       <channel-type id="color">
+               <item-type>Color</item-type>
+               <label>Generic Color Channel</label>
+       </channel-type>
+       <channel-type id="contact">
+               <item-type>Contact</item-type>
+               <label>Generic Contact Channel</label>
+       </channel-type>
+       <channel-type id="datetime">
+               <item-type>DateTime</item-type>
+               <label>Generic DateTime Channel</label>
+       </channel-type>
+       <channel-type id="dimmer">
+               <item-type>Dimmer</item-type>
+               <label>Generic Dimmer Channel</label>
+       </channel-type>
+       <channel-type id="image">
+               <item-type>Image</item-type>
+               <label>Generic Image Channel</label>
+       </channel-type>
+       <channel-type id="location">
+               <item-type>Location</item-type>
+               <label>Generic Location Channel</label>
+       </channel-type>
+       <channel-type id="number">
+               <item-type>Number</item-type>
+               <label>Generic Number Channel</label>
+       </channel-type>
+       <channel-type id="player">
+               <item-type>Player</item-type>
+               <label>Generic Player Channel</label>
+       </channel-type>
+       <channel-type id="rollershutter">
+               <item-type>Rollershutter</item-type>
+               <label>Generic Rollershutter Channel</label>
+       </channel-type>
+       <channel-type id="string">
+               <item-type>String</item-type>
+               <label>Generic String Channel</label>
+       </channel-type>
+       <channel-type id="switch">
+               <item-type>Switch</item-type>
+               <label>Generic Switch Channel</label>
+       </channel-type>
+
        <!-- Network channels -->
        <channel-type id="ssid" advanced="true">
                <item-type>String</item-type>