]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mqtt.homeassistant] Mark disabled by default components as advanced channels (#14240)
authorCody Cutrer <cody@cutrer.us>
Fri, 27 Jan 2023 23:37:15 +0000 (16:37 -0700)
committerGitHub <noreply@github.com>
Fri, 27 Jan 2023 23:37:15 +0000 (00:37 +0100)
openHAB doesn't have the concept of "enabled by default", since _everything_
is technically "disabled" until you link it to an item. It seems devices
use disabled by default on less common entities, such as zigbee2mqtt
marking a binary_sensor as a "backup" method to an update entity for
when an update is available, or a sensor as a "backup" method to a
select entity. So in that case, just hiding these channels unless the user
clicks "Show Advanced" seems to map best.

Signed-off-by: Cody Cutrer <cody@cutrer.us>
bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/ComponentChannel.java
bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponent.java
bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/component/Vacuum.java
bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/internal/config/dto/AbstractChannelConfiguration.java

index f0481c1128997afa383e769e8c53ede176489054..b016a6960e0bdbb470c2ac7f29fdb0661260c47e 100644 (file)
@@ -232,6 +232,11 @@ public class ComponentChannel {
                             .withCommandTopic(commandTopic).makeTrigger(trigger).withFormatter(format).build(),
                     channelUID, valueState, channelStateUpdateListener, commandFilter);
 
+            // disabled by default components should always show up as advanced
+            if (!component.isEnabledByDefault()) {
+                isAdvanced = true;
+            }
+
             if (this.trigger) {
                 type = ChannelTypeBuilder.trigger(channelTypeUID, label)
                         .withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HA_CHANNEL))
index 5f9caea2a108f371e7779bc82ad76924920aacfd..d4ab2251cbc75021f258e05d307a4c22e6be7275 100644 (file)
@@ -239,4 +239,8 @@ public abstract class AbstractComponent<C extends AbstractChannelConfiguration>
     public TransformationServiceProvider getTransformationServiceProvider() {
         return componentConfiguration.getTransformationServiceProvider();
     }
+
+    public boolean isEnabledByDefault() {
+        return channelConfiguration.isEnabledByDefault();
+    }
 }
index e599b9fa31497e93086c9e0947b2074b9d90bfda..7fd9d6b901fb9cb19c6c850a0d78fa14fb4bf39d 100644 (file)
@@ -127,9 +127,6 @@ public class Vacuum extends AbstractComponent<Vacuum.ChannelConfiguration> {
         @SerializedName("docked_topic")
         protected @Nullable String dockedTopic;
 
-        @SerializedName("enabled_by_default")
-        protected @Nullable Boolean enabledByDefault = true;
-
         @SerializedName("error_template")
         protected @Nullable String errorTemplate;
         @SerializedName("error_topic")
index dda84ada74e1563b790fea21d502e5106e9d6161..ae64e5d2445da4d7cc7fdd34bc70776089965c33 100644 (file)
@@ -55,6 +55,9 @@ public abstract class AbstractChannelConfiguration {
     @SerializedName("availability_template")
     protected @Nullable String availabilityTemplate;
 
+    @SerializedName("enabled_by_default")
+    protected boolean enabledByDefault = true;
+
     /**
      * A list of MQTT topics subscribed to receive availability (online/offline) updates. Must not be used together with
      * availability_topic
@@ -168,6 +171,10 @@ public abstract class AbstractChannelConfiguration {
         return availabilityTemplate;
     }
 
+    public boolean isEnabledByDefault() {
+        return enabledByDefault;
+    }
+
     @Nullable
     public Device getDevice() {
         return device;