[mqtt.homeassistant] Mark disabled by default components as advanced channels (#14240)

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>
This commit is contained in:
Cody Cutrer 2023-01-27 16:37:15 -07:00 committed by GitHub
parent 83c20b0bd6
commit d97d212cd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View 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))

View File

@ -239,4 +239,8 @@ public abstract class AbstractComponent<C extends AbstractChannelConfiguration>
public TransformationServiceProvider getTransformationServiceProvider() {
return componentConfiguration.getTransformationServiceProvider();
}
public boolean isEnabledByDefault() {
return channelConfiguration.isEnabledByDefault();
}
}

View 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")

View 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;