Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mqtt.homeassistant] Avoid improperly delivered triggers #17584

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down