mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-11 05:41:52 +01:00
[automation] Allow using * as wildcard in thing status triggers (#2832)
Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
parent
26596ecc25
commit
86960f243f
@ -17,6 +17,7 @@ import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@ -65,6 +66,7 @@ public class ThingStatusTriggerHandler extends BaseTriggerModuleHandler implemen
|
||||
private final BundleContext bundleContext;
|
||||
|
||||
private final ServiceRegistration<?> eventSubscriberRegistration;
|
||||
private final Pattern eventTopicFilter;
|
||||
|
||||
public ThingStatusTriggerHandler(Trigger module, BundleContext bundleContext) {
|
||||
super(module);
|
||||
@ -77,6 +79,9 @@ public class ThingStatusTriggerHandler extends BaseTriggerModuleHandler implemen
|
||||
this.types = Set.of(ThingStatusInfoChangedEvent.TYPE);
|
||||
}
|
||||
this.bundleContext = bundleContext;
|
||||
|
||||
this.eventTopicFilter = Pattern.compile("^openhab/things/" + thingUID.replace("*", ".*?") + "/.*$");
|
||||
|
||||
Dictionary<String, Object> properties = new Hashtable<>();
|
||||
properties.put("event.topics", "openhab/things/" + thingUID + "/*");
|
||||
eventSubscriberRegistration = this.bundleContext.registerService(EventSubscriber.class.getName(), this,
|
||||
@ -143,6 +148,6 @@ public class ThingStatusTriggerHandler extends BaseTriggerModuleHandler implemen
|
||||
@Override
|
||||
public boolean apply(Event event) {
|
||||
logger.trace("->FILTER: {}: {}", event.getTopic(), thingUID);
|
||||
return event.getTopic().contains("openhab/things/" + thingUID + "/");
|
||||
return eventTopicFilter.matcher(event.getTopic()).matches();
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
"type": "TEXT",
|
||||
"context": "thing",
|
||||
"label": "Thing",
|
||||
"description": "The UID of the thing.",
|
||||
"description": "The UID of the thing. You can use '*' as wildcard to match multiple things.",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user