use of org.openhab.core.model.rule.rules.SystemStartlevelTrigger in project openhab-core by openhab.
the class DSLRuleProvider method mapTrigger.
@Nullable
private Trigger mapTrigger(EventTrigger t) {
if (t instanceof SystemOnStartupTrigger) {
Configuration cfg = new Configuration();
cfg.put("startlevel", 20);
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.SystemStartlevelTrigger").withConfiguration(cfg).build();
} else if (t instanceof SystemStartlevelTrigger) {
SystemStartlevelTrigger slTrigger = (SystemStartlevelTrigger) t;
Configuration cfg = new Configuration();
cfg.put("startlevel", slTrigger.getLevel());
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.SystemStartlevelTrigger").withConfiguration(cfg).build();
} else if (t instanceof SystemOnShutdownTrigger) {
logger.warn("System shutdown rule triggers are no longer supported!");
return null;
} else if (t instanceof CommandEventTrigger) {
CommandEventTrigger ceTrigger = (CommandEventTrigger) t;
Configuration cfg = new Configuration();
cfg.put("itemName", ceTrigger.getItem());
if (ceTrigger.getCommand() != null) {
cfg.put("command", ceTrigger.getCommand().getValue());
}
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.ItemCommandTrigger").withConfiguration(cfg).build();
} else if (t instanceof GroupMemberCommandEventTrigger) {
GroupMemberCommandEventTrigger ceTrigger = (GroupMemberCommandEventTrigger) t;
Configuration cfg = new Configuration();
cfg.put("groupName", ceTrigger.getGroup());
if (ceTrigger.getCommand() != null) {
cfg.put("command", ceTrigger.getCommand().getValue());
}
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.GroupCommandTrigger").withConfiguration(cfg).build();
} else if (t instanceof UpdateEventTrigger) {
UpdateEventTrigger ueTrigger = (UpdateEventTrigger) t;
Configuration cfg = new Configuration();
cfg.put("itemName", ueTrigger.getItem());
if (ueTrigger.getState() != null) {
cfg.put("state", ueTrigger.getState().getValue());
}
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.ItemStateUpdateTrigger").withConfiguration(cfg).build();
} else if (t instanceof GroupMemberUpdateEventTrigger) {
GroupMemberUpdateEventTrigger ueTrigger = (GroupMemberUpdateEventTrigger) t;
Configuration cfg = new Configuration();
cfg.put("groupName", ueTrigger.getGroup());
if (ueTrigger.getState() != null) {
cfg.put("state", ueTrigger.getState().getValue());
}
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.GroupStateUpdateTrigger").withConfiguration(cfg).build();
} else if (t instanceof ChangedEventTrigger) {
ChangedEventTrigger ceTrigger = (ChangedEventTrigger) t;
Configuration cfg = new Configuration();
cfg.put("itemName", ceTrigger.getItem());
if (ceTrigger.getNewState() != null) {
cfg.put("state", ceTrigger.getNewState().getValue());
}
if (ceTrigger.getOldState() != null) {
cfg.put("previousState", ceTrigger.getOldState().getValue());
}
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.ItemStateChangeTrigger").withConfiguration(cfg).build();
} else if (t instanceof GroupMemberChangedEventTrigger) {
GroupMemberChangedEventTrigger ceTrigger = (GroupMemberChangedEventTrigger) t;
Configuration cfg = new Configuration();
cfg.put("groupName", ceTrigger.getGroup());
if (ceTrigger.getNewState() != null) {
cfg.put("state", ceTrigger.getNewState().getValue());
}
if (ceTrigger.getOldState() != null) {
cfg.put("previousState", ceTrigger.getOldState().getValue());
}
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.GroupStateChangeTrigger").withConfiguration(cfg).build();
} else if (t instanceof TimerTrigger) {
TimerTrigger tt = (TimerTrigger) t;
Configuration cfg = new Configuration();
String id;
if (tt.getCron() != null) {
id = tt.getCron();
cfg.put("cronExpression", tt.getCron());
} else {
id = tt.getTime();
if (id.equals("noon")) {
cfg.put("cronExpression", "0 0 12 * * ?");
} else if (id.equals("midnight")) {
cfg.put("cronExpression", "0 0 0 * * ?");
} else {
logger.warn("Unrecognized time expression '{}' in rule trigger", tt.getTime());
return null;
}
}
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("timer.GenericCronTrigger").withConfiguration(cfg).build();
} else if (t instanceof EventEmittedTrigger) {
EventEmittedTrigger eeTrigger = (EventEmittedTrigger) t;
Configuration cfg = new Configuration();
cfg.put("channelUID", eeTrigger.getChannel());
if (eeTrigger.getTrigger() != null) {
cfg.put("event", eeTrigger.getTrigger().getValue());
}
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.ChannelEventTrigger").withConfiguration(cfg).build();
} else if (t instanceof ThingStateUpdateEventTrigger) {
ThingStateUpdateEventTrigger tsuTrigger = (ThingStateUpdateEventTrigger) t;
Configuration cfg = new Configuration();
cfg.put("thingUID", tsuTrigger.getThing());
cfg.put("status", tsuTrigger.getState());
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.ThingStatusUpdateTrigger").withConfiguration(cfg).build();
} else if (t instanceof ThingStateChangedEventTrigger) {
ThingStateChangedEventTrigger tscTrigger = (ThingStateChangedEventTrigger) t;
Configuration cfg = new Configuration();
cfg.put("thingUID", tscTrigger.getThing());
cfg.put("status", tscTrigger.getNewState());
cfg.put("previousStatus", tscTrigger.getOldState());
return TriggerBuilder.create().withId(Integer.toString(triggerId++)).withTypeUID("core.ThingStatusChangeTrigger").withConfiguration(cfg).build();
} else {
logger.warn("Unknown trigger type '{}' - ignoring it.", t.getClass().getSimpleName());
return null;
}
}
Aggregations