diff --git a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/OnOffValue.java b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/OnOffValue.java index e87f78a9291ae..5a5596af952f8 100644 --- a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/OnOffValue.java +++ b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/OnOffValue.java @@ -21,6 +21,8 @@ import org.eclipse.smarthome.core.library.types.OnOffType; import org.eclipse.smarthome.core.library.types.StringType; import org.eclipse.smarthome.core.types.Command; +import org.eclipse.smarthome.core.types.CommandDescriptionBuilder; +import org.eclipse.smarthome.core.types.CommandOption; /** * Implements an on/off boolean value. @@ -95,4 +97,12 @@ public String getMQTTpublishValue(@Nullable String pattern) { return String.format(formatPattern, state == OnOffType.ON ? onCommand : offCommand); } + + @Override + public CommandDescriptionBuilder createCommandDescription() { + CommandDescriptionBuilder builder = super.createCommandDescription(); + builder = builder.withCommandOption(new CommandOption(onCommand, onCommand)); + builder = builder.withCommandOption(new CommandOption(offCommand, offCommand)); + return builder; + } } diff --git a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/TextValue.java b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/TextValue.java index b6ef5db7cdc34..eaf33b821f5d5 100644 --- a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/TextValue.java +++ b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/TextValue.java @@ -23,6 +23,8 @@ import org.eclipse.smarthome.core.library.CoreItemFactory; import org.eclipse.smarthome.core.library.types.StringType; import org.eclipse.smarthome.core.types.Command; +import org.eclipse.smarthome.core.types.CommandDescriptionBuilder; +import org.eclipse.smarthome.core.types.CommandOption; import org.eclipse.smarthome.core.types.StateDescriptionFragmentBuilder; import org.eclipse.smarthome.core.types.StateOption; @@ -84,4 +86,16 @@ public StateDescriptionFragmentBuilder createStateDescription(boolean readOnly) } return builder; } + + @Override + public CommandDescriptionBuilder createCommandDescription() { + CommandDescriptionBuilder builder = super.createCommandDescription(); + final Set commands = this.states; + if (states != null) { + for (String command : commands) { + builder = builder.withCommandOption(new CommandOption(command, command)); + } + } + return builder; + } } diff --git a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/Value.java b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/Value.java index 40d9de3bd4792..91009c100c346 100644 --- a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/Value.java +++ b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/Value.java @@ -24,6 +24,7 @@ import org.eclipse.smarthome.core.library.types.PercentType; import org.eclipse.smarthome.core.library.types.RawType; import org.eclipse.smarthome.core.types.Command; +import org.eclipse.smarthome.core.types.CommandDescriptionBuilder; import org.eclipse.smarthome.core.types.State; import org.eclipse.smarthome.core.types.StateDescriptionFragmentBuilder; import org.eclipse.smarthome.core.types.UnDefType; @@ -169,4 +170,13 @@ public void update(byte data[]) throws IllegalArgumentException { public StateDescriptionFragmentBuilder createStateDescription(boolean readOnly) { return StateDescriptionFragmentBuilder.create().withReadOnly(readOnly).withPattern("%s"); } + + /** + * Return the command description builder for this value state. + * + * @return A command description builder + */ + public CommandDescriptionBuilder createCommandDescription() { + return CommandDescriptionBuilder.create(); + } } diff --git a/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/homie300/Property.java b/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/homie300/Property.java index 57bd027d12fd0..58bfed99ecd33 100644 --- a/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/homie300/Property.java +++ b/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/internal/homie300/Property.java @@ -29,6 +29,7 @@ import org.eclipse.smarthome.core.thing.ChannelUID; import org.eclipse.smarthome.core.thing.DefaultSystemChannelTypeProvider; import org.eclipse.smarthome.core.thing.binding.builder.ChannelBuilder; +import org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy; import org.eclipse.smarthome.core.thing.type.ChannelType; import org.eclipse.smarthome.core.thing.type.ChannelTypeBuilder; import org.eclipse.smarthome.core.thing.type.ChannelTypeUID; @@ -137,6 +138,7 @@ public void attributesReceived() { * @return Returns the ChannelType to be used to build the Channel. */ private ChannelType createChannelType(PropertyAttributes attributes, ChannelState channelState) { + // Retained property -> State channel if (attributes.retained) { return ChannelTypeBuilder.state(channelTypeUID, attributes.name, channelState.getItemType()) .withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HOMIE_CHANNEL)) @@ -144,6 +146,14 @@ private ChannelType createChannelType(PropertyAttributes attributes, ChannelStat .toStateDescription()) .build(); } else { + // Non-retained and settable property -> State channel + if (attributes.settable) { + return ChannelTypeBuilder.state(channelTypeUID, attributes.name, channelState.getItemType()) + .withConfigDescriptionURI(URI.create(MqttBindingConstants.CONFIG_HOMIE_CHANNEL)) + .withCommandDescription(channelState.getCache().createCommandDescription().build()) + .withAutoUpdatePolicy(AutoUpdatePolicy.VETO).build(); + } + // Non-retained and non settable property -> Trigger channel if (attributes.datatype.equals(DataTypeEnum.enum_)) { if (attributes.format.contains("PRESSED") && attributes.format.contains("RELEASED")) { return DefaultSystemChannelTypeProvider.SYSTEM_RAWBUTTON;