use of org.openhab.core.automation.handler.ModuleHandler in project openhab-core by openhab.
the class ScriptedPrivateModuleHandlerFactory method internalCreate.
@Override
@Nullable
protected ModuleHandler internalCreate(Module module, String ruleUID) {
ModuleHandler moduleHandler = null;
ScriptedHandler scriptedHandler = null;
try {
scriptedHandler = privateTypes.get(module.getConfiguration().get(PRIV_ID));
} catch (Exception e) {
logger.warn("ScriptedHandler {} for ruleUID {} not found", module.getConfiguration().get(PRIV_ID), ruleUID);
}
if (scriptedHandler != null) {
moduleHandler = getModuleHandler(module, scriptedHandler);
}
return moduleHandler;
}
use of org.openhab.core.automation.handler.ModuleHandler in project openhab-core by openhab.
the class RuleEngineImpl method setModuleHandlers.
/**
* This method links modules to corresponding module handlers.
*
* @param rUID id of rule containing these modules
* @param modules list of modules
* @return null when all modules are connected or list of RuleErrors for missing handlers.
*/
@Nullable
private <T extends WrappedModule<?, ?>> String setModuleHandlers(String rUID, List<T> modules) {
StringBuilder sb = null;
for (T mm : modules) {
final Module m = mm.unwrap();
try {
ModuleHandler moduleHandler = getModuleHandler(m, rUID);
if (moduleHandler != null) {
if (mm instanceof WrappedAction) {
((WrappedAction) mm).setModuleHandler((ActionHandler) moduleHandler);
} else if (mm instanceof WrappedCondition) {
((WrappedCondition) mm).setModuleHandler((ConditionHandler) moduleHandler);
} else if (mm instanceof WrappedTrigger) {
((WrappedTrigger) mm).setModuleHandler((TriggerHandler) moduleHandler);
}
} else {
if (sb == null) {
sb = new StringBuilder();
}
String message = "Missing handler '" + m.getTypeUID() + "' for module '" + m.getId() + "'";
sb.append(message).append("\n");
logger.trace(message);
}
} catch (Throwable t) {
if (sb == null) {
sb = new StringBuilder();
}
String message = "Getting handler '" + m.getTypeUID() + "' for module '" + m.getId() + "' failed: " + t.getMessage();
sb.append(message).append("\n");
logger.trace(message);
}
}
return sb != null ? sb.toString() : null;
}
use of org.openhab.core.automation.handler.ModuleHandler in project openhab-core by openhab.
the class EphemerisModuleHandlerFactoryTest method testFactoryCreatesModuleHandlerForWeekdayCondition.
@Test
public void testFactoryCreatesModuleHandlerForWeekdayCondition() {
when(moduleMock.getTypeUID()).thenReturn(EphemerisConditionHandler.WEEKDAY_MODULE_TYPE_ID);
when(moduleMock.getConfiguration()).thenReturn(new Configuration());
ModuleHandler handler = factory.internalCreate(moduleMock, "My first rule");
assertThat(handler, is(notNullValue()));
assertThat(handler, instanceOf(EphemerisConditionHandler.class));
when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of("offset", 5)));
handler = factory.internalCreate(moduleMock, "My second rule");
assertThat(handler, is(notNullValue()));
assertThat(handler, instanceOf(EphemerisConditionHandler.class));
}
use of org.openhab.core.automation.handler.ModuleHandler in project openhab-core by openhab.
the class EphemerisModuleHandlerFactoryTest method testFactoryCreatesModuleHandlerForDaysetCondition.
@Test
public void testFactoryCreatesModuleHandlerForDaysetCondition() {
when(moduleMock.getTypeUID()).thenReturn(EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID);
when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of("dayset", "school")));
ModuleHandler handler = factory.internalCreate(moduleMock, "My second rule");
assertThat(handler, is(notNullValue()));
assertThat(handler, instanceOf(EphemerisConditionHandler.class));
}
use of org.openhab.core.automation.handler.ModuleHandler in project openhab-core by openhab.
the class CompositeModuleHandlerFactory method internalCreate.
@Override
@Nullable
public ModuleHandler internalCreate(Module module, String ruleUID) {
ModuleHandler handler = null;
String moduleType = module.getTypeUID();
ModuleType mt = mtRegistry.get(moduleType);
if (mt instanceof CompositeTriggerType) {
List<Trigger> childModules = ((CompositeTriggerType) mt).getChildren();
LinkedHashMap<Trigger, @Nullable TriggerHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeTriggerHandler((Trigger) module, (CompositeTriggerType) mt, mapModuleToHandler, ruleUID);
}
} else if (mt instanceof CompositeConditionType) {
List<Condition> childModules = ((CompositeConditionType) mt).getChildren();
LinkedHashMap<Condition, @Nullable ConditionHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeConditionHandler((Condition) module, (CompositeConditionType) mt, mapModuleToHandler, ruleUID);
}
} else if (mt instanceof CompositeActionType) {
List<Action> childModules = ((CompositeActionType) mt).getChildren();
LinkedHashMap<Action, @Nullable ActionHandler> mapModuleToHandler = getChildHandlers(module.getId(), module.getConfiguration(), childModules, ruleUID);
if (mapModuleToHandler != null) {
handler = new CompositeActionHandler((Action) module, (CompositeActionType) mt, mapModuleToHandler, ruleUID);
}
}
if (handler != null) {
logger.debug("Set module handler: {} -> {} of rule {}.", module.getId(), handler.getClass().getSimpleName() + "(" + moduleType + ")", ruleUID);
} else {
logger.debug("Not found module handler {} for moduleType {} of rule {}.", module.getId(), moduleType, ruleUID);
}
return handler;
}
Aggregations