mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
Add more null annotations to automation bundles (#2763)
* Add more null annotations to automation bundles. This adds null annotations to many classes in the automation bundles and a few dimension classes. * Further cleanup AutomationCommandExport * Remove null from RuleStatusInfo JavaDocs. This should be clear from how the class is now annotated. * Validate deserialized RuleStatusInfo * Allow TriggerHandlerCallback to be triggered without providing a context Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
parent
44f7b00c45
commit
9ff7ad43b9
@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.core.automation.module.script.rulesupport.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.Module;
|
||||
@ -36,10 +38,11 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class AbstractScriptedModuleHandlerFactory extends BaseModuleHandlerFactory {
|
||||
Logger logger = LoggerFactory.getLogger(AbstractScriptedModuleHandlerFactory.class);
|
||||
|
||||
protected ModuleHandler getModuleHandler(Module module, ScriptedHandler scriptedHandler) {
|
||||
protected @Nullable ModuleHandler getModuleHandler(Module module, @Nullable ScriptedHandler scriptedHandler) {
|
||||
ModuleHandler moduleHandler = null;
|
||||
|
||||
if (scriptedHandler != null) {
|
||||
|
@ -15,6 +15,8 @@ package org.openhab.core.automation.module.script.rulesupport.internal;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Module;
|
||||
import org.openhab.core.automation.handler.ModuleHandler;
|
||||
import org.openhab.core.automation.handler.ModuleHandlerFactory;
|
||||
@ -31,6 +33,7 @@ import org.osgi.service.component.annotations.Component;
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@Component(immediate = true, service = { ScriptedCustomModuleHandlerFactory.class, ModuleHandlerFactory.class })
|
||||
public class ScriptedCustomModuleHandlerFactory extends AbstractScriptedModuleHandlerFactory {
|
||||
private final HashMap<String, ScriptedHandler> typesHandlers = new HashMap<>();
|
||||
@ -41,7 +44,7 @@ public class ScriptedCustomModuleHandlerFactory extends AbstractScriptedModuleHa
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModuleHandler internalCreate(Module module, String ruleUID) {
|
||||
protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
|
||||
ScriptedHandler scriptedHandler = typesHandlers.get(module.getTypeUID());
|
||||
|
||||
return getModuleHandler(module, scriptedHandler);
|
||||
|
@ -16,6 +16,8 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Module;
|
||||
import org.openhab.core.automation.handler.ModuleHandler;
|
||||
import org.openhab.core.automation.handler.ModuleHandlerFactory;
|
||||
@ -33,6 +35,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@Component(immediate = true, service = { ScriptedPrivateModuleHandlerFactory.class, ModuleHandlerFactory.class })
|
||||
public class ScriptedPrivateModuleHandlerFactory extends AbstractScriptedModuleHandlerFactory {
|
||||
private static final String PRIV_ID = "privId";
|
||||
@ -50,7 +53,7 @@ public class ScriptedPrivateModuleHandlerFactory extends AbstractScriptedModuleH
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModuleHandler internalCreate(Module module, String ruleUID) {
|
||||
protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
|
||||
ModuleHandler moduleHandler = null;
|
||||
|
||||
ScriptedHandler scriptedHandler = null;
|
||||
|
@ -17,6 +17,8 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.handler.BaseActionModuleHandler;
|
||||
import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleActionHandler;
|
||||
@ -26,6 +28,7 @@ import org.openhab.core.automation.module.script.rulesupport.shared.simple.Simpl
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class SimpleActionHandlerDelegate extends BaseActionModuleHandler {
|
||||
|
||||
private org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleActionHandler actionHandler;
|
||||
@ -41,10 +44,10 @@ public class SimpleActionHandlerDelegate extends BaseActionModuleHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> execute(Map<String, Object> inputs) {
|
||||
public @Nullable Map<String, Object> execute(Map<String, @Nullable Object> inputs) {
|
||||
Set<String> keys = new HashSet<>(inputs.keySet());
|
||||
|
||||
Map<String, Object> extendedInputs = new HashMap<>(inputs);
|
||||
Map<String, @Nullable Object> extendedInputs = new HashMap<>(inputs);
|
||||
for (String key : keys) {
|
||||
Object value = extendedInputs.get(key);
|
||||
int dotIndex = key.indexOf('.');
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.core.automation.module.script.rulesupport.internal.delegates
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.handler.BaseConditionModuleHandler;
|
||||
import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleConditionHandler;
|
||||
@ -23,6 +24,7 @@ import org.openhab.core.automation.module.script.rulesupport.shared.simple.Simpl
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class SimpleConditionHandlerDelegate extends BaseConditionModuleHandler {
|
||||
|
||||
private SimpleConditionHandler conditionHandler;
|
||||
|
@ -15,6 +15,8 @@ package org.openhab.core.automation.module.script.rulesupport.internal.delegates
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.RuleStatus;
|
||||
import org.openhab.core.automation.RuleStatusInfo;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
@ -26,6 +28,7 @@ import org.openhab.core.automation.module.script.rulesupport.shared.simple.Simpl
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class SimpleTriggerHandlerCallbackDelegate implements SimpleTriggerHandlerCallback {
|
||||
private final Trigger trigger;
|
||||
private final TriggerHandlerCallback callback;
|
||||
@ -51,7 +54,7 @@ public class SimpleTriggerHandlerCallbackDelegate implements SimpleTriggerHandle
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isEnabled(String ruleUID) {
|
||||
public @Nullable Boolean isEnabled(String ruleUID) {
|
||||
return callback.isEnabled(ruleUID);
|
||||
}
|
||||
|
||||
@ -61,12 +64,12 @@ public class SimpleTriggerHandlerCallbackDelegate implements SimpleTriggerHandle
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleStatusInfo getStatusInfo(String ruleUID) {
|
||||
public @Nullable RuleStatusInfo getStatusInfo(String ruleUID) {
|
||||
return callback.getStatusInfo(ruleUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleStatus getStatus(String ruleUID) {
|
||||
public @Nullable RuleStatus getStatus(String ruleUID) {
|
||||
return callback.getStatus(ruleUID);
|
||||
}
|
||||
|
||||
@ -76,7 +79,7 @@ public class SimpleTriggerHandlerCallbackDelegate implements SimpleTriggerHandle
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runNow(String uid, boolean considerConditions, Map<String, Object> context) {
|
||||
public void runNow(String uid, boolean considerConditions, @Nullable Map<String, Object> context) {
|
||||
callback.runNow(uid, considerConditions, context);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.core.automation.module.script.rulesupport.internal.delegates;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.ModuleHandlerCallback;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
import org.openhab.core.automation.handler.BaseTriggerModuleHandler;
|
||||
@ -22,6 +23,7 @@ import org.openhab.core.automation.handler.TriggerHandlerCallback;
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class SimpleTriggerHandlerDelegate extends BaseTriggerModuleHandler {
|
||||
|
||||
private final org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleTriggerHandler triggerHandler;
|
||||
|
@ -18,6 +18,8 @@ import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.WatchEvent;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.service.AbstractWatchService;
|
||||
|
||||
/**
|
||||
@ -25,6 +27,7 @@ import org.openhab.core.service.AbstractWatchService;
|
||||
*
|
||||
* @author Jonathan Gilbert - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class ScriptLibraryWatcher extends AbstractWatchService {
|
||||
|
||||
public ScriptLibraryWatcher(final String libraryPath) {
|
||||
@ -37,7 +40,7 @@ public abstract class ScriptLibraryWatcher extends AbstractWatchService {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WatchEvent.Kind<?>[] getWatchEventKinds(Path path) {
|
||||
protected WatchEvent.Kind<?> @Nullable [] getWatchEventKinds(Path path) {
|
||||
return new WatchEvent.Kind<?>[] { ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY };
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,8 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Bidirectional bag of unique elements. A map allowing multiple, unique values to be stored against a single key.
|
||||
* Provides optimized lookup of values for a key, as well as keys referencing a value.
|
||||
@ -26,6 +28,7 @@ import java.util.Set;
|
||||
* @param <K> Type of Key
|
||||
* @param <V> Type of Value
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BidiSetBag<K, V> {
|
||||
private Map<K, Set<V>> keyToValues = new HashMap<>();
|
||||
private Map<V, Set<K>> valueToKeys = new HashMap<>();
|
||||
|
@ -12,11 +12,14 @@
|
||||
*/
|
||||
package org.openhab.core.automation.module.script.rulesupport.shared;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Empty interface to identify scripted handlers
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface ScriptedHandler {
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.core.automation.module.script.rulesupport.shared.factories;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.handler.ActionHandler;
|
||||
import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHandler;
|
||||
@ -20,6 +22,7 @@ import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHand
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface ScriptedActionHandlerFactory extends ScriptedHandler {
|
||||
public ActionHandler get(Action action);
|
||||
public @Nullable ActionHandler get(Action action);
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.core.automation.module.script.rulesupport.shared.factories;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.handler.ConditionHandler;
|
||||
import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHandler;
|
||||
@ -20,6 +22,7 @@ import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHand
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface ScriptedConditionHandlerFactory extends ScriptedHandler {
|
||||
public ConditionHandler get(Condition module);
|
||||
public @Nullable ConditionHandler get(Condition module);
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.core.automation.module.script.rulesupport.shared.factories;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
import org.openhab.core.automation.handler.TriggerHandler;
|
||||
import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHandler;
|
||||
@ -20,6 +22,7 @@ import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHand
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface ScriptedTriggerHandlerFactory extends ScriptedHandler {
|
||||
public TriggerHandler get(Trigger module);
|
||||
public @Nullable TriggerHandler get(Trigger module);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.core.automation.module.script.rulesupport.shared.simple;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHandler;
|
||||
|
||||
@ -21,6 +22,7 @@ import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHand
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class SimpleActionHandler implements ScriptedHandler {
|
||||
public void init(Action module) {
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.core.automation.module.script.rulesupport.shared.simple;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHandler;
|
||||
|
||||
@ -21,6 +22,7 @@ import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHand
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class SimpleConditionHandler implements ScriptedHandler {
|
||||
public void init(Condition condition) {
|
||||
}
|
||||
|
@ -14,12 +14,14 @@ package org.openhab.core.automation.module.script.rulesupport.shared.simple;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.Action;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface SimpleRuleActionHandler {
|
||||
Object execute(Action module, Map<String, ?> inputs);
|
||||
}
|
||||
|
@ -14,12 +14,14 @@ package org.openhab.core.automation.module.script.rulesupport.shared.simple;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.Action;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class SimpleRuleActionHandlerDelegate extends SimpleActionHandler {
|
||||
|
||||
private SimpleRuleActionHandler handler;
|
||||
|
@ -14,6 +14,8 @@ package org.openhab.core.automation.module.script.rulesupport.shared.simple;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHandler;
|
||||
|
||||
@ -21,8 +23,9 @@ import org.openhab.core.automation.module.script.rulesupport.shared.ScriptedHand
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class SimpleTriggerHandler implements ScriptedHandler {
|
||||
private SimpleTriggerHandlerCallback ruleCallback;
|
||||
private @Nullable SimpleTriggerHandlerCallback ruleCallback;
|
||||
|
||||
public void init(Trigger module) {
|
||||
}
|
||||
@ -32,6 +35,9 @@ public abstract class SimpleTriggerHandler implements ScriptedHandler {
|
||||
}
|
||||
|
||||
protected void trigger(Map<String, ?> context) {
|
||||
this.ruleCallback.triggered(context);
|
||||
SimpleTriggerHandlerCallback callback = this.ruleCallback;
|
||||
if (callback != null) {
|
||||
callback.triggered(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,14 @@ package org.openhab.core.automation.module.script.rulesupport.shared.simple;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.handler.TriggerHandlerCallback;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface SimpleTriggerHandlerCallback extends TriggerHandlerCallback {
|
||||
public void triggered(Map<String, ?> context);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.items.Item;
|
||||
import org.openhab.core.items.ItemNotFoundException;
|
||||
@ -28,6 +29,7 @@ import org.openhab.core.types.State;
|
||||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ItemRegistryDelegate implements Map<String, State> {
|
||||
|
||||
private final ItemRegistry itemRegistry;
|
||||
@ -47,10 +49,11 @@ public class ItemRegistryDelegate implements Map<String, State> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
public boolean containsKey(@Nullable Object key) {
|
||||
if (key instanceof String) {
|
||||
try {
|
||||
return itemRegistry.getItem((String) key) != null;
|
||||
itemRegistry.getItem((String) key);
|
||||
return true;
|
||||
} catch (ItemNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
@ -60,12 +63,12 @@ public class ItemRegistryDelegate implements Map<String, State> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
public boolean containsValue(@Nullable Object value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public State get(@Nullable Object key) {
|
||||
public @Nullable State get(@Nullable Object key) {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
@ -77,12 +80,12 @@ public class ItemRegistryDelegate implements Map<String, State> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public State put(String key, State value) {
|
||||
public @Nullable State put(String key, State value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public State remove(Object key) {
|
||||
public @Nullable State remove(@Nullable Object key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.core.automation.rest.internal.dto;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.ManagedRuleProvider;
|
||||
import org.openhab.core.automation.Rule;
|
||||
import org.openhab.core.automation.RuleManager;
|
||||
@ -23,6 +24,7 @@ import org.openhab.core.automation.dto.RuleDTOMapper;
|
||||
* @author Markus Rathgeb - Initial contribution
|
||||
* @author Kai Kreuzer - added editable field
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class EnrichedRuleDTOMapper extends RuleDTOMapper {
|
||||
|
||||
public static EnrichedRuleDTO map(final Rule rule, final RuleManager ruleEngine,
|
||||
|
@ -19,11 +19,15 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This class add support for prefixes for {@link Rule} UIDs and provide default predicates for prefixes and tags.
|
||||
*
|
||||
* @author Victor Toni - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class RulePredicates {
|
||||
|
||||
/**
|
||||
@ -48,7 +52,7 @@ public class RulePredicates {
|
||||
*
|
||||
* @return prefix of this {@link Rule}, or {@code null} if no prefix or an empty prefix is found.
|
||||
*/
|
||||
public static String getPrefix(Rule rule) {
|
||||
public static @Nullable String getPrefix(@Nullable Rule rule) {
|
||||
if (null != rule) {
|
||||
final String uid = rule.getUID();
|
||||
final int index = uid.indexOf(PREFIX_SEPARATOR);
|
||||
@ -66,7 +70,7 @@ public class RulePredicates {
|
||||
* @param prefix to search for.
|
||||
* @return created {@link Predicate}.
|
||||
*/
|
||||
public static Predicate<Rule> hasPrefix(final String prefix) {
|
||||
public static Predicate<Rule> hasPrefix(final @Nullable String prefix) {
|
||||
if (null == prefix) {
|
||||
return r -> null == getPrefix(r);
|
||||
} else {
|
||||
@ -121,7 +125,7 @@ public class RulePredicates {
|
||||
* @param tags to search for.
|
||||
* @return created {@link Predicate}.
|
||||
*/
|
||||
public static Predicate<Rule> hasAllTags(final Collection<String> tags) {
|
||||
public static Predicate<Rule> hasAllTags(final @Nullable Collection<String> tags) {
|
||||
if (tags == null || tags.isEmpty()) {
|
||||
return (Predicate<Rule>) r -> true;
|
||||
} else {
|
||||
@ -140,7 +144,7 @@ public class RulePredicates {
|
||||
* @param tags to search for.
|
||||
* @return created {@link Predicate}.
|
||||
*/
|
||||
public static Predicate<Rule> hasAllTags(final String... tags) {
|
||||
public static Predicate<Rule> hasAllTags(final String @Nullable... tags) {
|
||||
return hasAllTags(tags == null ? null : Arrays.asList(tags));
|
||||
}
|
||||
|
||||
@ -151,7 +155,7 @@ public class RulePredicates {
|
||||
* @param tags to search for.
|
||||
* @return created {@link Predicate}.
|
||||
*/
|
||||
public static Predicate<Rule> hasAnyOfTags(final Collection<String> tags) {
|
||||
public static Predicate<Rule> hasAnyOfTags(final @Nullable Collection<String> tags) {
|
||||
if (null == tags || tags.isEmpty()) {
|
||||
// everything without a tag is matching
|
||||
return hasNoTags();
|
||||
@ -171,7 +175,7 @@ public class RulePredicates {
|
||||
* @param tags to search for.
|
||||
* @return created {@link Predicate}.
|
||||
*/
|
||||
public static Predicate<Rule> hasAnyOfTags(final String... tags) {
|
||||
public static Predicate<Rule> hasAnyOfTags(final String @Nullable... tags) {
|
||||
if (null == tags || 0 == tags.length) {
|
||||
// everything without a tag is matching
|
||||
return hasNoTags();
|
||||
|
@ -12,6 +12,9 @@
|
||||
*/
|
||||
package org.openhab.core.automation;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This class is used to present status of a rule. The status consists of three parts:
|
||||
* The main status, a status detail and a string description.
|
||||
@ -19,11 +22,12 @@ package org.openhab.core.automation;
|
||||
* @author Yordan Mihaylov - Initial contribution
|
||||
* @author Kai Kreuzer - Refactored to match ThingStatusInfo implementation
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class RuleStatusInfo {
|
||||
|
||||
private RuleStatus status;
|
||||
private RuleStatusDetail statusDetail;
|
||||
private String description;
|
||||
private @NonNullByDefault({}) RuleStatus status;
|
||||
private @NonNullByDefault({}) RuleStatusDetail statusDetail;
|
||||
private @Nullable String description;
|
||||
|
||||
/**
|
||||
* Default constructor for deserialization e.g. by Gson.
|
||||
@ -34,40 +38,30 @@ public class RuleStatusInfo {
|
||||
/**
|
||||
* Constructs a status info.
|
||||
*
|
||||
* @param status the status (must not be null)
|
||||
* @throws IllegalArgumentException if status is null
|
||||
* @param status the status
|
||||
*/
|
||||
public RuleStatusInfo(RuleStatus status) throws IllegalArgumentException {
|
||||
public RuleStatusInfo(RuleStatus status) {
|
||||
this(status, RuleStatusDetail.NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a status info.
|
||||
*
|
||||
* @param status the status (must not be null)
|
||||
* @param statusDetail the detail of the status (must not be null)
|
||||
* @throws IllegalArgumentException if status or status detail is null
|
||||
* @param status the status
|
||||
* @param statusDetail the detail of the status
|
||||
*/
|
||||
public RuleStatusInfo(RuleStatus status, RuleStatusDetail statusDetail) throws IllegalArgumentException {
|
||||
public RuleStatusInfo(RuleStatus status, RuleStatusDetail statusDetail) {
|
||||
this(status, statusDetail, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a status info.
|
||||
*
|
||||
* @param status the status (must not be null)
|
||||
* @param statusDetail the detail of the status (must not be null)
|
||||
* @param status the status
|
||||
* @param statusDetail the detail of the status
|
||||
* @param description the description of the status
|
||||
* @throws IllegalArgumentException if status or status detail is null
|
||||
*/
|
||||
public RuleStatusInfo(RuleStatus status, RuleStatusDetail statusDetail, String description)
|
||||
throws IllegalArgumentException {
|
||||
if (status == null) {
|
||||
throw new IllegalArgumentException("Thing status must not be null");
|
||||
}
|
||||
if (statusDetail == null) {
|
||||
throw new IllegalArgumentException("Thing status detail must not be null");
|
||||
}
|
||||
public RuleStatusInfo(RuleStatus status, RuleStatusDetail statusDetail, @Nullable String description) {
|
||||
this.status = status;
|
||||
this.statusDetail = statusDetail;
|
||||
this.description = description;
|
||||
@ -76,7 +70,7 @@ public class RuleStatusInfo {
|
||||
/**
|
||||
* Gets the status itself.
|
||||
*
|
||||
* @return the status (not null)
|
||||
* @return the status
|
||||
*/
|
||||
public RuleStatus getStatus() {
|
||||
return status;
|
||||
@ -85,7 +79,7 @@ public class RuleStatusInfo {
|
||||
/**
|
||||
* Gets the detail of the status.
|
||||
*
|
||||
* @return the status detail (not null)
|
||||
* @return the status detail
|
||||
*/
|
||||
public RuleStatusDetail getStatusDetail() {
|
||||
return statusDetail;
|
||||
@ -96,7 +90,7 @@ public class RuleStatusInfo {
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
public @Nullable String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@ -118,7 +112,7 @@ public class RuleStatusInfo {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2022 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.core.automation;
|
||||
|
||||
/**
|
||||
* This interface is used by {@link RuleRegistry} implementation to be notified of changes related to statuses of rules.
|
||||
*
|
||||
* @author Yordan Mihaylov - Initial contribution
|
||||
*/
|
||||
public interface StatusInfoCallback {
|
||||
|
||||
/**
|
||||
* The method is called when the rule has update of its status.
|
||||
*
|
||||
* @param ruleUID UID of the {@link Rule}
|
||||
* @param statusInfo new status info releated to the {@link Rule}
|
||||
*/
|
||||
void statusInfoChanged(String ruleUID, RuleStatusInfo statusInfo);
|
||||
}
|
@ -16,6 +16,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.util.ModuleBuilder;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
@ -26,6 +28,7 @@ import org.openhab.core.config.core.Configuration;
|
||||
* @author Markus Rathgeb - Initial contribution
|
||||
* @author Kai Kreuzer - Changed to using ModuleBuilder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ActionDTOMapper extends ModuleDTOMapper {
|
||||
|
||||
public static ActionDTO map(final Action action) {
|
||||
@ -41,9 +44,9 @@ public class ActionDTOMapper extends ModuleDTOMapper {
|
||||
.withLabel(actionDto.label).withDescription(actionDto.description).build();
|
||||
}
|
||||
|
||||
public static List<ActionDTO> map(final Collection<? extends Action> actions) {
|
||||
public static List<ActionDTO> map(final @Nullable Collection<? extends Action> actions) {
|
||||
if (actions == null) {
|
||||
return null;
|
||||
return List.of();
|
||||
}
|
||||
final List<ActionDTO> dtos = new ArrayList<>(actions.size());
|
||||
for (final Action action : actions) {
|
||||
@ -52,9 +55,9 @@ public class ActionDTOMapper extends ModuleDTOMapper {
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public static List<Action> mapDto(final Collection<ActionDTO> dtos) {
|
||||
public static List<Action> mapDto(final @Nullable Collection<ActionDTO> dtos) {
|
||||
if (dtos == null) {
|
||||
return null;
|
||||
return List.of();
|
||||
}
|
||||
final List<Action> actions = new ArrayList<>(dtos.size());
|
||||
for (final ActionDTO dto : dtos) {
|
||||
|
@ -16,6 +16,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.type.ActionType;
|
||||
import org.openhab.core.automation.type.CompositeActionType;
|
||||
import org.openhab.core.config.core.dto.ConfigDescriptionDTOMapper;
|
||||
@ -26,6 +28,7 @@ import org.openhab.core.config.core.dto.ConfigDescriptionDTOMapper;
|
||||
* @author Markus Rathgeb - Initial contribution
|
||||
* @author Ana Dimova - extends Action Module type DTOs with composites
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ActionTypeDTOMapper extends ModuleTypeDTOMapper {
|
||||
|
||||
public static ActionTypeDTO map(final ActionType actionType) {
|
||||
@ -51,9 +54,9 @@ public class ActionTypeDTOMapper extends ModuleTypeDTOMapper {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ActionTypeDTO> map(final Collection<ActionType> types) {
|
||||
public static List<ActionTypeDTO> map(final @Nullable Collection<ActionType> types) {
|
||||
if (types == null) {
|
||||
return null;
|
||||
return List.of();
|
||||
}
|
||||
final List<ActionTypeDTO> dtos = new ArrayList<>(types.size());
|
||||
for (final ActionType type : types) {
|
||||
|
@ -15,6 +15,8 @@ package org.openhab.core.automation.dto;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.util.ModuleBuilder;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
@ -25,6 +27,7 @@ import org.openhab.core.config.core.Configuration;
|
||||
* @author Markus Rathgeb - Initial contribution
|
||||
* @author Kai Kreuzer - Changed to using ModuleBuilder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ConditionDTOMapper extends ModuleDTOMapper {
|
||||
|
||||
public static ConditionDTO map(final Condition condition) {
|
||||
@ -40,9 +43,9 @@ public class ConditionDTOMapper extends ModuleDTOMapper {
|
||||
.withLabel(conditionDto.label).withDescription(conditionDto.description).build();
|
||||
}
|
||||
|
||||
public static List<ConditionDTO> map(final List<? extends Condition> conditions) {
|
||||
public static List<ConditionDTO> map(final @Nullable List<? extends Condition> conditions) {
|
||||
if (conditions == null) {
|
||||
return null;
|
||||
return List.of();
|
||||
}
|
||||
final List<ConditionDTO> dtos = new ArrayList<>(conditions.size());
|
||||
for (final Condition action : conditions) {
|
||||
@ -51,9 +54,9 @@ public class ConditionDTOMapper extends ModuleDTOMapper {
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public static List<Condition> mapDto(final List<ConditionDTO> dtos) {
|
||||
public static List<Condition> mapDto(final @Nullable List<ConditionDTO> dtos) {
|
||||
if (dtos == null) {
|
||||
return null;
|
||||
return List.of();
|
||||
}
|
||||
final List<Condition> conditions = new ArrayList<>(dtos.size());
|
||||
for (final ConditionDTO dto : dtos) {
|
||||
|
@ -16,6 +16,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.type.CompositeConditionType;
|
||||
import org.openhab.core.automation.type.ConditionType;
|
||||
import org.openhab.core.config.core.dto.ConfigDescriptionDTOMapper;
|
||||
@ -26,6 +28,7 @@ import org.openhab.core.config.core.dto.ConfigDescriptionDTOMapper;
|
||||
* @author Markus Rathgeb - Initial contribution
|
||||
* @author Ana Dimova - extends Condition Module type DTOs with composites
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ConditionTypeDTOMapper extends ModuleTypeDTOMapper {
|
||||
|
||||
public static ConditionTypeDTO map(final ConditionType conditionType) {
|
||||
@ -52,9 +55,9 @@ public class ConditionTypeDTOMapper extends ModuleTypeDTOMapper {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ConditionTypeDTO> map(final Collection<ConditionType> types) {
|
||||
public static List<ConditionTypeDTO> map(final @Nullable Collection<ConditionType> types) {
|
||||
if (types == null) {
|
||||
return null;
|
||||
return List.of();
|
||||
}
|
||||
final List<ConditionTypeDTO> dtos = new ArrayList<>(types.size());
|
||||
for (final ConditionType type : types) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.core.automation.dto;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.Module;
|
||||
|
||||
/**
|
||||
@ -19,6 +20,7 @@ import org.openhab.core.automation.Module;
|
||||
*
|
||||
* @author Markus Rathgeb - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ModuleDTOMapper {
|
||||
|
||||
protected static void fillProperties(final Module from, final ModuleDTO to) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.core.automation.dto;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.type.ModuleType;
|
||||
import org.openhab.core.config.core.dto.ConfigDescriptionDTOMapper;
|
||||
|
||||
@ -20,6 +21,7 @@ import org.openhab.core.config.core.dto.ConfigDescriptionDTOMapper;
|
||||
*
|
||||
* @author Markus Rathgeb - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ModuleTypeDTOMapper {
|
||||
|
||||
protected static void fillProperties(final ModuleType from, final ModuleTypeDTO to) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
package org.openhab.core.automation.dto;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.Rule;
|
||||
import org.openhab.core.automation.util.RuleBuilder;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
@ -23,6 +24,7 @@ import org.openhab.core.config.core.dto.ConfigDescriptionDTOMapper;
|
||||
* @author Markus Rathgeb - Initial contribution
|
||||
* @author Kai Kreuzer - Changed to using RuleBuilder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class RuleDTOMapper {
|
||||
|
||||
public static RuleDTO map(final Rule rule) {
|
||||
|
@ -16,6 +16,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
import org.openhab.core.automation.util.ModuleBuilder;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
@ -26,6 +28,7 @@ import org.openhab.core.config.core.Configuration;
|
||||
* @author Markus Rathgeb - Initial contribution
|
||||
* @author Kai Kreuzer - Changed to using ModuleBuilder
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class TriggerDTOMapper extends ModuleDTOMapper {
|
||||
|
||||
public static TriggerDTO map(final Trigger trigger) {
|
||||
@ -40,9 +43,9 @@ public class TriggerDTOMapper extends ModuleDTOMapper {
|
||||
.withDescription(triggerDto.description).build();
|
||||
}
|
||||
|
||||
public static List<TriggerDTO> map(final Collection<? extends Trigger> triggers) {
|
||||
public static List<TriggerDTO> map(final @Nullable Collection<? extends Trigger> triggers) {
|
||||
if (triggers == null) {
|
||||
return null;
|
||||
return List.of();
|
||||
}
|
||||
final List<TriggerDTO> dtos = new ArrayList<>(triggers.size());
|
||||
for (final Trigger trigger : triggers) {
|
||||
@ -51,9 +54,9 @@ public class TriggerDTOMapper extends ModuleDTOMapper {
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public static List<Trigger> mapDto(final Collection<TriggerDTO> dtos) {
|
||||
public static List<Trigger> mapDto(final @Nullable Collection<TriggerDTO> dtos) {
|
||||
if (dtos == null) {
|
||||
return null;
|
||||
return List.of();
|
||||
}
|
||||
final List<Trigger> triggers = new ArrayList<>(dtos.size());
|
||||
for (final TriggerDTO dto : dtos) {
|
||||
|
@ -16,6 +16,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.type.CompositeTriggerType;
|
||||
import org.openhab.core.automation.type.TriggerType;
|
||||
import org.openhab.core.config.core.dto.ConfigDescriptionDTOMapper;
|
||||
@ -26,6 +28,7 @@ import org.openhab.core.config.core.dto.ConfigDescriptionDTOMapper;
|
||||
* @author Markus Rathgeb - Initial contribution
|
||||
* @author Ana Dimova - extends Trigger Module type DTOs with composites
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class TriggerTypeDTOMapper extends ModuleTypeDTOMapper {
|
||||
|
||||
public static TriggerTypeDTO map(final TriggerType triggerType) {
|
||||
@ -51,9 +54,9 @@ public class TriggerTypeDTOMapper extends ModuleTypeDTOMapper {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<TriggerTypeDTO> map(final Collection<TriggerType> types) {
|
||||
public static List<TriggerTypeDTO> map(final @Nullable Collection<TriggerType> types) {
|
||||
if (types == null) {
|
||||
return null;
|
||||
return List.of();
|
||||
}
|
||||
final List<TriggerTypeDTO> dtos = new ArrayList<>(types.size());
|
||||
for (final TriggerType type : types) {
|
||||
|
@ -74,7 +74,7 @@ public abstract class BaseModuleHandlerFactory implements ModuleHandlerFactory {
|
||||
*
|
||||
* @param module the {@link Module} for which a handler should be created.
|
||||
* @param ruleUID the identifier of the {@link Rule} that the given module belongs to.
|
||||
* @return a {@link ModuleHandler} instance or {@code null} if thins module type is not supported.
|
||||
* @return a {@link ModuleHandler} instance or {@code null} if this module type is not supported.
|
||||
*/
|
||||
protected abstract @Nullable ModuleHandler internalCreate(Module module, String ruleUID);
|
||||
|
||||
|
@ -16,7 +16,6 @@ import java.util.Map;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.ModuleHandlerCallback;
|
||||
import org.openhab.core.automation.Rule;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
@ -37,7 +36,19 @@ public interface TriggerHandlerCallback extends ModuleHandlerCallback {
|
||||
|
||||
/**
|
||||
* This method is used by the {@link TriggerHandler} to notify the RuleManager when
|
||||
* the liked {@link Trigger} instance was fired.
|
||||
* the linked {@link Trigger} instance was fired.
|
||||
*
|
||||
* @param trigger instance of trigger which was fired. When one TriggerHandler
|
||||
* serve more then one {@link Trigger} instances, this parameter
|
||||
* defines which trigger was fired.
|
||||
*/
|
||||
default void triggered(Trigger trigger) {
|
||||
triggered(trigger, Map.of());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used by the {@link TriggerHandler} to notify the RuleManager when
|
||||
* the linked {@link Trigger} instance was fired.
|
||||
*
|
||||
* @param trigger instance of trigger which was fired. When one TriggerHandler
|
||||
* serve more then one {@link Trigger} instances, this parameter
|
||||
@ -49,10 +60,10 @@ public interface TriggerHandlerCallback extends ModuleHandlerCallback {
|
||||
* <li><code>value</code> - represents output value of the {@link Trigger}'s {@link Output}
|
||||
* </ul>
|
||||
*/
|
||||
public void triggered(Trigger trigger, @Nullable Map<String, ?> context);
|
||||
void triggered(Trigger trigger, Map<String, ?> context);
|
||||
|
||||
/**
|
||||
* @return the scheduler of this rule
|
||||
*/
|
||||
public ScheduledExecutorService getScheduler();
|
||||
ScheduledExecutorService getScheduler();
|
||||
}
|
||||
|
@ -662,7 +662,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
|
||||
* @param msg provides the {@link RuleStatusInfo} description, corresponding to the new <b>uninitialized</b>
|
||||
* status, should be {@code null} if the status will be skipped.
|
||||
*/
|
||||
private void unregister(@Nullable WrappedRule r, @Nullable RuleStatusDetail detail, @Nullable String msg) {
|
||||
private void unregister(@Nullable WrappedRule r, RuleStatusDetail detail, @Nullable String msg) {
|
||||
if (r != null) {
|
||||
unregister(r);
|
||||
setStatus(r.getUID(), new RuleStatusInfo(RuleStatus.UNINITIALIZED, detail, msg));
|
||||
|
@ -91,8 +91,12 @@ public class RuleEventFactory extends AbstractEventFactory {
|
||||
return new RuleUpdatedEvent(topic, payload, source, ruleDTO[0], ruleDTO[1]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("null")
|
||||
private Event createRuleStatusInfoEvent(String topic, String payload, @Nullable String source) {
|
||||
RuleStatusInfo statusInfo = deserializePayload(payload, RuleStatusInfo.class);
|
||||
if (statusInfo.getStatus() == null || statusInfo.getStatusDetail() == null) {
|
||||
throw new IllegalArgumentException("Creation of RuleStatusInfo failed: invalid payload: " + payload);
|
||||
}
|
||||
return new RuleStatusInfoEvent(topic, payload, source, statusInfo, getRuleId(topic));
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class TriggerHandlerCallbackImpl implements TriggerHandlerCallback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggered(Trigger trigger, @Nullable Map<String, ?> context) {
|
||||
public void triggered(Trigger trigger, Map<String, ?> context) {
|
||||
synchronized (this) {
|
||||
future = executor.submit(new TriggerData(trigger, context));
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.core.automation.internal.commands;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.RuleStatus;
|
||||
|
||||
/**
|
||||
@ -19,6 +21,7 @@ import org.openhab.core.automation.RuleStatus;
|
||||
*
|
||||
* @author Ana Dimova - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class AutomationCommandEnableRule extends AutomationCommand {
|
||||
|
||||
/**
|
||||
@ -34,7 +37,7 @@ public class AutomationCommandEnableRule extends AutomationCommand {
|
||||
/**
|
||||
* This field keeps the specified rule UID.
|
||||
*/
|
||||
private String uid;
|
||||
private @Nullable String uid;
|
||||
|
||||
public AutomationCommandEnableRule(String command, String[] parameterValues, int providerType,
|
||||
AutomationCommandsPluggable autoCommands) {
|
||||
@ -43,9 +46,11 @@ public class AutomationCommandEnableRule extends AutomationCommand {
|
||||
|
||||
@Override
|
||||
public String execute() {
|
||||
if (parsingResult != SUCCESS) {
|
||||
String uid = this.uid;
|
||||
if (!SUCCESS.equals(parsingResult) || uid == null) {
|
||||
return parsingResult;
|
||||
}
|
||||
|
||||
if (hasEnable) {
|
||||
autoCommands.setEnabled(uid, enable);
|
||||
return SUCCESS;
|
||||
|
@ -13,11 +13,12 @@
|
||||
package org.openhab.core.automation.internal.commands;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.parser.Parser;
|
||||
|
||||
/**
|
||||
@ -30,6 +31,7 @@ import org.openhab.core.automation.parser.Parser;
|
||||
*
|
||||
* @author Ana Dimova - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class AutomationCommandExport extends AutomationCommand {
|
||||
|
||||
/**
|
||||
@ -47,7 +49,7 @@ public class AutomationCommandExport extends AutomationCommand {
|
||||
/**
|
||||
* This field keeps the path of the output file where the automation objects to be exported.
|
||||
*/
|
||||
private File file;
|
||||
private @Nullable File file;
|
||||
|
||||
/**
|
||||
* This field stores the value of <b>locale</b> parameter of the command.
|
||||
@ -75,46 +77,31 @@ public class AutomationCommandExport extends AutomationCommand {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String execute() {
|
||||
if (parsingResult != SUCCESS) {
|
||||
File file = this.file;
|
||||
if (!SUCCESS.equals(parsingResult) || file == null) {
|
||||
return parsingResult;
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
Set set = new HashSet();
|
||||
switch (providerType) {
|
||||
case AutomationCommands.MODULE_TYPE_PROVIDER:
|
||||
@SuppressWarnings("rawtypes")
|
||||
Collection collection = autoCommands.getTriggers(locale);
|
||||
if (collection != null) {
|
||||
set.addAll(collection);
|
||||
}
|
||||
collection = autoCommands.getConditions(locale);
|
||||
if (collection != null) {
|
||||
set.addAll(collection);
|
||||
}
|
||||
collection = autoCommands.getActions(locale);
|
||||
if (collection != null) {
|
||||
set.addAll(collection);
|
||||
}
|
||||
set.addAll(autoCommands.getTriggers(locale));
|
||||
set.addAll(autoCommands.getConditions(locale));
|
||||
set.addAll(autoCommands.getActions(locale));
|
||||
try {
|
||||
return autoCommands.exportModuleTypes(parserType, set, file);
|
||||
} catch (Exception e) {
|
||||
return getStackTrace(e);
|
||||
}
|
||||
case AutomationCommands.TEMPLATE_PROVIDER:
|
||||
collection = autoCommands.getTemplates(locale);
|
||||
if (collection != null) {
|
||||
set.addAll(collection);
|
||||
}
|
||||
set.addAll(autoCommands.getTemplates(locale));
|
||||
try {
|
||||
return autoCommands.exportTemplates(parserType, set, file);
|
||||
} catch (Exception e) {
|
||||
return getStackTrace(e);
|
||||
}
|
||||
case AutomationCommands.RULE_PROVIDER:
|
||||
collection = autoCommands.getRules();
|
||||
if (collection != null) {
|
||||
set.addAll(collection);
|
||||
}
|
||||
set.addAll(autoCommands.getRules());
|
||||
try {
|
||||
return autoCommands.exportRules(parserType, set, file);
|
||||
} catch (Exception e) {
|
||||
@ -132,7 +119,7 @@ public class AutomationCommandExport extends AutomationCommand {
|
||||
* @return a {@link File} object created from the string that is passed as a parameter of the command or <b>null</b>
|
||||
* if the parent directory could not be found or created or the string could not be parsed.
|
||||
*/
|
||||
private File initFile(String parameterValue) {
|
||||
private @Nullable File initFile(String parameterValue) {
|
||||
File f = new File(parameterValue);
|
||||
File parent = f.getParentFile();
|
||||
return (parent == null || (!parent.isDirectory() && !parent.mkdirs())) ? null : f;
|
||||
@ -174,7 +161,8 @@ public class AutomationCommandExport extends AutomationCommand {
|
||||
} else if (parameterValues[i].charAt(0) == '-') {
|
||||
return String.format("Unsupported option: %s", parameterValues[i]);
|
||||
} else if (getFile) {
|
||||
file = initFile(parameterValues[i]);
|
||||
File file = initFile(parameterValues[i]);
|
||||
this.file = file;
|
||||
if (file != null) {
|
||||
getFile = false;
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.parser.Parser;
|
||||
|
||||
/**
|
||||
@ -28,6 +30,7 @@ import org.openhab.core.automation.parser.Parser;
|
||||
*
|
||||
* @author Ana Dimova - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class AutomationCommandImport extends AutomationCommand {
|
||||
|
||||
/**
|
||||
@ -45,7 +48,7 @@ public class AutomationCommandImport extends AutomationCommand {
|
||||
/**
|
||||
* This field keeps URL of the source of automation objects that has to be imported.
|
||||
*/
|
||||
private URL url;
|
||||
private @Nullable URL url;
|
||||
|
||||
/**
|
||||
* @see AutomationCommand#AutomationCommand(String, String[], int, AutomationCommandsPluggable)
|
||||
@ -65,7 +68,8 @@ public class AutomationCommandImport extends AutomationCommand {
|
||||
*/
|
||||
@Override
|
||||
public String execute() {
|
||||
if (parsingResult != SUCCESS) {
|
||||
URL url = this.url;
|
||||
if (!SUCCESS.equals(parsingResult) || url == null) {
|
||||
return parsingResult;
|
||||
}
|
||||
try {
|
||||
@ -95,7 +99,7 @@ public class AutomationCommandImport extends AutomationCommand {
|
||||
* @return an {@link URL} object created from the string that is passed as parameter of the command or <b>null</b>
|
||||
* if either no legal protocol could be found in the specified string or the string could not be parsed.
|
||||
*/
|
||||
private URL initURL(String parameterValue) {
|
||||
private @Nullable URL initURL(String parameterValue) {
|
||||
try {
|
||||
return new URL(parameterValue);
|
||||
} catch (MalformedURLException mue) {
|
||||
|
@ -16,6 +16,8 @@ import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Rule;
|
||||
|
||||
/**
|
||||
@ -31,17 +33,18 @@ import org.openhab.core.automation.Rule;
|
||||
* @author Kai Kreuzer - fixed feedback when deleting non-existent rule
|
||||
* @author Marin Mitev - removed prefixes in the output
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class AutomationCommandRemove extends AutomationCommand {
|
||||
|
||||
/**
|
||||
* This field keeps the UID of the {@link Rule} if command is {@link AutomationCommands#REMOVE_RULE}
|
||||
*/
|
||||
private String id;
|
||||
private @Nullable String id;
|
||||
|
||||
/**
|
||||
* This field keeps URL of the source of automation objects that has to be removed.
|
||||
*/
|
||||
private URL url;
|
||||
private @Nullable URL url;
|
||||
|
||||
/**
|
||||
* @see AutomationCommand#AutomationCommand(String, String[], int, AutomationCommandsPluggable)
|
||||
@ -62,7 +65,9 @@ public class AutomationCommandRemove extends AutomationCommand {
|
||||
*/
|
||||
@Override
|
||||
public String execute() {
|
||||
if (parsingResult != SUCCESS) {
|
||||
String id = this.id;
|
||||
URL url = this.url;
|
||||
if (!SUCCESS.equals(parsingResult) || id == null || url == null) {
|
||||
return parsingResult;
|
||||
}
|
||||
switch (providerType) {
|
||||
@ -89,7 +94,7 @@ public class AutomationCommandRemove extends AutomationCommand {
|
||||
* @return an {@link URL} object created from the string that is passed as parameter of the command or <b>null</b>
|
||||
* if either no legal protocol could be found in the specified string or the string could not be parsed.
|
||||
*/
|
||||
private URL initURL(String parameterValue) {
|
||||
private @Nullable URL initURL(String parameterValue) {
|
||||
try {
|
||||
return new URL(parameterValue);
|
||||
} catch (MalformedURLException mue) {
|
||||
|
@ -18,11 +18,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* This class contains methods for facilitating sorting and filtering lists stored in {@link Hashtable}s.
|
||||
*
|
||||
* @author Ana Dimova - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,8 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.Module;
|
||||
@ -48,10 +50,11 @@ import org.openhab.core.automation.util.ReferenceResolver;
|
||||
* @param <H> type of module handler. It can be {@link TriggerHandler}, {@link ConditionHandler} or
|
||||
* {@link ActionHandler}
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public abstract class AbstractCompositeModuleHandler<M extends Module, MT extends ModuleType, H extends ModuleHandler>
|
||||
implements ModuleHandler {
|
||||
|
||||
protected LinkedHashMap<M, H> moduleHandlerMap;
|
||||
protected LinkedHashMap<M, @Nullable H> moduleHandlerMap;
|
||||
protected M module;
|
||||
protected MT moduleType;
|
||||
|
||||
@ -64,7 +67,7 @@ public abstract class AbstractCompositeModuleHandler<M extends Module, MT extend
|
||||
* @param mapModuleToHandler map containing pairs of child modules instances (defined by module type) and their
|
||||
* handlers
|
||||
*/
|
||||
public AbstractCompositeModuleHandler(M module, MT moduleType, LinkedHashMap<M, H> mapModuleToHandler) {
|
||||
public AbstractCompositeModuleHandler(M module, MT moduleType, LinkedHashMap<M, @Nullable H> mapModuleToHandler) {
|
||||
this.module = module;
|
||||
this.moduleType = moduleType;
|
||||
this.moduleHandlerMap = mapModuleToHandler;
|
||||
@ -102,17 +105,20 @@ public abstract class AbstractCompositeModuleHandler<M extends Module, MT extend
|
||||
childHandler.dispose();
|
||||
}
|
||||
}
|
||||
moduleHandlerMap = null;
|
||||
moduleHandlerMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCallback(ModuleHandlerCallback callback) {
|
||||
List<M> children = getChildren();
|
||||
for (M child : children) {
|
||||
@Nullable
|
||||
H handler = moduleHandlerMap.get(child);
|
||||
if (handler != null) {
|
||||
handler.setCallback(callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract List<M> getChildren();
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.handler.ActionHandler;
|
||||
import org.openhab.core.automation.type.CompositeActionType;
|
||||
@ -34,6 +36,7 @@ import org.openhab.core.automation.util.ReferenceResolver;
|
||||
*
|
||||
* @author Yordan Mihaylov - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class CompositeActionHandler extends AbstractCompositeModuleHandler<Action, CompositeActionType, ActionHandler>
|
||||
implements ActionHandler {
|
||||
|
||||
@ -50,7 +53,7 @@ public class CompositeActionHandler extends AbstractCompositeModuleHandler<Actio
|
||||
* @param ruleUID UID of rule where the parent action is part of.
|
||||
*/
|
||||
public CompositeActionHandler(Action action, CompositeActionType mt,
|
||||
LinkedHashMap<Action, ActionHandler> mapModuleToHandler, String ruleUID) {
|
||||
LinkedHashMap<Action, @Nullable ActionHandler> mapModuleToHandler, String ruleUID) {
|
||||
super(action, mt, mapModuleToHandler);
|
||||
compositeOutputs = getCompositeOutputMap(moduleType.getOutputs());
|
||||
}
|
||||
@ -61,14 +64,14 @@ public class CompositeActionHandler extends AbstractCompositeModuleHandler<Actio
|
||||
* @see org.openhab.core.automation.handler.ActionHandler#execute(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> execute(Map<String, Object> context) {
|
||||
public @Nullable Map<String, Object> execute(Map<String, Object> context) {
|
||||
final Map<String, Object> result = new HashMap<>();
|
||||
final List<Action> children = getChildren();
|
||||
final Map<String, Object> compositeContext = getCompositeContext(context);
|
||||
for (Action child : children) {
|
||||
ActionHandler childHandler = moduleHandlerMap.get(child);
|
||||
Map<String, Object> childContext = Collections.unmodifiableMap(getChildContext(child, compositeContext));
|
||||
Map<String, Object> childResults = childHandler.execute(childContext);
|
||||
Map<String, Object> childResults = childHandler == null ? null : childHandler.execute(childContext);
|
||||
if (childResults != null) {
|
||||
for (Entry<String, Object> childResult : childResults.entrySet()) {
|
||||
String childOuputName = child.getId() + "." + childResult.getKey();
|
||||
@ -91,7 +94,7 @@ public class CompositeActionHandler extends AbstractCompositeModuleHandler<Actio
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a map of links between child outputs and parent outputs. These links are base on the refecences defined in
|
||||
* Create a map of links between child outputs and parent outputs. These links are base on the references defined in
|
||||
* the outputs of parent action.
|
||||
*
|
||||
* @param outputs outputs of the parent action. The action of {@link CompositeActionType}
|
||||
@ -99,7 +102,6 @@ public class CompositeActionHandler extends AbstractCompositeModuleHandler<Actio
|
||||
*/
|
||||
protected Map<String, Output> getCompositeOutputMap(List<Output> outputs) {
|
||||
Map<String, Output> result = new HashMap<>(11);
|
||||
if (outputs != null) {
|
||||
for (Output output : outputs) {
|
||||
String refs = output.getReference();
|
||||
if (refs != null) {
|
||||
@ -118,7 +120,6 @@ public class CompositeActionHandler extends AbstractCompositeModuleHandler<Actio
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.handler.ConditionHandler;
|
||||
import org.openhab.core.automation.type.CompositeConditionType;
|
||||
@ -28,12 +30,13 @@ import org.openhab.core.automation.type.CompositeConditionType;
|
||||
*
|
||||
* @author Yordan Mihaylov - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class CompositeConditionHandler
|
||||
extends AbstractCompositeModuleHandler<Condition, CompositeConditionType, ConditionHandler>
|
||||
implements ConditionHandler {
|
||||
|
||||
public CompositeConditionHandler(Condition condition, CompositeConditionType mt,
|
||||
LinkedHashMap<Condition, ConditionHandler> mapModuleToHandler, String ruleUID) {
|
||||
LinkedHashMap<Condition, @Nullable ConditionHandler> mapModuleToHandler, String ruleUID) {
|
||||
super(condition, mt, mapModuleToHandler);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.Module;
|
||||
@ -53,6 +55,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Yordan Mihaylov - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class CompositeModuleHandlerFactory extends BaseModuleHandlerFactory implements ModuleHandlerFactory {
|
||||
|
||||
private final ModuleTypeRegistry mtRegistry;
|
||||
@ -116,13 +119,13 @@ public class CompositeModuleHandlerFactory extends BaseModuleHandlerFactory impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleHandler internalCreate(Module module, String ruleUID) {
|
||||
public @Nullable 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, TriggerHandler> mapModuleToHandler = getChildHandlers(module.getId(),
|
||||
LinkedHashMap<Trigger, @Nullable TriggerHandler> mapModuleToHandler = getChildHandlers(module.getId(),
|
||||
module.getConfiguration(), childModules, ruleUID);
|
||||
if (mapModuleToHandler != null) {
|
||||
handler = new CompositeTriggerHandler((Trigger) module, (CompositeTriggerType) mt, mapModuleToHandler,
|
||||
@ -130,7 +133,7 @@ public class CompositeModuleHandlerFactory extends BaseModuleHandlerFactory impl
|
||||
}
|
||||
} else if (mt instanceof CompositeConditionType) {
|
||||
List<Condition> childModules = ((CompositeConditionType) mt).getChildren();
|
||||
LinkedHashMap<Condition, ConditionHandler> mapModuleToHandler = getChildHandlers(module.getId(),
|
||||
LinkedHashMap<Condition, @Nullable ConditionHandler> mapModuleToHandler = getChildHandlers(module.getId(),
|
||||
module.getConfiguration(), childModules, ruleUID);
|
||||
if (mapModuleToHandler != null) {
|
||||
handler = new CompositeConditionHandler((Condition) module, (CompositeConditionType) mt,
|
||||
@ -138,7 +141,7 @@ public class CompositeModuleHandlerFactory extends BaseModuleHandlerFactory impl
|
||||
}
|
||||
} else if (mt instanceof CompositeActionType) {
|
||||
List<Action> childModules = ((CompositeActionType) mt).getChildren();
|
||||
LinkedHashMap<Action, ActionHandler> mapModuleToHandler = getChildHandlers(module.getId(),
|
||||
LinkedHashMap<Action, @Nullable ActionHandler> mapModuleToHandler = getChildHandlers(module.getId(),
|
||||
module.getConfiguration(), childModules, ruleUID);
|
||||
if (mapModuleToHandler != null) {
|
||||
handler = new CompositeActionHandler((Action) module, (CompositeActionType) mt, mapModuleToHandler,
|
||||
@ -170,8 +173,8 @@ public class CompositeModuleHandlerFactory extends BaseModuleHandlerFactory impl
|
||||
* handler.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Module, MT extends ModuleHandler> LinkedHashMap<T, MT> getChildHandlers(String compositeModuleId,
|
||||
Configuration compositeConfig, List<T> childModules, String childModulePrefix) {
|
||||
private <T extends Module, @Nullable MT extends ModuleHandler> @Nullable LinkedHashMap<T, MT> getChildHandlers(
|
||||
String compositeModuleId, Configuration compositeConfig, List<T> childModules, String childModulePrefix) {
|
||||
LinkedHashMap<T, MT> mapModuleToHandler = new LinkedHashMap<>();
|
||||
for (T child : childModules) {
|
||||
String ruleId = getRuleId(childModulePrefix);
|
||||
|
@ -19,6 +19,7 @@ import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.ModuleHandlerCallback;
|
||||
import org.openhab.core.automation.RuleStatus;
|
||||
@ -38,11 +39,12 @@ import org.openhab.core.automation.util.ReferenceResolver;
|
||||
*
|
||||
* @author Yordan Mihaylov - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class CompositeTriggerHandler
|
||||
extends AbstractCompositeModuleHandler<Trigger, CompositeTriggerType, TriggerHandler>
|
||||
implements TriggerHandler, TriggerHandlerCallback {
|
||||
|
||||
private TriggerHandlerCallback callback;
|
||||
private @NonNullByDefault({}) TriggerHandlerCallback callback;
|
||||
|
||||
/**
|
||||
* Constructor of this system handler.
|
||||
@ -53,7 +55,7 @@ public class CompositeTriggerHandler
|
||||
* @param ruleUID UID of rule where the parent trigger is part of
|
||||
*/
|
||||
public CompositeTriggerHandler(Trigger trigger, CompositeTriggerType mt,
|
||||
LinkedHashMap<Trigger, TriggerHandler> mapModuleToHandler, String ruleUID) {
|
||||
LinkedHashMap<Trigger, @Nullable TriggerHandler> mapModuleToHandler, String ruleUID) {
|
||||
super(trigger, mt, mapModuleToHandler);
|
||||
}
|
||||
|
||||
@ -125,10 +127,12 @@ public class CompositeTriggerHandler
|
||||
List<Trigger> children = getChildren();
|
||||
for (Trigger child : children) {
|
||||
TriggerHandler handler = moduleHandlerMap.get(child);
|
||||
if (handler != null) {
|
||||
handler.setCallback(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
@ -142,7 +146,7 @@ public class CompositeTriggerHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isEnabled(String ruleUID) {
|
||||
public @Nullable Boolean isEnabled(String ruleUID) {
|
||||
return callback.isEnabled(ruleUID);
|
||||
}
|
||||
|
||||
@ -152,12 +156,12 @@ public class CompositeTriggerHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleStatusInfo getStatusInfo(String ruleUID) {
|
||||
public @Nullable RuleStatusInfo getStatusInfo(String ruleUID) {
|
||||
return callback.getStatusInfo(ruleUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuleStatus getStatus(String ruleUID) {
|
||||
public @Nullable RuleStatus getStatus(String ruleUID) {
|
||||
return callback.getStatus(ruleUID);
|
||||
}
|
||||
|
||||
@ -167,7 +171,7 @@ public class CompositeTriggerHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runNow(String uid, boolean considerConditions, Map<String, Object> context) {
|
||||
public void runNow(String uid, boolean considerConditions, @Nullable Map<String, Object> context) {
|
||||
callback.runNow(uid, considerConditions, context);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ package org.openhab.core.automation.internal.module.factory;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.Module;
|
||||
@ -55,6 +57,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Kai Kreuzer - refactored and simplified customized module handling
|
||||
*/
|
||||
@Component
|
||||
@NonNullByDefault
|
||||
public class CoreModuleHandlerFactory extends BaseModuleHandlerFactory implements ModuleHandlerFactory {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(CoreModuleHandlerFactory.class);
|
||||
@ -76,8 +79,11 @@ public class CoreModuleHandlerFactory extends BaseModuleHandlerFactory implement
|
||||
private BundleContext bundleContext;
|
||||
|
||||
@Activate
|
||||
protected void activate(BundleContext bundleContext) {
|
||||
public CoreModuleHandlerFactory(BundleContext bundleContext, final @Reference EventPublisher eventPublisher,
|
||||
final @Reference ItemRegistry itemRegistry) {
|
||||
this.bundleContext = bundleContext;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.itemRegistry = itemRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -91,78 +97,8 @@ public class CoreModuleHandlerFactory extends BaseModuleHandlerFactory implement
|
||||
return TYPES;
|
||||
}
|
||||
|
||||
/**
|
||||
* the itemRegistry was added (called by serviceTracker)
|
||||
*
|
||||
* @param itemRegistry
|
||||
*/
|
||||
@Reference
|
||||
protected void setItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.itemRegistry = itemRegistry;
|
||||
for (ModuleHandler handler : getHandlers().values()) {
|
||||
if (handler instanceof ItemStateConditionHandler) {
|
||||
((ItemStateConditionHandler) handler).setItemRegistry(this.itemRegistry);
|
||||
} else if (handler instanceof ItemCommandActionHandler) {
|
||||
((ItemCommandActionHandler) handler).setItemRegistry(this.itemRegistry);
|
||||
} else if (handler instanceof GroupCommandTriggerHandler) {
|
||||
((GroupCommandTriggerHandler) handler).setItemRegistry(this.itemRegistry);
|
||||
} else if (handler instanceof GroupStateTriggerHandler) {
|
||||
((GroupStateTriggerHandler) handler).setItemRegistry(this.itemRegistry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unsetter for itemRegistry (called by serviceTracker)
|
||||
*
|
||||
* @param itemRegistry
|
||||
*/
|
||||
protected void unsetItemRegistry(ItemRegistry itemRegistry) {
|
||||
for (ModuleHandler handler : getHandlers().values()) {
|
||||
if (handler instanceof ItemStateConditionHandler) {
|
||||
((ItemStateConditionHandler) handler).unsetItemRegistry(this.itemRegistry);
|
||||
} else if (handler instanceof ItemCommandActionHandler) {
|
||||
((ItemCommandActionHandler) handler).unsetItemRegistry(this.itemRegistry);
|
||||
} else if (handler instanceof GroupCommandTriggerHandler) {
|
||||
((GroupCommandTriggerHandler) handler).unsetItemRegistry(this.itemRegistry);
|
||||
} else if (handler instanceof GroupStateTriggerHandler) {
|
||||
((GroupStateTriggerHandler) handler).unsetItemRegistry(this.itemRegistry);
|
||||
}
|
||||
}
|
||||
this.itemRegistry = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for the eventPublisher (called by serviceTracker)
|
||||
*
|
||||
* @param eventPublisher
|
||||
*/
|
||||
@Reference
|
||||
protected void setEventPublisher(EventPublisher eventPublisher) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
for (ModuleHandler handler : getHandlers().values()) {
|
||||
if (handler instanceof ItemCommandActionHandler) {
|
||||
((ItemCommandActionHandler) handler).setEventPublisher(eventPublisher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unsetter for eventPublisher (called by serviceTracker)
|
||||
*
|
||||
* @param eventPublisher
|
||||
*/
|
||||
protected void unsetEventPublisher(EventPublisher eventPublisher) {
|
||||
this.eventPublisher = null;
|
||||
for (ModuleHandler handler : getHandlers().values()) {
|
||||
if (handler instanceof ItemCommandActionHandler) {
|
||||
((ItemCommandActionHandler) handler).unsetEventPublisher(eventPublisher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized ModuleHandler internalCreate(final Module module, final String ruleUID) {
|
||||
protected synchronized @Nullable ModuleHandler internalCreate(final Module module, final String ruleUID) {
|
||||
logger.trace("create {} -> {} : {}", module.getId(), module.getTypeUID(), ruleUID);
|
||||
final String moduleTypeUID = module.getTypeUID();
|
||||
if (module instanceof Trigger) {
|
||||
@ -182,22 +118,15 @@ public class CoreModuleHandlerFactory extends BaseModuleHandlerFactory implement
|
||||
|| ItemStateTriggerHandler.UPDATE_MODULE_TYPE_ID.equals(moduleTypeUID)) {
|
||||
return new ItemStateTriggerHandler((Trigger) module, bundleContext);
|
||||
} else if (GroupCommandTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID)) {
|
||||
final GroupCommandTriggerHandler handler = new GroupCommandTriggerHandler((Trigger) module,
|
||||
bundleContext);
|
||||
handler.setItemRegistry(itemRegistry);
|
||||
return handler;
|
||||
return new GroupCommandTriggerHandler((Trigger) module, bundleContext, itemRegistry);
|
||||
} else if (GroupStateTriggerHandler.CHANGE_MODULE_TYPE_ID.equals(moduleTypeUID)
|
||||
|| GroupStateTriggerHandler.UPDATE_MODULE_TYPE_ID.equals(moduleTypeUID)) {
|
||||
final GroupStateTriggerHandler handler = new GroupStateTriggerHandler((Trigger) module, bundleContext);
|
||||
handler.setItemRegistry(itemRegistry);
|
||||
return handler;
|
||||
return new GroupStateTriggerHandler((Trigger) module, bundleContext, itemRegistry);
|
||||
}
|
||||
} else if (module instanceof Condition) {
|
||||
// Handle conditions
|
||||
if (ItemStateConditionHandler.ITEM_STATE_CONDITION.equals(moduleTypeUID)) {
|
||||
ItemStateConditionHandler handler = new ItemStateConditionHandler((Condition) module);
|
||||
handler.setItemRegistry(itemRegistry);
|
||||
return handler;
|
||||
return new ItemStateConditionHandler((Condition) module, itemRegistry);
|
||||
} else if (GenericEventConditionHandler.MODULETYPE_ID.equals(moduleTypeUID)) {
|
||||
return new GenericEventConditionHandler((Condition) module);
|
||||
} else if (CompareConditionHandler.MODULE_TYPE.equals(moduleTypeUID)) {
|
||||
@ -206,10 +135,7 @@ public class CoreModuleHandlerFactory extends BaseModuleHandlerFactory implement
|
||||
} else if (module instanceof Action) {
|
||||
// Handle actions
|
||||
if (ItemCommandActionHandler.ITEM_COMMAND_ACTION.equals(moduleTypeUID)) {
|
||||
final ItemCommandActionHandler postCommandActionHandler = new ItemCommandActionHandler((Action) module);
|
||||
postCommandActionHandler.setEventPublisher(eventPublisher);
|
||||
postCommandActionHandler.setItemRegistry(itemRegistry);
|
||||
return postCommandActionHandler;
|
||||
return new ItemCommandActionHandler((Action) module, eventPublisher, itemRegistry);
|
||||
} else if (ItemStateUpdateActionHandler.ITEM_STATE_UPDATE_ACTION.equals(moduleTypeUID)) {
|
||||
return new ItemStateUpdateActionHandler((Action) module, eventPublisher, itemRegistry);
|
||||
} else if (RuleEnablementActionHandler.UID.equals(moduleTypeUID)) {
|
||||
|
@ -21,6 +21,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.annotation.ActionInput;
|
||||
import org.openhab.core.automation.handler.BaseActionModuleHandler;
|
||||
@ -35,6 +37,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Stefan Triller - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class AnnotationActionHandler extends BaseActionModuleHandler {
|
||||
|
||||
private static final String MODULE_RESULT = "result";
|
||||
@ -54,11 +57,11 @@ public class AnnotationActionHandler extends BaseActionModuleHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> execute(Map<String, Object> context) {
|
||||
public @Nullable Map<String, Object> execute(Map<String, Object> context) {
|
||||
Map<String, Object> output = new HashMap<>();
|
||||
|
||||
Annotation[][] annotations = method.getParameterAnnotations();
|
||||
List<Object> args = new ArrayList<>();
|
||||
List<@Nullable Object> args = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < annotations.length; i++) {
|
||||
Annotation[] annotationsOnParam = annotations[i];
|
||||
@ -90,6 +93,7 @@ public class AnnotationActionHandler extends BaseActionModuleHandler {
|
||||
if (result != null) {
|
||||
if (result instanceof Map<?, ?>) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> resultMap = (Map<String, Object>) result;
|
||||
for (Entry<String, Object> entry : resultMap.entrySet()) {
|
||||
if (hasOutput(moduleType, entry.getKey())) {
|
||||
|
@ -86,6 +86,7 @@ public class ChannelEventTriggerHandler extends BaseTriggerModuleHandler impleme
|
||||
if (event instanceof ChannelTriggeredEvent) {
|
||||
ChannelTriggeredEvent cte = (ChannelTriggeredEvent) event;
|
||||
if (channelUID.equals(cte.getChannel())) {
|
||||
String eventOnChannel = this.eventOnChannel;
|
||||
logger.trace("->FILTER: {}:{}", cte.getEvent(), eventOnChannel);
|
||||
eventMatches = eventOnChannel == null || eventOnChannel.isBlank()
|
||||
|| eventOnChannel.equals(cte.getEvent());
|
||||
|
@ -17,6 +17,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.handler.BaseConditionModuleHandler;
|
||||
@ -31,6 +32,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Benedikt Niehues - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class CompareConditionHandler extends BaseConditionModuleHandler {
|
||||
|
||||
public static final String MODULE_TYPE = "core.GenericCompareCondition";
|
||||
@ -47,7 +49,7 @@ public class CompareConditionHandler extends BaseConditionModuleHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSatisfied(Map<String, Object> context) {
|
||||
public boolean isSatisfied(Map<String, @Nullable Object> context) {
|
||||
Object operatorObj = this.module.getConfiguration().get(OPERATOR);
|
||||
String operator = (operatorObj != null && operatorObj instanceof String) ? (String) operatorObj : null;
|
||||
Object rightObj = this.module.getConfiguration().get(RIGHT_OP);
|
||||
@ -151,7 +153,7 @@ public class CompareConditionHandler extends BaseConditionModuleHandler {
|
||||
throw new UncomparableException();
|
||||
}
|
||||
|
||||
private @Nullable Object getRightOperandValue(String rightOperandString2, Object toCompare) {
|
||||
private @Nullable Object getRightOperandValue(String rightOperandString2, @Nullable Object toCompare) {
|
||||
if ("null".equals(rightOperandString2)) {
|
||||
return rightOperandString2;
|
||||
}
|
||||
@ -169,7 +171,7 @@ public class CompareConditionHandler extends BaseConditionModuleHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object getCompareValue(Object leftObj, String leftObjFieldName) {
|
||||
private @Nullable Object getCompareValue(@Nullable Object leftObj, @Nullable String leftObjFieldName) {
|
||||
if (leftObj == null || leftObjFieldName == null || leftObjFieldName.isEmpty() || leftObj instanceof String
|
||||
|| leftObj instanceof Integer || leftObj instanceof Long || leftObj instanceof Double) {
|
||||
return leftObj;
|
||||
|
@ -18,6 +18,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.handler.BaseConditionModuleHandler;
|
||||
import org.openhab.core.automation.handler.TimeBasedConditionHandler;
|
||||
@ -29,6 +30,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DayOfWeekConditionHandler extends BaseConditionModuleHandler implements TimeBasedConditionHandler {
|
||||
|
||||
public static final String MODULE_TYPE_ID = "timer.DayOfWeekCondition";
|
||||
|
@ -64,20 +64,20 @@ public class EphemerisConditionHandler extends BaseModuleHandler<Condition> impl
|
||||
|
||||
@Override
|
||||
public boolean isSatisfiedAt(ZonedDateTime time) {
|
||||
time = time.plusDays(offset); // Apply offset to time
|
||||
ZonedDateTime offsetTime = time.plusDays(offset); // Apply offset to time
|
||||
switch (module.getTypeUID()) {
|
||||
case HOLIDAY_MODULE_TYPE_ID:
|
||||
return ephemerisManager.isBankHoliday(time);
|
||||
return ephemerisManager.isBankHoliday(offsetTime);
|
||||
case NOT_HOLIDAY_MODULE_TYPE_ID:
|
||||
return !ephemerisManager.isBankHoliday(time);
|
||||
return !ephemerisManager.isBankHoliday(offsetTime);
|
||||
case WEEKEND_MODULE_TYPE_ID:
|
||||
return ephemerisManager.isWeekend(time);
|
||||
return ephemerisManager.isWeekend(offsetTime);
|
||||
case WEEKDAY_MODULE_TYPE_ID:
|
||||
return !ephemerisManager.isWeekend(time);
|
||||
return !ephemerisManager.isWeekend(offsetTime);
|
||||
case DAYSET_MODULE_TYPE_ID:
|
||||
final String dayset = this.dayset;
|
||||
if (dayset != null) {
|
||||
return ephemerisManager.isInDayset(dayset, time);
|
||||
return ephemerisManager.isInDayset(dayset, offsetTime);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.core.automation.internal.module.handler;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.ModuleHandlerCallback;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
import org.openhab.core.automation.handler.BaseTriggerModuleHandler;
|
||||
@ -32,6 +34,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Christoph Knauf - Initial contribution
|
||||
* @author Yordan Mihaylov - Remove Quarz lib dependency
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class GenericCronTriggerHandler extends BaseTriggerModuleHandler
|
||||
implements SchedulerRunnable, TimeBasedTriggerHandler {
|
||||
|
||||
@ -45,7 +48,7 @@ public class GenericCronTriggerHandler extends BaseTriggerModuleHandler
|
||||
|
||||
private final CronScheduler scheduler;
|
||||
private final String expression;
|
||||
private ScheduledCompletableFuture<?> schedule;
|
||||
private @Nullable ScheduledCompletableFuture<?> schedule;
|
||||
|
||||
public GenericCronTriggerHandler(Trigger module, CronScheduler scheduler) {
|
||||
super(module);
|
||||
@ -77,7 +80,7 @@ public class GenericCronTriggerHandler extends BaseTriggerModuleHandler
|
||||
@Override
|
||||
public void run() {
|
||||
if (callback != null) {
|
||||
((TriggerHandlerCallback) callback).triggered(module, null);
|
||||
((TriggerHandlerCallback) callback).triggered(module);
|
||||
} else {
|
||||
logger.debug("Tried to trigger, but callback isn't available!");
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ package org.openhab.core.automation.internal.module.handler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.handler.BaseConditionModuleHandler;
|
||||
import org.openhab.core.events.Event;
|
||||
@ -26,6 +28,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Benedikt Niehues - Initial contribution
|
||||
* @author Kai Kreuzer - refactored and simplified customized module handling
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class GenericEventConditionHandler extends BaseConditionModuleHandler {
|
||||
|
||||
public static final String MODULETYPE_ID = "core.GenericEventCondition";
|
||||
@ -41,7 +44,7 @@ public class GenericEventConditionHandler extends BaseConditionModuleHandler {
|
||||
super(module);
|
||||
}
|
||||
|
||||
private boolean isConfiguredAndMatches(String keyParam, String value) {
|
||||
private boolean isConfiguredAndMatches(String keyParam, @Nullable String value) {
|
||||
Object mo = module.getConfiguration().get(keyParam);
|
||||
String configValue = mo != null && mo instanceof String ? (String) mo : null;
|
||||
if (configValue != null) {
|
||||
|
@ -18,6 +18,9 @@ import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.ModuleHandlerCallback;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
import org.openhab.core.automation.handler.BaseTriggerModuleHandler;
|
||||
import org.openhab.core.automation.handler.TriggerHandlerCallback;
|
||||
@ -41,6 +44,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Benedikt Niehues - Initial contribution
|
||||
* @author Kai Kreuzer - refactored and simplified customized module handling
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class GenericEventTriggerHandler extends BaseTriggerModuleHandler implements EventSubscriber, EventFilter {
|
||||
|
||||
public static final String MODULE_TYPE_ID = "core.GenericEventTrigger";
|
||||
@ -56,7 +60,7 @@ public class GenericEventTriggerHandler extends BaseTriggerModuleHandler impleme
|
||||
private final Set<String> types;
|
||||
private final BundleContext bundleContext;
|
||||
|
||||
private ServiceRegistration<?> eventSubscriberRegistration;
|
||||
private @Nullable ServiceRegistration<?> eventSubscriberRegistration;
|
||||
|
||||
public GenericEventTriggerHandler(Trigger module, BundleContext bundleContext) {
|
||||
super(module);
|
||||
@ -81,12 +85,13 @@ public class GenericEventTriggerHandler extends BaseTriggerModuleHandler impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventFilter getEventFilter() {
|
||||
public @Nullable EventFilter getEventFilter() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(Event event) {
|
||||
ModuleHandlerCallback callback = this.callback;
|
||||
if (callback != null) {
|
||||
logger.trace("Received Event: Source: {} Topic: {} Type: {} Payload: {}", event.getSource(),
|
||||
event.getTopic(), event.getType(), event.getPayload());
|
||||
|
@ -53,6 +53,7 @@ public class GroupCommandTriggerHandler extends BaseTriggerModuleHandler impleme
|
||||
|
||||
private final Set<String> types;
|
||||
private final BundleContext bundleContext;
|
||||
private final ItemRegistry itemRegistry;
|
||||
|
||||
public static final String MODULE_TYPE_ID = "core.GroupCommandTrigger";
|
||||
|
||||
@ -60,14 +61,14 @@ public class GroupCommandTriggerHandler extends BaseTriggerModuleHandler impleme
|
||||
public static final String CFG_COMMAND = "command";
|
||||
|
||||
private ServiceRegistration<?> eventSubscriberRegistration;
|
||||
private @Nullable ItemRegistry itemRegistry;
|
||||
|
||||
public GroupCommandTriggerHandler(Trigger module, BundleContext bundleContext) {
|
||||
public GroupCommandTriggerHandler(Trigger module, BundleContext bundleContext, ItemRegistry itemRegistry) {
|
||||
super(module);
|
||||
this.groupName = (String) module.getConfiguration().get(CFG_GROUPNAME);
|
||||
this.command = (String) module.getConfiguration().get(CFG_COMMAND);
|
||||
this.types = Set.of(ItemCommandEvent.TYPE);
|
||||
this.bundleContext = bundleContext;
|
||||
this.itemRegistry = itemRegistry;
|
||||
Dictionary<String, Object> properties = new Hashtable<>();
|
||||
this.topic = "openhab/items/";
|
||||
properties.put("event.topics", topic);
|
||||
@ -95,9 +96,9 @@ public class GroupCommandTriggerHandler extends BaseTriggerModuleHandler impleme
|
||||
if (event instanceof ItemCommandEvent) {
|
||||
ItemCommandEvent icEvent = (ItemCommandEvent) event;
|
||||
String itemName = icEvent.getItemName();
|
||||
if (itemRegistry != null) {
|
||||
Item item = itemRegistry.get(itemName);
|
||||
if (item != null && item.getGroupNames().contains(groupName)) {
|
||||
String command = this.command;
|
||||
Command itemCommand = icEvent.getItemCommand();
|
||||
if (command == null || command.equals(itemCommand.toFullString())) {
|
||||
values.put("triggeringItem", item);
|
||||
@ -109,7 +110,6 @@ public class GroupCommandTriggerHandler extends BaseTriggerModuleHandler impleme
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* do the cleanup: unregistering eventSubscriber...
|
||||
@ -125,12 +125,4 @@ public class GroupCommandTriggerHandler extends BaseTriggerModuleHandler impleme
|
||||
logger.trace("->FILTER: {}", event.getTopic());
|
||||
return event.getTopic().startsWith(topic);
|
||||
}
|
||||
|
||||
public void setItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.itemRegistry = itemRegistry;
|
||||
}
|
||||
|
||||
public void unsetItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.itemRegistry = null;
|
||||
}
|
||||
}
|
||||
|
@ -61,11 +61,11 @@ public class GroupStateTriggerHandler extends BaseTriggerModuleHandler implement
|
||||
private final String previousState;
|
||||
private Set<String> types;
|
||||
private final BundleContext bundleContext;
|
||||
private @Nullable ItemRegistry itemRegistry;
|
||||
private ItemRegistry itemRegistry;
|
||||
|
||||
private ServiceRegistration<?> eventSubscriberRegistration;
|
||||
|
||||
public GroupStateTriggerHandler(Trigger module, BundleContext bundleContext) {
|
||||
public GroupStateTriggerHandler(Trigger module, BundleContext bundleContext, ItemRegistry itemRegistry) {
|
||||
super(module);
|
||||
this.groupName = (String) module.getConfiguration().get(CFG_GROUPNAME);
|
||||
this.state = (String) module.getConfiguration().get(CFG_STATE);
|
||||
@ -76,6 +76,7 @@ public class GroupStateTriggerHandler extends BaseTriggerModuleHandler implement
|
||||
this.types = Set.of(ItemStateChangedEvent.TYPE, GroupItemStateChangedEvent.TYPE);
|
||||
}
|
||||
this.bundleContext = bundleContext;
|
||||
this.itemRegistry = itemRegistry;
|
||||
Dictionary<String, Object> properties = new Hashtable<>();
|
||||
properties.put("event.topics", "openhab/items/*");
|
||||
eventSubscriberRegistration = this.bundleContext.registerService(EventSubscriber.class.getName(), this,
|
||||
@ -101,7 +102,6 @@ public class GroupStateTriggerHandler extends BaseTriggerModuleHandler implement
|
||||
if (event instanceof ItemStateEvent && UPDATE_MODULE_TYPE_ID.equals(module.getTypeUID())) {
|
||||
ItemStateEvent isEvent = (ItemStateEvent) event;
|
||||
String itemName = isEvent.getItemName();
|
||||
if (itemRegistry != null) {
|
||||
Item item = itemRegistry.get(itemName);
|
||||
if (item != null && item.getGroupNames().contains(groupName)) {
|
||||
State state = isEvent.getItemState();
|
||||
@ -113,11 +113,9 @@ public class GroupStateTriggerHandler extends BaseTriggerModuleHandler implement
|
||||
cb.triggered(this.module, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (event instanceof ItemStateChangedEvent && CHANGE_MODULE_TYPE_ID.equals(module.getTypeUID())) {
|
||||
ItemStateChangedEvent iscEvent = (ItemStateChangedEvent) event;
|
||||
String itemName = iscEvent.getItemName();
|
||||
if (itemRegistry != null) {
|
||||
Item item = itemRegistry.get(itemName);
|
||||
if (item != null && item.getGroupNames().contains(groupName)) {
|
||||
State state = iscEvent.getItemState();
|
||||
@ -135,7 +133,6 @@ public class GroupStateTriggerHandler extends BaseTriggerModuleHandler implement
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean stateMatches(@Nullable String requiredState, State state) {
|
||||
if (requiredState == null) {
|
||||
@ -160,12 +157,4 @@ public class GroupStateTriggerHandler extends BaseTriggerModuleHandler implement
|
||||
logger.trace("->FILTER: {}:{}", event.getTopic(), groupName);
|
||||
return event.getTopic().startsWith("openhab/items/");
|
||||
}
|
||||
|
||||
public void setItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.itemRegistry = itemRegistry;
|
||||
}
|
||||
|
||||
public void unsetItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.itemRegistry = null;
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ package org.openhab.core.automation.internal.module.handler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.handler.BaseActionModuleHandler;
|
||||
import org.openhab.core.events.EventPublisher;
|
||||
@ -34,6 +36,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Kai Kreuzer - refactored and simplified customized module handling
|
||||
* @author Stefan Triller - use command from input first and if not set, use command from configuration
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ItemCommandActionHandler extends BaseActionModuleHandler {
|
||||
|
||||
public static final String ITEM_COMMAND_ACTION = "core.ItemCommandAction";
|
||||
@ -42,8 +45,8 @@ public class ItemCommandActionHandler extends BaseActionModuleHandler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ItemCommandActionHandler.class);
|
||||
|
||||
private ItemRegistry itemRegistry;
|
||||
private EventPublisher eventPublisher;
|
||||
private final EventPublisher eventPublisher;
|
||||
private final ItemRegistry itemRegistry;
|
||||
|
||||
/**
|
||||
* constructs a new ItemCommandActionHandler
|
||||
@ -51,58 +54,18 @@ public class ItemCommandActionHandler extends BaseActionModuleHandler {
|
||||
* @param module
|
||||
* @param moduleTypes
|
||||
*/
|
||||
public ItemCommandActionHandler(Action module) {
|
||||
public ItemCommandActionHandler(Action module, EventPublisher eventPublisher, ItemRegistry itemRegistry) {
|
||||
super(module);
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for itemRegistry, used by DS
|
||||
*
|
||||
* @param itemRegistry
|
||||
*/
|
||||
public void setItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.itemRegistry = itemRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* unsetter for itemRegistry, used by DS
|
||||
*
|
||||
* @param itemRegistry
|
||||
*/
|
||||
public void unsetItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.itemRegistry = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for eventPublisher used by DS
|
||||
*
|
||||
* @param eventPublisher
|
||||
*/
|
||||
public void setEventPublisher(EventPublisher eventPublisher) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
/**
|
||||
* unsetter for eventPublisher used by DS
|
||||
*
|
||||
* @param eventPublisher
|
||||
*/
|
||||
public void unsetEventPublisher(EventPublisher eventPublisher) {
|
||||
this.eventPublisher = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
this.eventPublisher = null;
|
||||
this.itemRegistry = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> execute(Map<String, Object> inputs) {
|
||||
public @Nullable Map<String, Object> execute(Map<String, Object> inputs) {
|
||||
String itemName = (String) module.getConfiguration().get(ITEM_NAME);
|
||||
String command = (String) module.getConfiguration().get(COMMAND);
|
||||
|
||||
if (itemName != null && eventPublisher != null && itemRegistry != null) {
|
||||
if (itemName != null) {
|
||||
try {
|
||||
Item item = itemRegistry.getItem(itemName);
|
||||
|
||||
|
@ -18,6 +18,9 @@ import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.ModuleHandlerCallback;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
import org.openhab.core.automation.handler.BaseTriggerModuleHandler;
|
||||
import org.openhab.core.automation.handler.TriggerHandlerCallback;
|
||||
@ -38,6 +41,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ItemCommandTriggerHandler extends BaseTriggerModuleHandler implements EventSubscriber, EventFilter {
|
||||
|
||||
public static final String MODULE_TYPE_ID = "core.ItemCommandTrigger";
|
||||
@ -48,13 +52,13 @@ public class ItemCommandTriggerHandler extends BaseTriggerModuleHandler implemen
|
||||
private final Logger logger = LoggerFactory.getLogger(ItemCommandTriggerHandler.class);
|
||||
|
||||
private final String itemName;
|
||||
private final String command;
|
||||
private final @Nullable String command;
|
||||
private final String topic;
|
||||
|
||||
private final Set<String> types;
|
||||
private final BundleContext bundleContext;
|
||||
|
||||
private ServiceRegistration<?> eventSubscriberRegistration;
|
||||
private @Nullable ServiceRegistration<?> eventSubscriberRegistration;
|
||||
|
||||
public ItemCommandTriggerHandler(Trigger module, BundleContext bundleContext) {
|
||||
super(module);
|
||||
@ -75,20 +79,22 @@ public class ItemCommandTriggerHandler extends BaseTriggerModuleHandler implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventFilter getEventFilter() {
|
||||
public @Nullable EventFilter getEventFilter() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(Event event) {
|
||||
ModuleHandlerCallback callback = this.callback;
|
||||
if (callback != null) {
|
||||
logger.trace("Received Event: Source: {} Topic: {} Type: {} Payload: {}", event.getSource(),
|
||||
event.getTopic(), event.getType(), event.getPayload());
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
if (event instanceof ItemCommandEvent) {
|
||||
Command command = ((ItemCommandEvent) event).getItemCommand();
|
||||
if (this.command == null || this.command.equals(command.toFullString())) {
|
||||
values.put("command", command);
|
||||
String command = this.command;
|
||||
Command itemCommand = ((ItemCommandEvent) event).getItemCommand();
|
||||
if (command == null || command.equals(itemCommand.toFullString())) {
|
||||
values.put("command", itemCommand);
|
||||
values.put("event", event);
|
||||
((TriggerHandlerCallback) callback).triggered(this.module, values);
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ package org.openhab.core.automation.internal.module.handler;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.handler.BaseConditionModuleHandler;
|
||||
import org.openhab.core.items.Item;
|
||||
@ -49,35 +48,13 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler {
|
||||
|
||||
public static final String ITEM_STATE_CONDITION = "core.ItemStateCondition";
|
||||
|
||||
private @Nullable ItemRegistry itemRegistry;
|
||||
private final ItemRegistry itemRegistry;
|
||||
|
||||
public ItemStateConditionHandler(Condition condition) {
|
||||
public ItemStateConditionHandler(Condition condition, ItemRegistry itemRegistry) {
|
||||
super(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* setter for itemRegistry, used by DS
|
||||
*
|
||||
* @param itemRegistry
|
||||
*/
|
||||
public void setItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.itemRegistry = itemRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* unsetter for itemRegistry used by DS
|
||||
*
|
||||
* @param itemRegistry
|
||||
*/
|
||||
public void unsetItemRegistry(ItemRegistry itemRegistry) {
|
||||
this.itemRegistry = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
itemRegistry = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSatisfied(Map<String, Object> inputs) {
|
||||
String itemName = (String) module.getConfiguration().get(ITEM_NAME);
|
||||
@ -88,10 +65,6 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler {
|
||||
state);
|
||||
return false;
|
||||
}
|
||||
if (itemRegistry == null) {
|
||||
logger.error("The ItemRegistry is not available to evaluate the condition.");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
logger.debug("ItemStateCondition '{}' checking if {} {} {}", module.getId(), itemName, operator, state);
|
||||
switch (operator) {
|
||||
@ -174,7 +147,6 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("null")
|
||||
private boolean equalsToItemState(String itemName, String state) throws ItemNotFoundException {
|
||||
Item item = itemRegistry.getItem(itemName);
|
||||
State compareState = TypeParser.parseState(item.getAcceptedDataTypes(), state);
|
||||
|
@ -18,6 +18,9 @@ import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.ModuleHandlerCallback;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
import org.openhab.core.automation.handler.BaseTriggerModuleHandler;
|
||||
import org.openhab.core.automation.handler.TriggerHandlerCallback;
|
||||
@ -41,6 +44,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
* @author Simon Merschjohann - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ItemStateTriggerHandler extends BaseTriggerModuleHandler implements EventSubscriber, EventFilter {
|
||||
|
||||
public static final String UPDATE_MODULE_TYPE_ID = "core.ItemStateUpdateTrigger";
|
||||
@ -53,12 +57,12 @@ public class ItemStateTriggerHandler extends BaseTriggerModuleHandler implements
|
||||
private final Logger logger = LoggerFactory.getLogger(ItemStateTriggerHandler.class);
|
||||
|
||||
private final String itemName;
|
||||
private final String state;
|
||||
private final @Nullable String state;
|
||||
private final String previousState;
|
||||
private Set<String> types;
|
||||
private final BundleContext bundleContext;
|
||||
|
||||
private ServiceRegistration<?> eventSubscriberRegistration;
|
||||
private @Nullable ServiceRegistration<?> eventSubscriberRegistration;
|
||||
|
||||
public ItemStateTriggerHandler(Trigger module, BundleContext bundleContext) {
|
||||
super(module);
|
||||
@ -83,28 +87,30 @@ public class ItemStateTriggerHandler extends BaseTriggerModuleHandler implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventFilter getEventFilter() {
|
||||
public @Nullable EventFilter getEventFilter() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(Event event) {
|
||||
ModuleHandlerCallback callback = this.callback;
|
||||
if (callback != null) {
|
||||
logger.trace("Received Event: Source: {} Topic: {} Type: {} Payload: {}", event.getSource(),
|
||||
event.getTopic(), event.getType(), event.getPayload());
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
if (event instanceof ItemStateEvent && UPDATE_MODULE_TYPE_ID.equals(module.getTypeUID())) {
|
||||
State state = ((ItemStateEvent) event).getItemState();
|
||||
if ((this.state == null || this.state.equals(state.toFullString()))) {
|
||||
values.put("state", state);
|
||||
String state = this.state;
|
||||
State itemState = ((ItemStateEvent) event).getItemState();
|
||||
if ((state == null || state.equals(itemState.toFullString()))) {
|
||||
values.put("state", itemState);
|
||||
}
|
||||
} else if (event instanceof ItemStateChangedEvent && CHANGE_MODULE_TYPE_ID.equals(module.getTypeUID())) {
|
||||
State state = ((ItemStateChangedEvent) event).getItemState();
|
||||
State oldState = ((ItemStateChangedEvent) event).getOldItemState();
|
||||
State itemState = ((ItemStateChangedEvent) event).getItemState();
|
||||
State oldItemState = ((ItemStateChangedEvent) event).getOldItemState();
|
||||
|
||||
if (stateMatches(this.state, state) && stateMatches(this.previousState, oldState)) {
|
||||
values.put("oldState", oldState);
|
||||
values.put("newState", state);
|
||||
if (stateMatches(this.state, itemState) && stateMatches(this.previousState, oldItemState)) {
|
||||
values.put("oldState", oldItemState);
|
||||
values.put("newState", itemState);
|
||||
}
|
||||
}
|
||||
if (!values.isEmpty()) {
|
||||
@ -114,7 +120,7 @@ public class ItemStateTriggerHandler extends BaseTriggerModuleHandler implements
|
||||
}
|
||||
}
|
||||
|
||||
private boolean stateMatches(String requiredState, State state) {
|
||||
private boolean stateMatches(@Nullable String requiredState, State state) {
|
||||
if (requiredState == null) {
|
||||
return true;
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ package org.openhab.core.automation.internal.module.handler;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.RuleRegistry;
|
||||
import org.openhab.core.automation.handler.BaseActionModuleHandler;
|
||||
@ -41,6 +43,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Plamen Peev - Initial contribution
|
||||
* @author Kai Kreuzer - use rule engine instead of registry
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class RuleEnablementActionHandler extends BaseActionModuleHandler {
|
||||
|
||||
/**
|
||||
@ -91,7 +94,7 @@ public class RuleEnablementActionHandler extends BaseActionModuleHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> execute(Map<String, Object> context) {
|
||||
public @Nullable Map<String, Object> execute(Map<String, Object> context) {
|
||||
for (String uid : uids) {
|
||||
if (callback != null) {
|
||||
callback.setEnabled(uid, enable);
|
||||
|
@ -15,6 +15,8 @@ package org.openhab.core.automation.internal.module.handler;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.handler.BaseActionModuleHandler;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
@ -39,6 +41,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Benedikt Niehues - Initial contribution
|
||||
* @author Kai Kreuzer - use rule engine instead of registry
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class RunRuleActionHandler extends BaseActionModuleHandler {
|
||||
|
||||
/**
|
||||
@ -86,7 +89,7 @@ public class RunRuleActionHandler extends BaseActionModuleHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> execute(Map<String, Object> context) {
|
||||
public @Nullable Map<String, Object> execute(Map<String, Object> context) {
|
||||
// execute each rule after the other; at the moment synchronously
|
||||
for (String uid : ruleUIDs) {
|
||||
if (callback != null) {
|
||||
|
@ -17,6 +17,8 @@ import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.handler.BaseConditionModuleHandler;
|
||||
import org.openhab.core.automation.handler.TimeBasedConditionHandler;
|
||||
@ -29,6 +31,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Dominik Schlierf - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class TimeOfDayConditionHandler extends BaseConditionModuleHandler implements TimeBasedConditionHandler {
|
||||
|
||||
public static final String MODULE_TYPE_ID = "core.TimeOfDayCondition";
|
||||
@ -45,11 +48,11 @@ public class TimeOfDayConditionHandler extends BaseConditionModuleHandler implem
|
||||
/**
|
||||
* The start time of the user configured time span.
|
||||
*/
|
||||
private final LocalTime startTime;
|
||||
private final @Nullable LocalTime startTime;
|
||||
/**
|
||||
* The end time of the user configured time span.
|
||||
*/
|
||||
private final LocalTime endTime;
|
||||
private final @Nullable LocalTime endTime;
|
||||
|
||||
public TimeOfDayConditionHandler(Condition condition) {
|
||||
super(condition);
|
||||
@ -67,6 +70,8 @@ public class TimeOfDayConditionHandler extends BaseConditionModuleHandler implem
|
||||
|
||||
@Override
|
||||
public boolean isSatisfiedAt(ZonedDateTime time) {
|
||||
LocalTime startTime = this.startTime;
|
||||
LocalTime endTime = this.endTime;
|
||||
if (startTime == null || endTime == null) {
|
||||
logger.warn("Time condition with id {} is not well configured: startTime={} endTime = {}", module.getId(),
|
||||
startTime, endTime);
|
||||
|
@ -14,6 +14,8 @@ package org.openhab.core.automation.internal.module.handler;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.ModuleHandlerCallback;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
import org.openhab.core.automation.handler.BaseTriggerModuleHandler;
|
||||
@ -32,6 +34,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class TimeOfDayTriggerHandler extends BaseTriggerModuleHandler
|
||||
implements SchedulerRunnable, TimeBasedTriggerHandler {
|
||||
|
||||
@ -44,7 +47,7 @@ public class TimeOfDayTriggerHandler extends BaseTriggerModuleHandler
|
||||
|
||||
private final CronScheduler scheduler;
|
||||
private final String expression;
|
||||
private ScheduledCompletableFuture<?> schedule;
|
||||
private @Nullable ScheduledCompletableFuture<?> schedule;
|
||||
|
||||
public TimeOfDayTriggerHandler(Trigger module, CronScheduler scheduler) {
|
||||
super(module);
|
||||
@ -80,7 +83,7 @@ public class TimeOfDayTriggerHandler extends BaseTriggerModuleHandler
|
||||
@Override
|
||||
public void run() {
|
||||
if (callback != null) {
|
||||
((TriggerHandlerCallback) callback).triggered(module, null);
|
||||
((TriggerHandlerCallback) callback).triggered(module);
|
||||
} else {
|
||||
logger.debug("Tried to trigger, but callback isn't available!");
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ package org.openhab.core.automation.internal.module.handler;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Condition;
|
||||
import org.openhab.core.automation.Module;
|
||||
import org.openhab.core.automation.Trigger;
|
||||
@ -22,6 +24,7 @@ import org.openhab.core.automation.handler.BaseModuleHandlerFactory;
|
||||
import org.openhab.core.automation.handler.ModuleHandler;
|
||||
import org.openhab.core.automation.handler.ModuleHandlerFactory;
|
||||
import org.openhab.core.scheduler.CronScheduler;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.Deactivate;
|
||||
import org.osgi.service.component.annotations.Reference;
|
||||
@ -35,6 +38,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Christoph Knauf - Initial contribution
|
||||
* @author Kai Kreuzer - added new module types
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@Component(immediate = true, service = ModuleHandlerFactory.class)
|
||||
public class TimerModuleHandlerFactory extends BaseModuleHandlerFactory {
|
||||
|
||||
@ -45,7 +49,12 @@ public class TimerModuleHandlerFactory extends BaseModuleHandlerFactory {
|
||||
.asList(new String[] { GenericCronTriggerHandler.MODULE_TYPE_ID, TimeOfDayTriggerHandler.MODULE_TYPE_ID,
|
||||
TimeOfDayConditionHandler.MODULE_TYPE_ID, DayOfWeekConditionHandler.MODULE_TYPE_ID });
|
||||
|
||||
private CronScheduler scheduler;
|
||||
private final CronScheduler scheduler;
|
||||
|
||||
@Activate
|
||||
public TimerModuleHandlerFactory(final @Reference CronScheduler scheduler) {
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deactivate
|
||||
@ -53,22 +62,13 @@ public class TimerModuleHandlerFactory extends BaseModuleHandlerFactory {
|
||||
super.deactivate();
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setCronScheduler(CronScheduler scheduler) {
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
protected void unsetCronScheduler(CronScheduler scheduler) {
|
||||
this.scheduler = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getTypes() {
|
||||
return TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModuleHandler internalCreate(Module module, String ruleUID) {
|
||||
protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID) {
|
||||
logger.trace("create {} -> {}", module.getId(), module.getTypeUID());
|
||||
String moduleTypeUID = module.getTypeUID();
|
||||
if (GenericCronTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID) && module instanceof Trigger) {
|
||||
|
@ -218,6 +218,9 @@ public class AnnotatedActionModuleTypeProvider extends BaseModuleHandlerFactory
|
||||
false);
|
||||
if (finalMI != null) {
|
||||
ActionType moduleType = helper.buildModuleType(module.getTypeUID(), moduleInformation);
|
||||
if (moduleType == null) {
|
||||
return null;
|
||||
}
|
||||
return new AnnotationActionHandler(actionModule, moduleType, finalMI.getMethod(),
|
||||
finalMI.getActionProvider());
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.core.automation.internal.parser.gson;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.type.ActionType;
|
||||
import org.openhab.core.automation.type.CompositeActionType;
|
||||
|
||||
@ -24,10 +25,11 @@ import com.google.gson.InstanceCreator;
|
||||
*
|
||||
* @author Ana Dimova - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ActionInstanceCreator implements InstanceCreator<CompositeActionType> {
|
||||
|
||||
@Override
|
||||
public CompositeActionType createInstance(Type type) {
|
||||
public CompositeActionType createInstance(@NonNullByDefault({}) Type type) {
|
||||
return new CompositeActionType(null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.core.automation.internal.parser.gson;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.type.CompositeConditionType;
|
||||
import org.openhab.core.automation.type.ConditionType;
|
||||
|
||||
@ -24,10 +25,11 @@ import com.google.gson.InstanceCreator;
|
||||
*
|
||||
* @author Ana Dimova - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ConditionInstanceCreator implements InstanceCreator<CompositeConditionType> {
|
||||
|
||||
@Override
|
||||
public CompositeConditionType createInstance(Type type) {
|
||||
public CompositeConditionType createInstance(@NonNullByDefault({}) Type type) {
|
||||
return new CompositeConditionType(null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.dto.ActionTypeDTOMapper;
|
||||
import org.openhab.core.automation.dto.CompositeActionTypeDTO;
|
||||
import org.openhab.core.automation.dto.CompositeConditionTypeDTO;
|
||||
@ -42,6 +44,7 @@ import org.osgi.service.component.annotations.Component;
|
||||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@Component(immediate = true, service = Parser.class, property = { "parser.type=parser.module.type", "format=json" })
|
||||
public class ModuleTypeGSONParser extends AbstractGSONParser<ModuleType> {
|
||||
|
||||
@ -68,7 +71,7 @@ public class ModuleTypeGSONParser extends AbstractGSONParser<ModuleType> {
|
||||
gson.toJson(map, writer);
|
||||
}
|
||||
|
||||
private void addAll(Set<ModuleType> result, List<? extends ModuleTypeDTO> moduleTypes) {
|
||||
private void addAll(Set<ModuleType> result, @Nullable List<? extends ModuleTypeDTO> moduleTypes) {
|
||||
if (moduleTypes != null) {
|
||||
for (ModuleTypeDTO mt : moduleTypes) {
|
||||
if (mt instanceof CompositeTriggerTypeDTO) {
|
||||
|
@ -14,6 +14,8 @@ package org.openhab.core.automation.internal.parser.gson;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.dto.CompositeActionTypeDTO;
|
||||
import org.openhab.core.automation.dto.CompositeConditionTypeDTO;
|
||||
import org.openhab.core.automation.dto.CompositeTriggerTypeDTO;
|
||||
@ -24,11 +26,12 @@ import org.openhab.core.automation.dto.CompositeTriggerTypeDTO;
|
||||
*
|
||||
* @author Kai Kreuzer - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ModuleTypeParsingContainer {
|
||||
|
||||
public List<CompositeTriggerTypeDTO> triggers;
|
||||
public @Nullable List<CompositeTriggerTypeDTO> triggers;
|
||||
|
||||
public List<CompositeConditionTypeDTO> conditions;
|
||||
public @Nullable List<CompositeConditionTypeDTO> conditions;
|
||||
|
||||
public List<CompositeActionTypeDTO> actions;
|
||||
public @Nullable List<CompositeActionTypeDTO> actions;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.core.automation.internal.parser.gson;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.type.CompositeTriggerType;
|
||||
import org.openhab.core.automation.type.TriggerType;
|
||||
|
||||
@ -24,10 +25,11 @@ import com.google.gson.InstanceCreator;
|
||||
*
|
||||
* @author Ana Dimova - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class TriggerInstanceCreator implements InstanceCreator<CompositeTriggerType> {
|
||||
|
||||
@Override
|
||||
public CompositeTriggerType createInstance(Type type) {
|
||||
public CompositeTriggerType createInstance(@NonNullByDefault({}) Type type) {
|
||||
return new CompositeTriggerType(null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.Rule;
|
||||
import org.openhab.core.automation.template.TemplateProvider;
|
||||
import org.openhab.core.automation.type.ModuleTypeProvider;
|
||||
@ -34,6 +36,7 @@ import org.slf4j.LoggerFactory;
|
||||
* @author Kai Kreuzer - refactored (managed) provider and registry implementation
|
||||
* @param <E>
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class AutomationResourceBundlesEventQueue<@NonNull E> implements Runnable {
|
||||
|
||||
/**
|
||||
@ -52,7 +55,7 @@ public class AutomationResourceBundlesEventQueue<@NonNull E> implements Runnable
|
||||
*/
|
||||
private boolean running = false;
|
||||
|
||||
private Thread runningThread;
|
||||
private @Nullable Thread runningThread;
|
||||
|
||||
/**
|
||||
* This field is for synchronization purposes
|
||||
|
@ -19,6 +19,8 @@ import java.nio.file.Path;
|
||||
import java.nio.file.WatchEvent;
|
||||
import java.nio.file.WatchEvent.Kind;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.service.AbstractWatchService;
|
||||
|
||||
/**
|
||||
@ -30,6 +32,7 @@ import org.openhab.core.service.AbstractWatchService;
|
||||
* @author Ana Dimova - Initial contribution
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@NonNullByDefault
|
||||
public class AutomationWatchService extends AbstractWatchService {
|
||||
|
||||
private AbstractFileProvider provider;
|
||||
@ -45,7 +48,7 @@ public class AutomationWatchService extends AbstractWatchService {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Kind<?>[] getWatchEventKinds(Path subDir) {
|
||||
protected Kind<?> @Nullable [] getWatchEventKinds(Path subDir) {
|
||||
return new Kind<?>[] { ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY };
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.core.automation.internal.provider.file;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.automation.parser.Parser;
|
||||
import org.openhab.core.automation.template.RuleTemplate;
|
||||
import org.openhab.core.automation.template.RuleTemplateProvider;
|
||||
@ -28,6 +29,7 @@ import org.osgi.service.component.annotations.ReferencePolicy;
|
||||
*
|
||||
* @author Ana Dimova - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@Component(immediate = true, service = RuleTemplateProvider.class)
|
||||
public class TemplateFileProviderWatcher extends TemplateFileProvider {
|
||||
|
||||
|
@ -13,15 +13,19 @@
|
||||
package org.openhab.core.automation.internal.provider.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* This class isolates the java 1.7 functionality which tracks the file system changes.
|
||||
*
|
||||
* @author Ana Dimova - Initial contribution
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@NonNullByDefault
|
||||
public class WatchServiceUtil {
|
||||
|
||||
private static final Map<AbstractFileProvider, Map<String, AutomationWatchService>> WATCH_SERVICES = new HashMap<>();
|
||||
@ -46,17 +50,22 @@ public class WatchServiceUtil {
|
||||
}
|
||||
|
||||
public static void deactivateWatchService(String watchingDir, AbstractFileProvider provider) {
|
||||
AutomationWatchService aws;
|
||||
AutomationWatchService aws = null;
|
||||
synchronized (WATCH_SERVICES) {
|
||||
Map<String, AutomationWatchService> watchers = WATCH_SERVICES.get(provider);
|
||||
if (watchers != null) {
|
||||
aws = watchers.remove(watchingDir);
|
||||
if (watchers.isEmpty()) {
|
||||
WATCH_SERVICES.remove(provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (aws != null) {
|
||||
aws.deactivate();
|
||||
provider.removeResources(aws.getSourcePath().toFile());
|
||||
Path sourcePath = aws.getSourcePath();
|
||||
if (sourcePath != null) {
|
||||
provider.removeResources(sourcePath.toFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,6 +235,9 @@ public class AnnotatedThingActionModuleTypeProvider extends BaseModuleHandlerFac
|
||||
true);
|
||||
if (finalMI != null) {
|
||||
ActionType moduleType = helper.buildModuleType(module.getTypeUID(), moduleInformation);
|
||||
if (moduleType == null) {
|
||||
return null;
|
||||
}
|
||||
return new AnnotationActionHandler(actionModule, moduleType, finalMI.getMethod(),
|
||||
finalMI.getActionProvider());
|
||||
}
|
||||
|
@ -238,8 +238,6 @@ public class ItemStateConditionHandlerTest {
|
||||
.withId("conditionId") //
|
||||
.withTypeUID(ItemStateConditionHandler.ITEM_STATE_CONDITION) //
|
||||
.withConfiguration(configuration);
|
||||
ItemStateConditionHandler handler = new ItemStateConditionHandler(builder.build());
|
||||
handler.setItemRegistry(mockItemRegistry);
|
||||
return handler;
|
||||
return new ItemStateConditionHandler(builder.build(), mockItemRegistry);
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,14 @@ package org.openhab.core.library.dimension;
|
||||
|
||||
import javax.measure.Quantity;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Define Area density type (basic unit is kg/m^2)
|
||||
* https://en.wikipedia.org/wiki/Area_density
|
||||
*
|
||||
* @author Gaël L'hopital - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface ArealDensity extends Quantity<ArealDensity> {
|
||||
}
|
||||
|
@ -14,10 +14,13 @@ package org.openhab.core.library.dimension;
|
||||
|
||||
import javax.measure.Quantity;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Define Density type (basic unit is kg/m^3)
|
||||
*
|
||||
* @author Jan N. Klug - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface Density extends Quantity<Density> {
|
||||
}
|
||||
|
@ -14,11 +14,14 @@ package org.openhab.core.library.dimension;
|
||||
|
||||
import javax.measure.Quantity;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* This interface represents the intensity dimension.
|
||||
*
|
||||
* @author Henning Treu - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface Intensity extends Quantity<Intensity> {
|
||||
|
||||
}
|
||||
|
@ -14,10 +14,13 @@ package org.openhab.core.library.dimension;
|
||||
|
||||
import javax.measure.Quantity;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* Define Volumetric Flow Rate type (basic unit is m^3/s).
|
||||
*
|
||||
* @author Łukasz Dywicki - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface VolumetricFlowRate extends Quantity<VolumetricFlowRate> {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user