forked from openhab-scripters/openhab-helper-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path000_LogAction.py
33 lines (25 loc) · 1.09 KB
/
000_LogAction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from org.slf4j import Logger, LoggerFactory
ScriptExtension.importPreset("RuleSupport")
class LoggerAction(ActionHandler):
def __init__(self, module):
self.module = module
def dispose(self):
pass
def execute(self, context):
config = self.module.configuration
logger = LoggerFactory.getLogger(config.get('logname'))
logger.info(str(config.get('message')))
return {"result": "success"}
def param(name, type, label, default=None, required=False):
return ConfigDescriptionParameterBuilder.create(name, type)\
.withLabel(label).withDefault(default).withRequired(required).build()
automationManager.addActionHandler("LogAction", lambda module: LoggerAction(module))
automationManager.addActionType(ActionType(
"LogAction",
[
param("logname", ConfigDescriptionParameter.Type.TEXT, "Logger Name", default="LogAction"),
param("message", ConfigDescriptionParameter.Type.TEXT, "Message", required=True)
],
"write a log record",
"Write a record to the log file.",
set(), Visibility.VISIBLE, [], []))