diff --git a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/ChannelState.java b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/ChannelState.java index 681e5073e9af0..7304ae57c7c26 100644 --- a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/ChannelState.java +++ b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/ChannelState.java @@ -173,6 +173,13 @@ public void processMessage(String topic, byte[] payload) { // Is trigger?: Special handling if (config.trigger) { + try { + cachedValue.parseMessage(new StringType(strValue)); + } catch (IllegalArgumentException e) { + // invalid value for this trigger; ignore + receivedOrTimeout(); + return; + } channelStateUpdateListener.triggerChannel(channelUID, strValue); receivedOrTimeout(); return; diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponentTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponentTests.java index bbb278d530fbf..4b090b6385d9b 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponentTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/AbstractComponentTests.java @@ -237,6 +237,15 @@ protected void assertTriggered(AbstractComponent<@NonNull ? extends AbstractChan verify(thingHandler).triggerChannel(eq(component.getChannel(channelId).getChannel().getUID()), eq(trigger)); } + /** + * Assert a channel does not triggers= + */ + protected void assertNotTriggered(AbstractComponent<@NonNull ? extends AbstractChannelConfiguration> component, + String channelId, String trigger) { + verify(thingHandler, never()).triggerChannel(eq(component.getChannel(channelId).getChannel().getUID()), + eq(trigger)); + } + /** * Assert that given payload was published exact-once on given topic. * diff --git a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTriggerTests.java b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTriggerTests.java index ad5f338cc9da3..baa476704eb94 100644 --- a/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTriggerTests.java +++ b/bundles/org.openhab.binding.mqtt.homeassistant/src/test/java/org/openhab/binding/mqtt/homeassistant/internal/component/DeviceTriggerTests.java @@ -62,6 +62,9 @@ public void test() throws InterruptedException { spyOnChannelUpdates(component, "action"); publishMessage("zigbee2mqtt/Charge Now Button/action", "on"); assertTriggered(component, "action", "on"); + + publishMessage("zigbee2mqtt/Charge Now Button/action", "off"); + assertNotTriggered(component, "action", "off"); } @Override