mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[mqtt.homeassistant] avoid improperly delivered triggers (#17584)
if multiple DeviceTrigger components share a topic, and each has a payload value configured, only messages matching that payload should be delivered to the corresponding channel Signed-off-by: Cody Cutrer <cody@cutrer.us> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
6f283a47d4
commit
69c519e06d
@ -173,6 +173,13 @@ public class ChannelState implements MqttMessageSubscriber {
|
||||
|
||||
// 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;
|
||||
|
@ -237,6 +237,15 @@ public abstract class AbstractComponentTests extends AbstractHomeAssistantTests
|
||||
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.
|
||||
*
|
||||
|
@ -62,6 +62,9 @@ public class DeviceTriggerTests extends AbstractComponentTests {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user