implement addTrigger

This commit is contained in:
Felix Roos
2023-02-14 21:27:07 +01:00
parent 23f186ba97
commit f3e0e5e980
+16
View File
@@ -820,6 +820,22 @@ export class Pattern {
);
}
addTrigger(onTrigger) {
return this.withHap((hap) =>
hap.setContext({
...hap.context,
onTrigger: (...args) => {
if (hap.context.onTrigger) {
hap.context.onTrigger(...args);
}
onTrigger(...args);
},
// this flag causes the default output to be ignored
dominantTrigger: true,
}),
);
}
log(func = (_, hap) => `[hap] ${hap.showWhole(true)}`, getData = (_, hap) => ({ hap })) {
return this.onTrigger((...args) => {
logger(func(...args), undefined, getData(...args));