lukics
(Slaviša Lukić)
June 2, 2019, 12:02pm
1
I am trying to run the dir watcher example, though I do not get the trigger when adding a file to /tmp
from core.triggers import DirectoryEventTrigger, ENTRY_CREATE
from core.rules import rule
from core.log import logging, LOG_PREFIX
@rule("Directory watcher example")
class DirectoryWatcherExampleRule(object):
def getEventTriggers(self):
return [ DirectoryEventTrigger("/tmp", event_kinds=[ENTRY_CREATE]) ]
def execute(self, module, inputs):
logging.getLogger(LOG_PREFIX + ".directory_watcher_example").info("Detected new file: [{}]".format(inputs['path']))
Is the example still valid?
lukics
(Slaviša Lukić)
June 2, 2019, 1:47pm
2
This is not workin either:
from core.triggers import CronTrigger, ENTRY_CREATE
from core.rules import rule
from core.log import logging, LOG_PREFIX
@rule("Cron event trigger")
class CronlEventRule(object):
def getEventTriggers(self):
logging.getLogger(LOG_PREFIX + ".cron_event_rule").info("init called")
return [ CronTrigger("0/1 * * * * ?", triggerName="Example_Cron_event_trigger") ]
def execute(self, module, inputs):
logging.getLogger(LOG_PREFIX + ".cron_event_rule").info("cron triggered")
What am I making wrong here’
5iver
(Scott Rushworth)
June 2, 2019, 3:14pm
3
Custom handlers (DirectoryTriigger, OSGIEventTrigger, StartupTrigger) will only work in S1566 and newer. However, I have only tested the StartupTrigger. For the cron rule, look at the hello_world.py example to find the issue.
lukics
(Slaviša Lukić)
June 2, 2019, 5:33pm
4
Just for info what is meant with s1566 (JSR223 release), I am running 2.4.0.
I found out what the problem with the other samples is:
I did not add .trigger at the end. e.g. :
return [ DirectoryEventTrigger("/tmp", event_kinds=[ENTRY_CREATE]).trigger ]
but when I add the .trigger I get:
2019-06-02 19:25:51.868 [.event.RuleStatusInfoEvent] - ca6c7837-6ce2-47e5-ae19-cc54086a33b6 updated: UNINITIALIZED (HANDLER_INITIALIZING_ERROR): Missing handler 'jsr223.DirectoryTrigger' for module 'DirectoryEventTrigger-784ea94f855b11e9a3d12d236f51b29d'
5iver
(Scott Rushworth)
June 2, 2019, 5:42pm
5
Snapshot build 1566. A PR was need to fix the custom handlers after some changes made in ESH a while ago, but this went in after 2.4 and 2.5M1. You will need to upgrade OH to use them.