100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Macro and Timer (Trigger) protocol updates
Rich Turner7862a31643f8
diff --git a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.javaindex a25812a41..22b850d5c 100644--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java@@ -26,14 +26,14 @@ import org.openremote.container.message.MessageBrokerContext;import org.openremote.container.message.MessageBrokerService;import org.openremote.container.message.MessageBrokerSetupService;import org.openremote.container.timer.TimerService;-import org.openremote.model.AbstractValueHolder;import org.openremote.model.HasUniqueResourceName;import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.AssetMeta;import org.openremote.model.asset.agent.AgentLink;-import org.openremote.model.attribute.*;+import org.openremote.model.attribute.AttributeEvent;+import org.openremote.model.attribute.AttributeRef;+import org.openremote.model.attribute.AttributeState;+import org.openremote.model.attribute.MetaItem;import org.openremote.model.util.Triplet;-import org.openremote.model.value.Values;import java.util.Arrays;import java.util.Collection;@@ -85,31 +85,7 @@ public abstract class AbstractProtocol implements Protocol {LOG.warning("Attribute doesn't exist on this protocol: " + event.getAttributeRef());} else {AssetAttribute protocolConfiguration = getLinkedProtocolConfiguration(attribute);-- // TODO: Merge this into new TimerProtocol as custom configuration item- // If attribute is linked to protocol's enabled status handle here- boolean isLinkedToEnabledStatus = attribute- .getMetaItem(AssetMeta.PROTOCOL_PROPERTY)- .flatMap(AbstractValueHolder::getValueAsString)- .map(property -> property.equals("ENABLED"))- .orElse(false);-- if (isLinkedToEnabledStatus) {- LOG.fine("Attribute is linked to protocol's enabled property so handling write here");-- // check event value is a boolean- boolean enabled = Values.getBoolean(event.getValue()- .orElse(null))- .orElseThrow(() -> new IllegalStateException("Writing to protocol configuration ENABLED property requires a boolean value"));-- if (enabled == protocolConfiguration.isEnabled()) {- LOG.finer("Protocol configuration enabled status is already: " + enabled);- } else {- updateLinkedProtocolConfiguration(protocolConfiguration, AssetMeta.ENABLED, new MetaItem(AssetMeta.ENABLED, Values.create(enabled)));- }- } else {- processLinkedAttributeWrite(event, protocolConfiguration);- }+ processLinkedAttributeWrite(event, protocolConfiguration);}}}@@ -154,23 +130,8 @@ public abstract class AbstractProtocol implements Protocol {synchronized (linkedAttributes) {attributes.forEach(attribute -> {LOG.fine("Linking attribute to '" + getProtocolName() + "': " + attribute);-- // If attribute is linked to protocol configuration enabled status handle here- boolean isLinkedToEnabledStatus = attribute- .getMetaItem(AssetMeta.PROTOCOL_PROPERTY)- .flatMap(AbstractValueHolder::getValueAsString)- .map(property -> property.equals("ENABLED"))- .orElse(false);-- AttributeRef attributeRef = attribute.getReferenceOrThrow();- linkedAttributes.put(attributeRef, attribute);-- if (isLinkedToEnabledStatus) {- LOG.fine("Attribute is linked to protocol's enabled property so handling here");- updateLinkedAttribute(new AttributeState(attributeRef, Values.create(protocolConfiguration.isEnabled())));- } else {- doLinkAttribute(attribute, protocolConfiguration);- }+ linkedAttributes.put(attribute.getReferenceOrThrow(), attribute);+ doLinkAttribute(attribute, protocolConfiguration);});}}@@ -180,18 +141,7 @@ public abstract class AbstractProtocol implements Protocol {synchronized (linkedAttributes) {attributes.forEach(attribute -> {LOG.fine("Unlinking attribute on '" + getProtocolName() + "': " + attribute);-- // If attribute is linked to protocol's enabled status handle here- boolean isLinkedToEnabledStatus = attribute- .getMetaItem(AssetMeta.PROTOCOL_PROPERTY)- .flatMap(AbstractValueHolder::getValueAsString)- .map(property -> property.equals("ENABLED"))- .orElse(false);-- if (!isLinkedToEnabledStatus) {- // Only pass to the protocol if it is not linked to enabled status- doUnlinkAttribute(attribute, protocolConfiguration);- }+ doUnlinkAttribute(attribute, protocolConfiguration);linkedAttributes.remove(attribute.getReferenceOrThrow());});}diff --git a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroAction.java b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroAction.javaindex 22beb0663..f24d7faf5 100644--- a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroAction.java+++ b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroAction.java@@ -29,7 +29,7 @@ import org.openremote.model.value.Values;import java.util.Objects;import java.util.Optional;-import static org.openremote.agent.protocol.macro.MacroConfiguration.META_MACRO_ACTION;+import static org.openremote.agent.protocol.macro.MacroProtocol.META_MACRO_ACTION;/*** A desired {@link AttributeState} and a delay in milli seconds before that state@@ -86,9 +86,10 @@ public class MacroAction {}public static Optional<MacroAction> fromValue(Value value) {+ //noinspection ConstantConditionsreturn Values.getObject(value).map(objectValue -> new Pair<>(- AttributeState.fromValue(objectValue.get("attributeState").get()),+ AttributeState.fromValue(objectValue.get("attributeState").orElse(null)),objectValue.getNumber("delay").orElse(0d))).filter(pair -> pair.key.isPresent())diff --git a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroConfiguration.java b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroConfiguration.javaindex a7bfbb8eb..cca26dd65 100644--- a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroConfiguration.java+++ b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroConfiguration.java@@ -19,6 +19,7 @@*/package org.openremote.agent.protocol.macro;+import org.openremote.model.AbstractValueHolder;import org.openremote.model.asset.AssetAttribute;import java.util.Arrays;@@ -29,21 +30,19 @@ import java.util.function.UnaryOperator;import java.util.stream.Collectors;import java.util.stream.Stream;-import static org.openremote.model.Constants.ASSET_META_NAMESPACE;-import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;+import static org.openremote.agent.protocol.macro.MacroProtocol.META_MACRO_ACTION;import static org.openremote.model.asset.agent.ProtocolConfiguration.getProtocolName;import static org.openremote.model.asset.agent.ProtocolConfiguration.initProtocolConfiguration;+import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;/*** Agent attributes can be macro configurations.* <p>- * A macro configuration attribute has {@link MacroConfiguration#META_MACRO_ACTION} items attached to it, each+ * A macro configuration attribute has {@link MacroProtocol#META_MACRO_ACTION} items attached to it, each* item is a sequence of asset state changes to be executed.*/final public class MacroConfiguration {- public static final String META_MACRO_ACTION = ASSET_META_NAMESPACE + ":macroAction";-private MacroConfiguration() {}@@ -108,4 +107,10 @@ final public class MacroConfiguration {return attribute;}++ public static Optional<Integer> getMacroActionIndex(AssetAttribute attribute) {+ return attribute == null ? Optional.empty()+ : attribute.getMetaItem(MacroProtocol.META_MACRO_ACTION_INDEX)+ .flatMap(AbstractValueHolder::getValueAsInteger);+ }}diff --git a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.javaindex ed083ba37..3a893132d 100644--- a/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/macro/MacroProtocol.java@@ -20,48 +20,39 @@package org.openremote.agent.protocol.macro;import org.openremote.agent.protocol.AbstractProtocol;-import org.openremote.model.AbstractValueHolder;import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.AssetMeta;import org.openremote.model.attribute.*;import org.openremote.model.util.Pair;import org.openremote.model.value.Value;import org.openremote.model.value.Values;-import java.util.*;+import java.util.Collections;+import java.util.HashMap;+import java.util.List;+import java.util.Map;import java.util.concurrent.ScheduledFuture;import java.util.logging.Logger;-import static org.openremote.agent.protocol.macro.MacroConfiguration.META_MACRO_ACTION;+import static org.openremote.agent.protocol.macro.MacroConfiguration.getMacroActionIndex;import static org.openremote.agent.protocol.macro.MacroConfiguration.isValidMacroConfiguration;+import static org.openremote.model.Constants.ASSET_META_NAMESPACE;import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;/*** This protocol is responsible for executing macros.* <p>- * It expects a {@link AttributeExecuteStatus} as the attribute event value on the- * processLinkedAttributeWrite. The protocol will then try to perform the requested status on the- * linked macro.+ * It expects a {@link AttributeExecuteStatus} as the attribute event value on the {@link #processLinkedAttributeWrite}.+ * The protocol will then try to perform the request on the linked macro protocol configuration.+ * <p>+ * {@link AssetAttribute}s can also read/write the macro configuration's {@link MacroAction} values by using the+ * {@link #META_MACRO_ACTION_INDEX} Meta Item with the index of the {@link MacroAction} to link to.*/public class MacroProtocol extends AbstractProtocol {private static final Logger LOG = Logger.getLogger(MacroProtocol.class.getName());public static final String PROTOCOL_NAME = PROTOCOL_NAMESPACE + ":macro";-- /**- * Use as value of {@link org.openremote.model.asset.AssetMeta#PROTOCOL_PROPERTY} meta item to- * link an attribute to a macro action's value (allows reading/writing of macro action value).- * <p>- * Use in conjunction with {@link #META_MACRO_ACTION_INDEX} to determine which macro action to- * link to (defaults to 0 if not present).- */- public static final String PROPERTY_MACRO_ACTION = "ACTION";-- /**- * Use in combination with {@link #PROPERTY_MACRO_ACTION} on linked attributes to read/write- * a macro action's value. Value should be of type {@link org.openremote.model.value.ValueType#NUMBER}.- */+ public static final String META_MACRO_ACTION = ASSET_META_NAMESPACE + ":macroAction";public static final String META_MACRO_ACTION_INDEX = PROTOCOL_NAME + ":actionIndex";class MacroExecutionTask {@@ -210,34 +201,36 @@ public class MacroProtocol extends AbstractProtocol {return;}- // Check for protocol property meta- String protocolProperty = attribute- .getMetaItem(AssetMeta.PROTOCOL_PROPERTY)- .flatMap(AbstractValueHolder::getValueAsString)- .orElse("");-- if (protocolProperty.equals(PROPERTY_MACRO_ACTION)) {- // Get the macro action index- int actionIndex = attribute- .getMetaItem(META_MACRO_ACTION_INDEX)- .flatMap(AbstractValueHolder::getValueAsInteger)- .orElse(0);-- List<MacroAction> actions = getMacroActions(macroRef);-- Optional<Value> actionValue = Optional.empty();+ // Check for action index or default to index 0+ int actionIndex = getMacroActionIndex(attribute)+ .orElse(0);++ // Pull the macro action value out with the same type as the linked attribute+ // otherwise push a null value through to the attribute+ List<MacroAction> actions = getMacroActions(macroRef);+ Value actionValue = null;++ if (actions.isEmpty()) {+ LOG.fine("No actions are available for the linked macro, maybe it is disabled?: " + macroRef);+ } else {+ actionIndex = Math.min(actions.size(), Math.max(0, actionIndex));+ actionValue = actions.get(actionIndex).getAttributeState().getCurrentValue().orElse(null);+ LOG.fine("Attribute is linked to the value of macro action index: actionIndex");+ }- if (actions.isEmpty()) {- LOG.fine("No actions are available for the linked macro, maybe it is disabled?: " + macroRef);- } else {- actionIndex = Math.min(actions.size(), Math.max(0, actionIndex));- actionValue = actions.get(actionIndex).getAttributeState().getCurrentValue();- LOG.fine("Attribute is linked to the value of macro action [" + actionIndex + "] current value: " + actionValue.map(Value::toJson).orElse(""));+ if (actionValue != null) {+ // Verify the type of the attribute matches the action value+ if (attribute+ .getType()+ .map(AttributeType::getValueType)+ .orElse(null) != actionValue.getType()) {+ // Use a value of null so it is clear that the attribute isn't linked correctly+ actionValue = null;}-- // Push the value of this macro action into the attribute- updateLinkedAttribute(new AttributeState(attribute.getReferenceOrThrow(), actionValue.orElse(null)));}++ // Push the value of this macro action into the attribute+ updateLinkedAttribute(new AttributeState(attribute.getReferenceOrThrow(), actionValue));}@Override@@ -257,7 +250,6 @@ public class MacroProtocol extends AbstractProtocol {if (attribute.isExecutable()) {// This is a macro execution related write operation- Optional<Value> value = event.getValue();AttributeExecuteStatus status = event.getValue().flatMap(Values::getString).flatMap(AttributeExecuteStatus::fromString)@@ -296,37 +288,25 @@ public class MacroProtocol extends AbstractProtocol {return;}- // Check if this is a write to a macro action value- // Check for protocol property meta- String protocolProperty = attribute- .getMetaItem(AssetMeta.PROTOCOL_PROPERTY)- .flatMap(AbstractValueHolder::getValueAsString)- .orElse("");-- if (protocolProperty.equals(PROPERTY_MACRO_ACTION)) {- // Get the macro action index- int actionIndex = attribute- .getMetaItem(META_MACRO_ACTION_INDEX)- .flatMap(AbstractValueHolder::getValueAsInteger)- .orElse(0);-- // Extract macro actions from protocol configuration rather than modify the in memory ones- List<MacroAction> actions = MacroConfiguration.getMacroActions(protocolConfiguration);-- if (actions.isEmpty()) {- LOG.fine("No actions are available for the linked macro, maybe it is disabled?: " + protocolConfiguration.getReferenceOrThrow());- } else {- actionIndex = Math.min(actions.size(), Math.max(0, actionIndex));- LOG.fine("Updating macro action [" + actionIndex + "] value to: " + event.getValue().map(Value::toJson).orElse(""));- MacroAction action = actions.get(actionIndex);- action.setAttributeState(new AttributeState(action.getAttributeState().getAttributeRef(), event.getValue().orElse(null)));- MetaItem[] actionMeta = actions- .stream()- .map(MacroAction::toMetaItem)- .toArray(MetaItem[]::new);-- updateLinkedProtocolConfiguration(protocolConfiguration, META_MACRO_ACTION, actionMeta);- }+ // Assume this is a write to a macro action value (default to index 0)+ int actionIndex = getMacroActionIndex(attribute).orElse(0);++ // Extract macro actions from protocol configuration rather than modify the in memory ones+ List<MacroAction> actions = MacroConfiguration.getMacroActions(protocolConfiguration);++ if (actions.isEmpty()) {+ LOG.fine("No actions are available for the linked macro, maybe it is disabled?: " + protocolConfiguration.getReferenceOrThrow());+ } else {+ actionIndex = Math.min(actions.size(), Math.max(0, actionIndex));+ LOG.fine("Updating macro action [" + actionIndex + "] value to: " + event.getValue().map(Value::toJson).orElse(""));+ MacroAction action = actions.get(actionIndex);+ action.setAttributeState(new AttributeState(action.getAttributeState().getAttributeRef(), event.getValue().orElse(null)));+ MetaItem[] actionMeta = actions+ .stream()+ .map(MacroAction::toMetaItem)+ .toArray(MetaItem[]::new);++ updateLinkedProtocolConfiguration(protocolConfiguration, META_MACRO_ACTION, actionMeta);}}diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/time/CronExpressionParser.java b/agent/src/main/java/org/openremote/agent/protocol/timer/CronExpressionParser.javasimilarity index 99%rename from agent/src/main/java/org/openremote/agent/protocol/trigger/time/CronExpressionParser.javarename to agent/src/main/java/org/openremote/agent/protocol/timer/CronExpressionParser.javaindex 093f6068c..cf1e1a370 100644--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/time/CronExpressionParser.java+++ b/agent/src/main/java/org/openremote/agent/protocol/timer/CronExpressionParser.java@@ -17,7 +17,7 @@* You should have received a copy of the GNU Affero General Public License* along with this program. If not, see <http://www.gnu.org/licenses/>.*/-package org.openremote.agent.protocol.trigger.time;+package org.openremote.agent.protocol.timer;import org.openremote.model.syslog.SyslogCategory;import org.quartz.CronExpression;diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/time/CronJob.java b/agent/src/main/java/org/openremote/agent/protocol/timer/CronJob.javasimilarity index 96%rename from agent/src/main/java/org/openremote/agent/protocol/trigger/time/CronJob.javarename to agent/src/main/java/org/openremote/agent/protocol/timer/CronJob.javaindex ef97f7af4..5135fb85d 100644--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/time/CronJob.java+++ b/agent/src/main/java/org/openremote/agent/protocol/timer/CronJob.java@@ -17,7 +17,7 @@* You should have received a copy of the GNU Affero General Public License* along with this program. If not, see <http://www.gnu.org/licenses/>.*/-package org.openremote.agent.protocol.trigger.time;+package org.openremote.agent.protocol.timer;import org.quartz.Job;import org.quartz.JobExecutionContext;diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/time/CronScheduler.java b/agent/src/main/java/org/openremote/agent/protocol/timer/CronScheduler.javasimilarity index 98%rename from agent/src/main/java/org/openremote/agent/protocol/trigger/time/CronScheduler.javarename to agent/src/main/java/org/openremote/agent/protocol/timer/CronScheduler.javaindex a716bf503..8a9a361d3 100644--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/time/CronScheduler.java+++ b/agent/src/main/java/org/openremote/agent/protocol/timer/CronScheduler.java@@ -17,7 +17,7 @@* You should have received a copy of the GNU Affero General Public License* along with this program. If not, see <http://www.gnu.org/licenses/>.*/-package org.openremote.agent.protocol.trigger.time;+package org.openremote.agent.protocol.timer;import org.openremote.model.syslog.SyslogCategory;import org.openremote.model.util.Pair;diff --git a/agent/src/main/java/org/openremote/agent/protocol/timer/TimerConfiguration.java b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerConfiguration.javanew file mode 100644index 000000000..5f490747b--- /dev/null+++ b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerConfiguration.java@@ -0,0 +1,134 @@+/*+ * Copyright 2017, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.agent.protocol.timer;++import org.openremote.model.AbstractValueHolder;+import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.attribute.AttributeState;+import org.openremote.model.value.Values;++import java.util.Optional;++import static org.openremote.agent.protocol.timer.TimerProtocol.*;+import static org.openremote.model.asset.agent.ProtocolConfiguration.getProtocolName;+import static org.openremote.model.asset.agent.ProtocolConfiguration.initProtocolConfiguration;+import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;+import static org.openremote.model.attribute.MetaItem.replaceMetaByName;+import static org.openremote.model.util.TextUtil.isNullOrEmpty;++/**+ * Utility functions for working with timer configuration attributes for the {@link TimerProtocol}+ */+final public class TimerConfiguration {++ private TimerConfiguration() {+ }++ public static AssetAttribute initTimerConfiguration(AssetAttribute attribute, String cronExpression, AttributeState action) {+ initProtocolConfiguration(attribute, TimerProtocol.PROTOCOL_NAME);+ setCronExpression(attribute, cronExpression);+ setAction(attribute, action);+ return attribute;+ }++ public static boolean isTimerConfiguration(AssetAttribute attribute) {+ return getProtocolName(attribute)+ .map(TimerProtocol.PROTOCOL_NAME::equals)+ .orElse(false);+ }++ public static boolean isValidTimerConfiguration(AssetAttribute attribute) {+ return isTimerConfiguration(attribute)+ && isActionValid(attribute)+ && isCronExpressionValid(attribute);+ }++ public static boolean hasCronExpression(AssetAttribute attribute) {+ return attribute != null && attribute.hasMetaItem(META_TIMER_CRON_EXPRESSION);+ }++ public static boolean isCronExpressionValid(AssetAttribute attribute) {+ return attribute != null && attribute+ .getMetaItem(META_TIMER_CRON_EXPRESSION)+ .flatMap(AbstractValueHolder::getValueAsString)+ .map(TimerConfiguration::isCronExpressionValid)+ .orElse(false);+ }++ public static boolean isCronExpressionValid(String cronExpression) {+ return !isNullOrEmpty(cronExpression) && createCronExpression(cronExpression) != null;+ }++ public static Optional<String> getCronExpression(AssetAttribute attribute) {+ return attribute == null ? Optional.empty() : attribute+ .getMetaItem(META_TIMER_CRON_EXPRESSION)+ .flatMap(AbstractValueHolder::getValueAsString);+ }++ public static void setCronExpression(AssetAttribute attribute, String cronExpression) {+ if (attribute == null)+ return;++ replaceMetaByName(attribute.getMeta(), META_TIMER_CRON_EXPRESSION, Values.create(cronExpression));+ }++ public static boolean hasAction(AssetAttribute attribute) {+ return attribute != null && attribute.hasMetaItem(META_TIMER_ACTION);+ }++ public static boolean isActionValid(AssetAttribute attribute) {+ return attribute != null && attribute.getMetaItem(META_TIMER_ACTION)+ .flatMap(AbstractValueHolder::getValue)+ .map(AttributeState::isAttributeState)+ .orElse(false);+ }++ public static Optional<AttributeState> getAction(AssetAttribute attribute) {+ return attribute == null ? Optional.empty() : attribute+ .getMetaItem(META_TIMER_ACTION)+ .flatMap(AbstractValueHolder::getValueAsObject)+ .flatMap(AttributeState::fromValue);+ }++ public static void setAction(AssetAttribute attribute, AttributeState action) {+ if (attribute == null)+ return;+ replaceMetaByName(attribute.getMeta(), META_TIMER_ACTION, action.toObjectValue());+ }++ public static void removeTimer(AssetAttribute attribute) {+ if (attribute == null)+ return;++ attribute+ .getMeta()+ .removeIf(+ isMetaNameEqualTo(META_TIMER_ACTION)+ .or(isMetaNameEqualTo(META_TIMER_CRON_EXPRESSION))+ );+ }++ public static Optional<TimerValue> getValue(AssetAttribute attribute) {+ return attribute == null ? Optional.empty() : attribute+ .getMetaItem(META_TIMER_VALUE_LINK)+ .flatMap(AbstractValueHolder::getValueAsString)+ .map(TimerValue::fromString);+ }+}diff --git a/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.javanew file mode 100644index 000000000..57b01601b--- /dev/null+++ b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java@@ -0,0 +1,290 @@+/*+ * Copyright 2017, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.agent.protocol.timer;++import org.openremote.agent.protocol.AbstractProtocol;+import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.asset.AssetMeta;+import org.openremote.model.attribute.AttributeEvent;+import org.openremote.model.attribute.AttributeRef;+import org.openremote.model.attribute.AttributeState;+import org.openremote.model.attribute.MetaItem;+import org.openremote.model.util.TextUtil;+import org.openremote.model.value.Value;+import org.openremote.model.value.Values;+import org.quartz.CronExpression;++import javax.ws.rs.NotSupportedException;+import java.text.ParseException;+import java.util.HashMap;+import java.util.Map;+import java.util.Optional;+import java.util.logging.Logger;++import static java.util.logging.Level.FINER;+import static org.openremote.agent.protocol.timer.TimerConfiguration.*;+import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;++/**+ * This protocol can be used to trigger an {@link AttributeEvent} using a cron based timer.+ * <p>+ * A timer is defined by creating a {@link TimerConfiguration} attribute on an agent. A timer configuration consists of+ * the following Meta Items:+ * <ul>+ * <li>{@link #META_TIMER_CRON_EXPRESSION}: The cron expression of the timer</li>+ * <li>{@link #META_TIMER_ACTION}: The {@link AttributeState} that should be sent when the timer is triggered</li>+ * </ul>+ * <p>+ * {@link AssetAttribute}s can be linked to time triggers to read/write the trigger time and/or enable/disable the+ * trigger. A linked attribute must have a valid {@link AssetMeta#AGENT_LINK} Meta Item and+ * also a {@link #META_TIMER_VALUE_LINK} Meta Item to indicate what value of timer to link to {@link TimerValue}+ */+public class TimerProtocol extends AbstractProtocol {++ private static final Logger LOG = Logger.getLogger(TimerProtocol.class.getName());++ public static final String PROTOCOL_NAME = PROTOCOL_NAMESPACE + ":timer";+ public static final String META_TIMER_CRON_EXPRESSION = PROTOCOL_NAMESPACE + ":cronExpression";+ public static final String META_TIMER_ACTION = PROTOCOL_NAMESPACE + ":action";+ public static final String META_TIMER_VALUE_LINK = PROTOCOL_NAMESPACE + ":link";+ protected final Map<AttributeRef, CronExpressionParser> cronExpressionMap = new HashMap<>();+ protected CronScheduler cronScheduler;++ @Override+ public String getProtocolName() {+ return PROTOCOL_NAME;+ }++ @Override+ protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {+ AttributeRef protocolRef = protocolConfiguration.getReferenceOrThrow();++ // Verify that this is a valid Timer Configuration+ if (!isValidTimerConfiguration(protocolConfiguration)) {+ LOG.warning("Timer Configuration is not valid so it will be ignored: " + protocolRef);+ updateDeploymentStatus(protocolRef, DeploymentStatus.ERROR);+ return;+ }++ // Validate the cron expression+ CronExpressionParser expressionParser = getCronExpression(protocolConfiguration)+ .map(CronExpressionParser::new)+ .orElse(null);++ if (expressionParser == null || !expressionParser.isValid()) {+ LOG.warning("Timer cron expression is missing or invalid");+ updateDeploymentStatus(protocolRef, DeploymentStatus.ERROR);+ return;+ }++ synchronized (cronExpressionMap) {+ cronExpressionMap.put(protocolRef, expressionParser);+ }++ if (protocolConfiguration.isEnabled()) {+ CronExpression cronExpression = createCronExpression(expressionParser.buildCronExpression());+ if (cronExpression != null) {+ getCronScheduler()+ .addOrReplaceJob(+ getTimerId(protocolRef),+ cronExpression,+ () -> doTriggerAction(protocolConfiguration)+ );+ }+ }+ }++ @Override+ protected void doUnlinkProtocolConfiguration(AssetAttribute protocolConfiguration) {+ AttributeRef protocolConfigRef = protocolConfiguration.getReferenceOrThrow();++ synchronized (cronExpressionMap) {+ if (cronExpressionMap.remove(protocolConfigRef) != null) {+ getCronScheduler().removeJob(getTimerId(protocolConfigRef));+ }+ }+ }++ @Override+ protected void processLinkedAttributeWrite(AttributeEvent event, AssetAttribute protocolConfiguration) {+ AssetAttribute attribute = getLinkedAttribute(event.getAttributeRef());++ TimerValue timerValue = TimerConfiguration.getValue(attribute).orElse(null);++ if (timerValue == null) {+ LOG.warning("Attribute doesn't have a valid timer value so ignoring write request: " + attribute.getReferenceOrThrow());+ return;+ }++ // Don't remove or alter any running timer just push update back through the system and wait for link/unlink+ // protocol configuration method call+ Optional<String> writeValue = event.+ getValue()+ .flatMap(Values::getString)+ .flatMap(TextUtil::asNonNullAndNonEmpty);++ if (!writeValue.isPresent()) {+ LOG.warning("Send to actuator value for time trigger must be a non empty string");+ return;+ }++ String value = writeValue.get().trim();++ switch (timerValue) {+ case ENABLED:+ // check event value is a boolean+ boolean enabled = Values.getBoolean(event.getValue()+ .orElse(null))+ .orElseThrow(() -> new IllegalStateException("Writing to protocol configuration ENABLED property requires a boolean value"));++ if (enabled == protocolConfiguration.isEnabled()) {+ LOG.finer("Protocol configuration enabled status is already: " + enabled);+ } else {+ LOG.fine("Updating protocol configuration enabled status");+ updateLinkedProtocolConfiguration(protocolConfiguration, AssetMeta.ENABLED, new MetaItem(AssetMeta.ENABLED, Values.create(enabled)));+ }+ break;+ case CRON_EXPRESSION:+ // Allow writing invalid cron expressions; mean that the trigger will stop working+ // but that is handled gracefully+ updateTimerValue(new AttributeState(protocolConfiguration.getReferenceOrThrow(), Values.create(value)));+ break;+ case TIME:+ CronExpressionParser parser = getCronExpressionParser(protocolConfiguration.getReferenceOrThrow());+ if (parser == null) {+ LOG.info("Ignoring trigger update because current cron expression is invalid");+ return;+ }++ String[] writeTimeValues = value.split(":");+ Integer hours;+ Integer minutes;+ Integer seconds;++ if (writeTimeValues.length != 3+ || (hours = CronExpressionParser.parseNumberExpression(writeTimeValues[0])) == null+ || (minutes = CronExpressionParser.parseNumberExpression(writeTimeValues[1])) == null+ || (seconds = CronExpressionParser.parseNumberExpression(writeTimeValues[2])) == null) {+ LOG.info("Expected value to be in format HH:MM:SS, actual: " + writeValue);+ return;+ }++ parser.setTime(hours, minutes, seconds);+ updateTimerValue(new AttributeState(protocolConfiguration.getReferenceOrThrow(), Values.create(parser.buildCronExpression())));+ break;+ default:+ throw new NotSupportedException("Unsupported trigger property");+ }+ }++ @Override+ protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {+ TimerValue timerValue = TimerConfiguration.getValue(attribute).orElse(null);++ if (timerValue == null) {+ LOG.warning("Attribute doesn't have a valid timer value: " + attribute.getReferenceOrThrow());+ return;+ }++ LOG.fine("Attribute is linked to timer value: " + timerValue);++ switch (timerValue) {+ case ENABLED:+ updateLinkedAttribute(new AttributeState(attribute.getReferenceOrThrow(), Values.create(protocolConfiguration.isEnabled())));+ break;+ case CRON_EXPRESSION:+ case TIME:+ CronExpressionParser parser = getCronExpressionParser(protocolConfiguration.getReferenceOrThrow());+ if (parser == null) {+ LOG.info("Attribute is linked to an invalid timer so it will be ignored");+ return;+ }++ Value value = timerValue == TimerValue.CRON_EXPRESSION+ ? Values.create(parser.buildCronExpression())+ : Values.create(parser.getFormattedTime());++ updateLinkedAttribute(new AttributeState(attribute.getReferenceOrThrow(), value));+ break;+ }+ }++ @Override+ protected void doUnlinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {+ // Nothing to do here+ }++ /**+ * Sends the trigger's attribute state into the processing chain+ */+ protected void doTriggerAction(AssetAttribute triggerConfiguration) {+ if (triggerConfiguration == null) {+ LOG.fine("Cannot execute timer action as timer configuration cannot be found");+ return;+ }++ LOG.fine("Executing timer action: " + triggerConfiguration.getReferenceOrThrow());+ getAction(triggerConfiguration)+ .ifPresent(this::sendAttributeEvent);+ }++ /**+ * Update the trigger's {@link #META_TIMER_CRON_EXPRESSION}+ */+ protected void updateTimerValue(AttributeState state) {+ LOG.fine("Updating the timer value: " + state);++ updateLinkedProtocolConfiguration(+ getLinkedProtocolConfiguration(state.getAttributeRef()),+ META_TIMER_CRON_EXPRESSION,+ new MetaItem(META_TIMER_CRON_EXPRESSION, state.getCurrentValue().orElse(null))+ );+ }++ protected CronScheduler getCronScheduler() {+ if (cronScheduler == null) {+ LOG.fine("Create cron scheduler");+ cronScheduler = new CronScheduler();+ }++ return cronScheduler;+ }++ protected CronExpressionParser getCronExpressionParser(AttributeRef timerRef) {+ synchronized (cronExpressionMap) {+ return cronExpressionMap.get(timerRef);+ }+ }++ protected static String getTimerId(AttributeRef timerRef) {+ return timerRef.getEntityId() + ":" + timerRef.getAttributeName();+ }++ protected static CronExpression createCronExpression(String expression) {+ CronExpression cronExpression = null;+ try {+ cronExpression = new CronExpression(expression);+ } catch (ParseException e) {+ LOG.log(FINER, "Failed to create cron expression from string: " + expression, e);+ }++ return cronExpression;+ }+}diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/time/TimeTriggerProperty.java b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerValue.javasimilarity index 67%rename from agent/src/main/java/org/openremote/agent/protocol/trigger/time/TimeTriggerProperty.javarename to agent/src/main/java/org/openremote/agent/protocol/timer/TimerValue.javaindex e4b81bb0f..e528e13ca 100644--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/time/TimeTriggerProperty.java+++ b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerValue.java@@ -17,11 +17,16 @@* You should have received a copy of the GNU Affero General Public License* along with this program. If not, see <http://www.gnu.org/licenses/>.*/-package org.openremote.agent.protocol.trigger.time;+package org.openremote.agent.protocol.timer;import java.util.Locale;-public enum TimeTriggerProperty {+public enum TimerValue {++ /**+ * Links an attribute to the enabled status of a timer for read/write+ */+ ENABLED,/*** Links the entire cron expression to an attribute for read/write@@ -30,22 +35,17 @@ public enum TimeTriggerProperty {/*** Links the time of the cron expression to an attribute for read/write- * (read works for simple hour, min and second cron expressions- * e.g. 0 35 15 ? * *) once a write is performed to a non simple cron- * expression then it becomes simple.+ * <p>+ * Read works for simple hour, min and second cron expressions (e.g. 0 35 15 ? * *) once a write is performed to a+ * non simple cron expression then it becomes simple.** 24h time format*/TIME;-// /**-// * Links the Day of week of the cron expression to an attribute for-// * read/write (only works for single day of week cron expressions)-// */-// //TODO: Could pull multiple days as a JsonArray-// DAY_OF_WEEK+ // TODO: Add support for other links (e.g. DAY_OF_WEEK)- public static TimeTriggerProperty fromString(String value) {+ public static TimerValue fromString(String value) {return value == null ? null : valueOf(value.toUpperCase(Locale.ROOT));}}diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/AbstractTriggerHandler.java b/agent/src/main/java/org/openremote/agent/protocol/trigger/AbstractTriggerHandler.javadeleted file mode 100644index cf3268593..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/AbstractTriggerHandler.java+++ /dev/null@@ -1,102 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.trigger;--import org.openremote.agent.protocol.AbstractProtocol;-import org.openremote.container.Container;-import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.attribute.AttributeEvent;-import org.openremote.model.attribute.AttributeRef;-import org.openremote.model.attribute.AttributeState;-import org.openremote.model.value.Value;--public abstract class AbstractTriggerHandler {-- protected static TriggerProtocol protocol;-- protected abstract String getName();-- protected abstract boolean isValidValue(Value triggerValue);-- protected abstract void registerTrigger(AttributeRef triggerRef, Value value, boolean isEnabled);-- protected abstract void unregisterTrigger(AttributeRef triggerRef);-- /**- * The {@link AbstractTriggerHandler} implementation should override this method- * to handle the request based on the propertyName and the {@link AttributeEvent}.- *- * The propertyName should relate to a request to read that property from the trigger- * handler and the trigger handler is responsible for pushing updates to the attribute- * by calling {@link #updateAttributeValue(AttributeState)}- *- */- protected abstract void registerAttribute(AttributeRef attributeRef, AttributeRef triggerRef, String propertyName);-- protected abstract void unregisterAttribute(AttributeRef attributeRef, AttributeRef triggerRef);-- /**- * A {@link AbstractProtocol#processLinkedAttributeWrite(AttributeEvent, AssetAttribute)} has occurred on the protocol.- *- * The {@link AbstractTriggerHandler} implementation should override this method- * to handle the request based on the propertyName and the {@link AttributeEvent}.- *- * If the handler wishes to alter the trigger's value as a result of the request- * (e.g. request was to adjust the time of a TimeTrigger) then the handler- * should call {@link #updateTriggerValue(AttributeState)} with the new desired value.- */- protected abstract void processAttributeWrite(AssetAttribute attribute, AssetAttribute protocolConfiguration, String propertyName, AttributeEvent event);-- /**- * Called by the protocol init- */- protected void init(Container container) throws Exception {}-- /**- * Called by the protocol start- */- protected void start(Container container) throws Exception {}-- /**- * Called by the protocol stop- */- protected void stop(Container container) throws Exception {}-- /**- * Allows trigger handlers to update a trigger's value- */- protected void updateTriggerValue(AttributeState triggerRefAndValue) {- protocol.updateTriggerValue(triggerRefAndValue);- }-- /**- * Allows trigger handlers to update the value of linked attributes- */- protected void updateAttributeValue(AttributeState attributeState) {- protocol.updateAttribute(attributeState);- }-- /**- * Allows trigger handlers to request execution of the trigger action- */- protected void executeTrigger(AttributeRef triggerRef) {- protocol.doTriggerAction(triggerRef);- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerConfiguration.java b/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerConfiguration.javadeleted file mode 100644index e0336d7a3..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerConfiguration.java+++ /dev/null@@ -1,171 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.trigger;--import org.openremote.model.AbstractValueHolder;-import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.asset.AssetMeta;-import org.openremote.model.attribute.AttributeState;-import org.openremote.model.value.Value;-import org.openremote.model.value.Values;--import java.util.Optional;-import java.util.function.Function;--import static org.openremote.agent.protocol.trigger.TriggerProtocol.*;-import static org.openremote.agent.protocol.trigger.TriggerType.toValue;-import static org.openremote.model.asset.agent.ProtocolConfiguration.getProtocolName;-import static org.openremote.model.attribute.AttributeType.STRING;-import static org.openremote.model.attribute.MetaItem.isMetaNameEqualTo;-import static org.openremote.model.attribute.MetaItem.replaceMetaByName;--/**- * Utility functions for working with trigger attributes for the {@link TriggerProtocol}- */-final public class TriggerConfiguration {-- private TriggerConfiguration() {- }-- public static Function<AssetAttribute, AssetAttribute> initTriggerConfiguration() {- return attribute -> {- attribute.setTypeAndClearValue(STRING);- attribute.setValue(Values.create(TriggerProtocol.PROTOCOL_NAME));- return attribute;- };- }-- public static boolean isTriggerConfiguration(AssetAttribute attribute) {- return getProtocolName(attribute)- .map(TriggerProtocol.PROTOCOL_NAME::equals)- .orElse(false);- }-- public static boolean isValidTriggerConfiguration(AssetAttribute attribute) {- return isTriggerConfiguration(attribute)- && isTriggerActionValid(attribute)- && isTriggerTypeAndValueValid(attribute);- }-- public static boolean hasTriggerType(AssetAttribute attribute) {- return attribute != null && attribute- .getMetaStream()- .anyMatch(isMetaNameEqualTo(META_TRIGGER_TYPE));- }-- public static boolean isTriggerTypeValid(AssetAttribute attribute) {- return getTriggerType(attribute).isPresent();- }-- public static Optional<TriggerType> getTriggerType(AssetAttribute attribute) {- return attribute == null ? Optional.empty() : attribute- .getMetaItem(META_TRIGGER_TYPE)- .flatMap(AbstractValueHolder::getValueAsString)- .flatMap(TriggerType::fromString);- }-- public static void setTriggerType(AssetAttribute attribute, TriggerType triggerType) {- if (attribute == null)- return;-- replaceMetaByName(attribute.getMeta(), META_TRIGGER_TYPE, toValue(triggerType));- }-- public static Optional<AbstractTriggerHandler> getTriggerTypeHandler(AssetAttribute attribute) {- return getTriggerType(attribute)- .map(TriggerType::getHandler);- }-- public static boolean hasTriggerValue(AssetAttribute attribute) {- return attribute != null && attribute.hasMetaItem(META_TRIGGER_VALUE);- }-- public static boolean isTriggerTypeAndValueValid(AssetAttribute attribute) {- Optional<Value> triggerValue = getTriggerValue(attribute);- Optional<AbstractTriggerHandler> handler = getTriggerTypeHandler(attribute);- return triggerValue.isPresent() && handler- .map(h ->- isTriggerValueValid(h,- triggerValue.get()- )- )- .orElse(false);- }-- public static boolean isTriggerValueValid(AbstractTriggerHandler handler, Value value) {- return handler != null && value != null && handler.isValidValue(value);- }-- public static Optional<Value> getTriggerValue(AssetAttribute attribute) {- return attribute == null ? Optional.empty() : attribute- .getMetaItem(META_TRIGGER_VALUE)- .flatMap(AbstractValueHolder::getValue);- }-- public static void setTriggerValue(AssetAttribute attribute, Value value) {- if (attribute == null)- return;-- replaceMetaByName(attribute.getMeta(), META_TRIGGER_VALUE, value);- }-- public static boolean hasTriggerAction(AssetAttribute attribute) {- return attribute != null && attribute.hasMetaItem(META_TRIGGER_ACTION);- }-- public static boolean isTriggerActionValid(AssetAttribute attribute) {- return attribute != null && attribute.getMetaItem(META_TRIGGER_ACTION)- .flatMap(AbstractValueHolder::getValue)- .map(AttributeState::isAttributeState)- .orElse(false);- }-- public static Optional<AttributeState> getTriggerAction(AssetAttribute attribute) {- return attribute == null ? Optional.empty() : attribute- .getMetaItem(META_TRIGGER_ACTION)- .flatMap(AbstractValueHolder::getValueAsObject)- .flatMap(AttributeState::fromValue);- }-- public static void setTriggerAction(AssetAttribute attribute, AttributeState action) {- if (attribute == null)- return;- replaceMetaByName(attribute.getMeta(), META_TRIGGER_ACTION, action.toObjectValue());- }-- public static void removeTrigger(AssetAttribute attribute) {- if (attribute == null)- return;-- attribute- .getMeta()- .removeIf(- isMetaNameEqualTo(META_TRIGGER_TYPE)- .or(isMetaNameEqualTo(META_TRIGGER_VALUE))- .or(isMetaNameEqualTo(META_TRIGGER_ACTION))- );- }-- public static Optional<String> getTriggerProperty(AssetAttribute attribute) {- return attribute == null ? Optional.empty() : attribute- .getMetaItem(AssetMeta.PROTOCOL_PROPERTY)- .flatMap(AbstractValueHolder::getValueAsString);- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerHandlerProducer.java b/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerHandlerProducer.javadeleted file mode 100644index 6442701c0..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerHandlerProducer.java+++ /dev/null@@ -1,24 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.trigger;--public interface TriggerHandlerProducer {- AbstractTriggerHandler getHandler();-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerProtocol.javadeleted file mode 100644index aa65917d6..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerProtocol.java+++ /dev/null@@ -1,254 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.trigger;--import org.openremote.agent.protocol.AbstractProtocol;-import org.openremote.container.Container;-import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.attribute.AttributeEvent;-import org.openremote.model.attribute.AttributeRef;-import org.openremote.model.attribute.AttributeState;-import org.openremote.model.attribute.MetaItem;-import org.openremote.model.value.Value;--import java.util.HashMap;-import java.util.Map;-import java.util.Optional;-import java.util.logging.Logger;--import static org.openremote.agent.protocol.trigger.TriggerConfiguration.*;-import static org.openremote.model.Constants.ASSET_META_NAMESPACE;-import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;--/**- * This protocol can be used to trigger {@link AttributeEvent} using a trigger type:- * <p>- * A trigger is defined by creating a {@link TriggerConfiguration} attribute on an- * agent. A trigger consists of:- * <ul>- * <li>{@link TriggerType}</li>- * <li>Trigger Value: {@link TriggerType#TIME} = CRON EXPRESSION or {@link TriggerType#ATTRIBUTE} = {@link AttributeRef}</li>- * <li>Trigger Action {@link AttributeState} that should be sent when triggered</li>- * </ul>- * {@link AssetAttribute}s can link to time triggers to read/write the trigger time and/or enable/disable- * the trigger.- * <p>- * The {@link org.openremote.model.asset.AssetMeta#PROTOCOL_PROPERTY} meta should be used on linked attributes to- * indicate what property of the trigger the attribute should read/write. The content of the meta should be a string- * that is specific to the trigger type handler. The only globally recognised value is "ENABLED"- * which reads/writes the trigger's {@link org.openremote.model.asset.AssetMeta#ENABLED} meta item and is handled by- * the {@link AbstractProtocol} super class.- */-public class TriggerProtocol extends AbstractProtocol {-- private static final Logger LOG = Logger.getLogger(TriggerProtocol.class.getName());-- public static final String PROTOCOL_NAME = PROTOCOL_NAMESPACE + ":trigger";- public static final String META_TRIGGER_VALUE = ASSET_META_NAMESPACE + ":triggerValue";- public static final String META_TRIGGER_TYPE = ASSET_META_NAMESPACE + ":triggerType";- public static final String META_TRIGGER_ACTION = ASSET_META_NAMESPACE + ":triggerAction";- protected final Map<AttributeRef, AssetAttribute> protocolConfigMap = new HashMap<>();- protected final Map<AttributeRef, AbstractTriggerHandler> attributeTriggerHandlerMap = new HashMap<>();-- @Override- public String getProtocolName() {- return PROTOCOL_NAME;- }-- @Override- public void start(Container container) throws Exception {- super.start(container);-- for (TriggerType triggerType : TriggerType.values()) {- AbstractTriggerHandler handler = triggerType.getHandler();- LOG.info("Starting trigger handler: " + handler.getName());- handler.start(container);- }- }-- @Override- public void stop(Container container) throws Exception {- for (TriggerType triggerType : TriggerType.values()) {- AbstractTriggerHandler handler = triggerType.getHandler();- LOG.info("Stopping trigger handler: " + handler.getName());- handler.stop(container);- }-- super.stop(container);- }-- @Override- public void init(Container container) throws Exception {- super.init(container);-- // Push static protocol reference so trigger handlers can call doTriggerAction- AbstractTriggerHandler.protocol = this;-- for (TriggerType triggerType : TriggerType.values()) {- AbstractTriggerHandler handler = triggerType.getHandler();- LOG.info("Initialising trigger handler: " + handler.getName());- handler.init(container);- }- }-- @Override- protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {- // The protocol configuration is actually a Trigger Configuration- AssetAttribute initialisedProtocolConfiguration;-- synchronized (protocolConfigMap) {- initialisedProtocolConfiguration = protocolConfigMap.computeIfAbsent(protocolConfiguration.getReferenceOrThrow(), protocolConfigRef ->- {- // Verify that this is a valid Trigger Configuration- if (!isValidTriggerConfiguration(protocolConfiguration)) {- LOG.warning("Trigger Configuration is not valid so it will be ignored: " + protocolConfigRef);- updateDeploymentStatus(protocolConfigRef, DeploymentStatus.ERROR);- return null;- }-- // Register the trigger with its handler- TriggerType type = getTriggerType(protocolConfiguration).get();- AbstractTriggerHandler handler = getTriggerTypeHandler(protocolConfiguration).get();- Value value = getTriggerValue(protocolConfiguration).get();- handler.registerTrigger(protocolConfigRef, value, protocolConfiguration.isEnabled());- updateDeploymentStatus(protocolConfigRef, protocolConfiguration.isEnabled() ? DeploymentStatus.LINKED_ENABLED : DeploymentStatus.LINKED_DISABLED);-- return protocolConfiguration;- });- }- }-- @Override- protected void doUnlinkProtocolConfiguration(AssetAttribute protocolConfiguration) {- synchronized (protocolConfigMap) {- AttributeRef protocolConfigRef = protocolConfiguration.getReferenceOrThrow();-- if (protocolConfigMap.remove(protocolConfigRef) != null) {- // Unregister the trigger from its handler- TriggerType type = getTriggerType(protocolConfiguration).get();- AbstractTriggerHandler handler = getTriggerTypeHandler(protocolConfiguration).get();- handler.unregisterTrigger(protocolConfigRef);- }- }- }-- @Override- protected void processLinkedAttributeWrite(AttributeEvent event, AssetAttribute protocolConfiguration) {- LOG.fine("Request to send to actuator");-- // Send to actuator means that the trigger wants to be updated- // if the attributes' META_TRIGGER_PROPERTY value is TRIGGER_PROPERTY_ENABLED- // then handle the request here, otherwise delegate to the trigger handler- AssetAttribute attribute = getLinkedAttribute(event.getAttributeRef());-- TriggerConfiguration.getTriggerProperty(attribute)- .ifPresent(propertyName -> {- synchronized (attributeTriggerHandlerMap) {- AbstractTriggerHandler handler = attributeTriggerHandlerMap.get(event.getAttributeRef());- if (handler != null) {- LOG.info("Passing attribute write request to trigger handler '" + handler.getName() + "'");- handler.processAttributeWrite(attribute, protocolConfiguration, propertyName, event);- }- }- });- }-- @Override- protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {- // Wire up the attribute- TriggerConfiguration.getTriggerTypeHandler(protocolConfiguration)- .ifPresent(handler -> registerAttributeWithTriggerHandler(attribute, protocolConfiguration, handler));- }-- @Override- protected void doUnlinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {- AbstractTriggerHandler oldHandler;- AttributeRef attributeRef = attribute.getReferenceOrThrow();-- synchronized (attributeTriggerHandlerMap) {- oldHandler = attributeTriggerHandlerMap.get(attributeRef);-- if (oldHandler != null) {- unRegisterAttributeWithTriggerHandler(attributeRef, protocolConfiguration.getReferenceOrThrow(), oldHandler);- }- }- }-- protected void registerAttributeWithTriggerHandler(AssetAttribute attribute, AssetAttribute triggerConfiguration, AbstractTriggerHandler handler) {- LOG.fine("Request to register attribute with trigger handler");-- TriggerConfiguration.getTriggerProperty(attribute)- .ifPresent(propertyName -> {- AttributeRef attributeRef = attribute.getReferenceOrThrow();- LOG.info("Registering attribute '" + attributeRef + "' on trigger handler '" + handler.getName() + "'");- synchronized (attributeTriggerHandlerMap) {- attributeTriggerHandlerMap.put(attribute.getReferenceOrThrow(), handler);- }- handler.registerAttribute(attributeRef, triggerConfiguration.getReferenceOrThrow(), propertyName);- });- }-- protected void unRegisterAttributeWithTriggerHandler(AttributeRef attributeRef, AttributeRef triggerRef, AbstractTriggerHandler handler) {- LOG.fine("Request to unregister attribute with trigger handler");-- // Check if attribute is linked to a trigger handler- synchronized (attributeTriggerHandlerMap) {- if (attributeTriggerHandlerMap.remove(attributeRef) != null) {- LOG.info("Un-registering attribute '" + attributeRef + "' on trigger handler '" + handler.getName() + "'");- handler.unregisterAttribute(attributeRef, triggerRef);- }- }- }-- /**- * Updates the value of an attribute linked to a trigger handler- */- void updateAttribute(AttributeState state) {- updateLinkedAttribute(state);- }-- /**- * Sends the trigger's attribute state into the processing chain- */- void doTriggerAction(AttributeRef triggerRef) {- LOG.info("Trigger handler requested trigger action to be executed");-- synchronized (protocolConfigMap) {- Optional.ofNullable(protocolConfigMap.get(triggerRef))- .ifPresent(triggerConfiguration ->- getTriggerAction(triggerConfiguration)- .ifPresent(this::sendAttributeEvent)- );- }- }-- /**- * Update the trigger's {@link #META_TRIGGER_VALUE}- */- void updateTriggerValue(AttributeState state) {- LOG.fine("Updating the trigger value: " + state);-- updateLinkedProtocolConfiguration(- getLinkedProtocolConfiguration(state.getAttributeRef()),- META_TRIGGER_VALUE,- new MetaItem(META_TRIGGER_VALUE, state.getCurrentValue().orElse(null))- );- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerType.java b/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerType.javadeleted file mode 100644index 7db8d00af..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/TriggerType.java+++ /dev/null@@ -1,76 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.trigger;--import org.openremote.agent.protocol.trigger.attribute.AttributeTriggerHandler;-import org.openremote.agent.protocol.trigger.time.TimeTriggerHandler;-import org.openremote.model.attribute.AttributeEvent;-import org.openremote.model.value.Value;-import org.openremote.model.value.Values;--import java.util.Objects;-import java.util.Optional;--public enum TriggerType implements TriggerHandlerProducer {-- /**- * For cron based triggers- */- TIME(new TimeTriggerHandler()),-- /**- * For {@link AttributeEvent} triggers- */- ATTRIBUTE(new AttributeTriggerHandler());-- private AbstractTriggerHandler handler;-- // Prevents cloning of values each time fromString is called- private static final TriggerType[] copyOfValues = values();-- TriggerType(AbstractTriggerHandler handler) {- this.handler = handler;- }-- public AbstractTriggerHandler getHandler() {- return handler;- }-- public static Optional<TriggerType> fromString(String value) {- for (TriggerType type : copyOfValues) {- if (type.name().equalsIgnoreCase(value))- return Optional.of(type);- }- return Optional.empty();- }-- public static String toString(TriggerType triggerType) {- Objects.requireNonNull(triggerType);- return triggerType.toString();- }-- public static Optional<TriggerType> fromValue(Value value) {- return Values.getString(value).flatMap(TriggerType::fromString);- }-- public static Value toValue(TriggerType triggerType) {- return Values.create(toString(triggerType));- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/attribute/AttributeTriggerHandler.java b/agent/src/main/java/org/openremote/agent/protocol/trigger/attribute/AttributeTriggerHandler.javadeleted file mode 100644index e3f3ffc1d..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/attribute/AttributeTriggerHandler.java+++ /dev/null@@ -1,67 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.trigger.attribute;--import org.openremote.agent.protocol.trigger.AbstractTriggerHandler;-import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.attribute.AttributeEvent;-import org.openremote.model.attribute.AttributeRef;-import org.openremote.model.value.Value;--public class AttributeTriggerHandler extends AbstractTriggerHandler {-- public static final String ATTRIBUTE_TRIGGER_HANDLER_NAME = "Attribute Event Trigger Handler";-- @Override- protected String getName() {- return ATTRIBUTE_TRIGGER_HANDLER_NAME;- }-- @Override- protected boolean isValidValue(Value triggerValue) {- return false;- }-- @Override- protected void registerTrigger(AttributeRef triggerRef, Value value, boolean isEnabled) {-- }-- @Override- protected void unregisterTrigger(AttributeRef triggerRef) {-- }-- @Override- protected void registerAttribute(AttributeRef attributeRef, AttributeRef triggerRef, String propertyName) {-- }--- @Override- protected void unregisterAttribute(AttributeRef attributeRef, AttributeRef triggerRef) {-- }-- @Override- protected void processAttributeWrite(AssetAttribute attribute, AssetAttribute protocolConfiguration, String propertyName, AttributeEvent event) {-- }-}diff --git a/agent/src/main/java/org/openremote/agent/protocol/trigger/time/TimeTriggerHandler.java b/agent/src/main/java/org/openremote/agent/protocol/trigger/time/TimeTriggerHandler.javadeleted file mode 100644index e1352e2fd..000000000--- a/agent/src/main/java/org/openremote/agent/protocol/trigger/time/TimeTriggerHandler.java+++ /dev/null@@ -1,215 +0,0 @@-/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */-package org.openremote.agent.protocol.trigger.time;--import org.openremote.agent.protocol.trigger.AbstractTriggerHandler;-import org.openremote.model.asset.AssetAttribute;-import org.openremote.model.attribute.AttributeEvent;-import org.openremote.model.attribute.AttributeRef;-import org.openremote.model.attribute.AttributeState;-import org.openremote.model.syslog.SyslogCategory;-import org.openremote.model.util.TextUtil;-import org.openremote.model.value.Value;-import org.openremote.model.value.Values;-import org.quartz.CronExpression;--import javax.ws.rs.NotSupportedException;-import java.text.ParseException;-import java.util.HashMap;-import java.util.Map;-import java.util.Optional;-import java.util.logging.Logger;--import static java.util.logging.Level.FINER;-import static org.openremote.agent.protocol.trigger.time.CronExpressionParser.parseNumberExpression;-import static org.openremote.model.syslog.SyslogCategory.PROTOCOL;-import static org.openremote.model.util.TextUtil.isNullOrEmpty;--public class TimeTriggerHandler extends AbstractTriggerHandler {-- private static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, TimeTriggerHandler.class);-- public static final String TIME_TRIGGER_HANDLER_NAME = "Time Trigger Handler";- protected final Map<AttributeRef, CronExpressionParser> cronExpressionMap = new HashMap<>();- protected CronScheduler cronScheduler;-- @Override- protected String getName() {- return TIME_TRIGGER_HANDLER_NAME;- }-- @Override- protected boolean isValidValue(Value triggerValue) {- return Values.getString(triggerValue).filter(TimeTriggerHandler::isValidCronExpression).isPresent();- }-- @Override- protected void registerTrigger(AttributeRef triggerRef, Value value, boolean isEnabled) {- Optional<String> expression = Values.getString(value).flatMap(TextUtil::asNonNullAndNonEmpty);- CronExpressionParser cronExpressionParser = null;-- if (expression.isPresent()) {- cronExpressionParser = new CronExpressionParser(expression.get());- } else {- LOG.warning("Time trigger value is not a cron expression string");- }-- synchronized (cronExpressionMap) {- cronExpressionMap.put(triggerRef, cronExpressionParser);- }-- if (isEnabled && cronExpressionParser != null && cronExpressionParser.isValid()) {- @SuppressWarnings("ConstantConditions")- CronExpression cronExpression = createCronExpression(cronExpressionParser.buildCronExpression());- if (cronExpression != null) {- getCronScheduler().addOrReplaceJob(getTriggerId(triggerRef), cronExpression, () -> {- LOG.fine("Quartz job has triggered");-- // This is executed when the job triggers- executeTrigger(triggerRef);- });- }- }- }-- @Override- protected void unregisterTrigger(AttributeRef triggerRef) {- getCronScheduler().removeJob(getTriggerId(triggerRef));- }-- @Override- protected void registerAttribute(AttributeRef attributeRef, AttributeRef triggerRef, String propertyName) {- TimeTriggerProperty property = TimeTriggerProperty.fromString(propertyName);- if (property == null) {- LOG.warning("Property name is not valid for time trigger handler: " + propertyName);- return;- }-- CronExpressionParser parser = getCronExpressionParser(triggerRef);- if (parser == null) {- LOG.info("Attribute is linked to an invalid trigger so it will be ignored");- return;- }-- switch (property) {- case CRON_EXPRESSION:- // Pass the entire cron expression through to the attribute- updateAttributeValue(new AttributeState(attributeRef, Values.create(parser.buildCronExpression())));- break;- case TIME:- // Pass the 24h formatted time- updateAttributeValue(new AttributeState(attributeRef, Values.create(parser.getFormattedTime())));- break;- }- }-- @Override- protected void unregisterAttribute(AttributeRef attributeRef, AttributeRef triggerRef) {-- }-- @Override- protected void processAttributeWrite(AssetAttribute attribute, AssetAttribute protocolConfiguration, String propertyName, AttributeEvent event) {- TimeTriggerProperty triggerProperty = TimeTriggerProperty.fromString(propertyName);- if (triggerProperty == null) {- LOG.warning("Attribute is using an invalid trigger property name '" + propertyName + "': " + attribute.getReferenceOrThrow());- return;- }-- // Don't remove or alter any running trigger just push update back through the system- // and wait for add, remove or update trigger call- Optional<String> writeValue = event.getValue().flatMap(Values::getString).flatMap(TextUtil::asNonNullAndNonEmpty);-- if (!writeValue.isPresent()) {- LOG.warning("Send to actuator value for time trigger must be a non empty string");- return;- }-- String value = writeValue.get().trim();-- switch (triggerProperty) {- case CRON_EXPRESSION:- // Allow writing invalid cron expressions; mean that the trigger will stop working- // but that is handled gracefully- updateTriggerValue(new AttributeState(protocolConfiguration.getReferenceOrThrow(), Values.create(value)));- break;- case TIME:- CronExpressionParser parser = getCronExpressionParser(protocolConfiguration.getReferenceOrThrow());- if (parser == null) {- LOG.info("Ignoring trigger update because current cron expression is invalid");- return;- }-- String[] writeTimeValues = value.split(":");- Integer hours;- Integer minutes;- Integer seconds;-- if (writeTimeValues.length != 3- || (hours = parseNumberExpression(writeTimeValues[0])) == null- || (minutes = parseNumberExpression(writeTimeValues[1])) == null- || (seconds = parseNumberExpression(writeTimeValues[2])) == null) {- LOG.info("Expected value to be in format HH:MM:SS, actual: " + writeValue);- return;- }-- parser.setTime(hours, minutes, seconds);- updateTriggerValue(new AttributeState(protocolConfiguration.getReferenceOrThrow(), Values.create(parser.buildCronExpression())));- break;- default:- throw new NotSupportedException("Unsupported trigger property");- }-- }-- protected CronScheduler getCronScheduler() {- if (cronScheduler == null) {- LOG.fine("Create cron scheduler");- cronScheduler = new CronScheduler();- }-- return cronScheduler;- }-- protected CronExpressionParser getCronExpressionParser(AttributeRef triggerRef) {- synchronized (cronExpressionMap) {- return cronExpressionMap.get(triggerRef);- }- }-- public static CronExpression createCronExpression(String expression) {- CronExpression cronExpression = null;- try {- cronExpression = new CronExpression(expression);- } catch (ParseException e) {- LOG.log(FINER, "Failed to create cron expression from string: " + expression, e);- }-- return cronExpression;- }-- public static boolean isValidCronExpression(String expression) {- return !isNullOrEmpty(expression) && createCronExpression(expression) != null;- }-- protected static String getTriggerId(AttributeRef triggerRef) {- return triggerRef.getEntityId() + ":" + triggerRef.getAttributeName();- }-}diff --git a/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocol b/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocolindex 3b4b0a97c..b95463ff8 100644--- a/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocol+++ b/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocol@@ -1,3 +1,3 @@org.openremote.agent.protocol.simulator.SimulatorProtocolorg.openremote.agent.protocol.macro.MacroProtocol-org.openremote.agent.protocol.trigger.TriggerProtocol\ No newline at end of file+org.openremote.agent.protocol.timer.TimerProtocol\ No newline at end of filediff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.javaindex 799167e09..98b5d9b92 100644--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java@@ -27,9 +27,7 @@ import org.openremote.agent.protocol.simulator.element.ColorSimulatorElement;import org.openremote.agent.protocol.simulator.element.DecimalSimulatorElement;import org.openremote.agent.protocol.simulator.element.IntegerSimulatorElement;import org.openremote.agent.protocol.simulator.element.SwitchSimulatorElement;-import org.openremote.agent.protocol.trigger.TriggerProtocol;-import org.openremote.agent.protocol.trigger.TriggerType;-import org.openremote.agent.protocol.trigger.time.TimeTriggerProperty;+import org.openremote.agent.protocol.timer.TimerValue;import org.openremote.container.Container;import org.openremote.manager.server.asset.ServerAsset;import org.openremote.manager.server.setup.AbstractManagerSetup;@@ -47,8 +45,8 @@ import java.util.Arrays;import java.util.List;import static org.openremote.agent.protocol.macro.MacroProtocol.META_MACRO_ACTION_INDEX;-import static org.openremote.agent.protocol.macro.MacroProtocol.PROPERTY_MACRO_ACTION;-import static org.openremote.agent.protocol.trigger.TriggerConfiguration.*;+import static org.openremote.agent.protocol.timer.TimerConfiguration.initTimerConfiguration;+import static org.openremote.agent.protocol.timer.TimerProtocol.META_TIMER_VALUE_LINK;import static org.openremote.model.asset.AssetMeta.*;import static org.openremote.model.asset.AssetType.*;import static org.openremote.model.asset.agent.ProtocolConfiguration.initProtocolConfiguration;@@ -452,250 +450,150 @@ public class ManagerDemoSetup extends AbstractManagerSetup {new MacroAction(new AttributeState(new AttributeRef(apartment1Id, "alarmEnabled"), Values.create(true))).toMetaItem(),new MacroAction(new AttributeState(new AttributeRef(apartment1LivingroomThermostatId, "targetTemperature"), Values.create(19d))).toMetaItem(),new MacroAction(new AttributeState(new AttributeRef(apartment1Id, "lastExecutedScene"), Values.create("NIGHT"))).toMetaItem()+ ),+ // Add triggers+ initTimerConfiguration(new AssetAttribute("homeMondayTrigger"), "0 0 7 ? * MON *",+ new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Home Monday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("awayMondayTrigger"), "0 30 8 ? * MON *",+ new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Monday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("eveningMondayTrigger"), "0 30 17 ? * MON *",+ new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Monday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("nightMondayTrigger"), "0 0 22 ? * MON *",+ new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Night Monday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("homeTuesdayTrigger"), "0 0 7 ? * TUE *",+ new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Home Tuesday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("awayTuesdayTrigger"), "0 30 8 ? * TUE *",+ new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Tuesday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("eveningTuesdayTrigger"), "0 30 17 ? * TUE *",+ new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Tuesday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("nightTuesdayTrigger"), "0 0 22 ? * TUE *",+ new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Night Tuesday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("homeWednesdayTrigger"), "0 0 7 ? * WED *",+ new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Home Wednesday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("awayWednesdayTrigger"), "0 30 8 ? * WED *",+ new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Wednesday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("eveningWednesdayTrigger"), "0 30 17 ? * WED *",+ new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Wednesday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("nightWednesdayTrigger"), "0 0 22 ? * WED *",+ new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Night Wednesday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("homeThursdayTrigger"), "0 0 7 ? * THU *",+ new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Home Thursday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("awayThursdayTrigger"), "0 30 8 ? * THU *",+ new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Thursday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("eveningThursdayTrigger"), "0 30 17 ? * THU *",+ new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Thursday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("nightThursdayTrigger"), "0 0 22 ? * THU *",+ new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Night Thursday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("homeFridayTrigger"), "0 0 7 ? * FRI *",+ new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Home Friday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("awayFridayTrigger"), "0 30 8 ? * FRI *",+ new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Friday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("eveningFridayTrigger"), "0 30 17 ? * FRI *",+ new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Friday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("nightFridayTrigger"), "0 0 22 ? * FRI *",+ new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Night Friday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("homeSaturdayTrigger"), "0 0 8 ? * SAT *",+ new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Home Saturday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("awaySaturdayTrigger"), "0 30 9 ? * SAT *",+ new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Saturday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("eveningSaturdayTrigger"), "0 30 18 ? * SAT *",+ new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Saturday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("nightSaturdayTrigger"), "0 0 23 ? * SAT *",+ new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Night Saturday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("homeSundayTrigger"), "0 0 8 ? * SUN *",+ new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Home Sunday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("awaySundayTrigger"), "0 30 9 ? * SUN *",+ new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Sunday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("eveningSundayTrigger"), "0 30 18 ? * SUN *",+ new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Evening Sunday trigger"))+ ),+ initTimerConfiguration(new AssetAttribute("nightSundayTrigger"), "0 0 23 ? * SUN *",+ new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")))+ .addMeta(+ new MetaItem(LABEL, Values.create("Night Sunday trigger"))));- // Add triggers- AssetAttribute homeMonday = initProtocolConfiguration(new AssetAttribute("homeMondayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Home Monday trigger"))- );- setTriggerType(homeMonday, TriggerType.TIME);- setTriggerValue(homeMonday, Values.create("0 0 7 ? * MON *"));- setTriggerAction(homeMonday, new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")));- AssetAttribute awayMonday = initProtocolConfiguration(new AssetAttribute("awayMondayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Away Monday trigger"))- );- setTriggerType(awayMonday, TriggerType.TIME);- setTriggerValue(awayMonday, Values.create("0 30 8 ? * MON *"));- setTriggerAction(awayMonday, new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")));- AssetAttribute eveningMonday = initProtocolConfiguration(new AssetAttribute("eveningMondayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Evening Monday trigger"))- );- setTriggerType(eveningMonday, TriggerType.TIME);- setTriggerValue(eveningMonday, Values.create("0 30 17 ? * MON *"));- setTriggerAction(eveningMonday, new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")));- AssetAttribute nightMonday = initProtocolConfiguration(new AssetAttribute("nightMondayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Night Monday trigger"))- );- setTriggerType(nightMonday, TriggerType.TIME);- setTriggerValue(nightMonday, Values.create("0 0 22 ? * MON *"));- setTriggerAction(nightMonday, new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")));--- AssetAttribute homeTuesday = initProtocolConfiguration(new AssetAttribute("homeTuesdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Home Tuesday trigger"))- );- setTriggerType(homeTuesday, TriggerType.TIME);- setTriggerValue(homeTuesday, Values.create("0 0 7 ? * TUE *"));- setTriggerAction(homeTuesday, new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")));- AssetAttribute awayTuesday = initProtocolConfiguration(new AssetAttribute("awayTuesdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Away Tuesday trigger"))- );- setTriggerType(awayTuesday, TriggerType.TIME);- setTriggerValue(awayTuesday, Values.create("0 30 8 ? * TUE *"));- setTriggerAction(awayTuesday, new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")));- AssetAttribute eveningTuesday = initProtocolConfiguration(new AssetAttribute("eveningTuesdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Evening Tuesday trigger"))- );- setTriggerType(eveningTuesday, TriggerType.TIME);- setTriggerValue(eveningTuesday, Values.create("0 30 17 ? * TUE *"));- setTriggerAction(eveningTuesday, new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")));- AssetAttribute nightTuesday = initProtocolConfiguration(new AssetAttribute("nightTuesdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Night Tuesday trigger"))- );- setTriggerType(nightTuesday, TriggerType.TIME);- setTriggerValue(nightTuesday, Values.create("0 0 22 ? * TUE *"));- setTriggerAction(nightTuesday, new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")));--- AssetAttribute homeWednesday = initProtocolConfiguration(new AssetAttribute("homeWednesdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Home Wednesday trigger"))- );- setTriggerType(homeWednesday, TriggerType.TIME);- setTriggerValue(homeWednesday, Values.create("0 0 7 ? * WED *"));- setTriggerAction(homeWednesday, new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")));- AssetAttribute awayWednesday = initProtocolConfiguration(new AssetAttribute("awayWednesdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Away Wednesday trigger"))- );- setTriggerType(awayWednesday, TriggerType.TIME);- setTriggerValue(awayWednesday, Values.create("0 30 8 ? * WED *"));- setTriggerAction(awayWednesday, new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")));- AssetAttribute eveningWednesday = initProtocolConfiguration(new AssetAttribute("eveningWednesdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Evening Wednesday trigger"))- );- setTriggerType(eveningWednesday, TriggerType.TIME);- setTriggerValue(eveningWednesday, Values.create("0 30 17 ? * WED *"));- setTriggerAction(eveningWednesday, new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")));- AssetAttribute nightWednesday = initProtocolConfiguration(new AssetAttribute("nightWednesdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Night Wednesday trigger"))- );- setTriggerType(nightWednesday, TriggerType.TIME);- setTriggerValue(nightWednesday, Values.create("0 0 22 ? * WED *"));- setTriggerAction(nightWednesday, new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")));--- AssetAttribute homeThursday = initProtocolConfiguration(new AssetAttribute("homeThursdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Home Thursday trigger"))- );- setTriggerType(homeThursday, TriggerType.TIME);- setTriggerValue(homeThursday, Values.create("0 0 7 ? * THU *"));- setTriggerAction(homeThursday, new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")));- AssetAttribute awayThursday = initProtocolConfiguration(new AssetAttribute("awayThursdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Away Thursday trigger"))- );- setTriggerType(awayThursday, TriggerType.TIME);- setTriggerValue(awayThursday, Values.create("0 30 8 ? * THU *"));- setTriggerAction(awayThursday, new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")));- AssetAttribute eveningThursday = initProtocolConfiguration(new AssetAttribute("eveningThursdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Evening Thursday trigger"))- );- setTriggerType(eveningThursday, TriggerType.TIME);- setTriggerValue(eveningThursday, Values.create("0 30 17 ? * THU *"));- setTriggerAction(eveningThursday, new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")));- AssetAttribute nightThursday = initProtocolConfiguration(new AssetAttribute("nightThursdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Night Thursday trigger"))- );- setTriggerType(nightThursday, TriggerType.TIME);- setTriggerValue(nightThursday, Values.create("0 0 22 ? * THU *"));- setTriggerAction(nightThursday, new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")));--- AssetAttribute homeFriday = initProtocolConfiguration(new AssetAttribute("homeFridayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Home Friday trigger"))- );- setTriggerType(homeFriday, TriggerType.TIME);- setTriggerValue(homeFriday, Values.create("0 0 7 ? * FRI *"));- setTriggerAction(homeFriday, new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")));- AssetAttribute awayFriday = initProtocolConfiguration(new AssetAttribute("awayFridayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Away Friday trigger"))- );- setTriggerType(awayFriday, TriggerType.TIME);- setTriggerValue(awayFriday, Values.create("0 30 8 ? * FRI *"));- setTriggerAction(awayFriday, new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")));- AssetAttribute eveningFriday = initProtocolConfiguration(new AssetAttribute("eveningFridayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Evening Friday trigger"))- );- setTriggerType(eveningFriday, TriggerType.TIME);- setTriggerValue(eveningFriday, Values.create("0 30 17 ? * FRI *"));- setTriggerAction(eveningFriday, new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")));- AssetAttribute nightFriday = initProtocolConfiguration(new AssetAttribute("nightFridayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Night Friday trigger"))- );- setTriggerType(nightFriday, TriggerType.TIME);- setTriggerValue(nightFriday, Values.create("0 0 22 ? * FRI *"));- setTriggerAction(nightFriday, new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")));--- AssetAttribute homeSaturday = initProtocolConfiguration(new AssetAttribute("homeSaturdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Home Saturday trigger"))- );- setTriggerType(homeSaturday, TriggerType.TIME);- setTriggerValue(homeSaturday, Values.create("0 0 8 ? * SAT *"));- setTriggerAction(homeSaturday, new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")));- AssetAttribute awaySaturday = initProtocolConfiguration(new AssetAttribute("awaySaturdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Away Saturday trigger"))- );- setTriggerType(awaySaturday, TriggerType.TIME);- setTriggerValue(awaySaturday, Values.create("0 30 9 ? * SAT *"));- setTriggerAction(awaySaturday, new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")));- AssetAttribute eveningSaturday = initProtocolConfiguration(new AssetAttribute("eveningSaturdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Evening Saturday trigger"))- );- setTriggerType(eveningSaturday, TriggerType.TIME);- setTriggerValue(eveningSaturday, Values.create("0 0 18 ? * SAT *"));- setTriggerAction(eveningSaturday, new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")));- AssetAttribute nightSaturday = initProtocolConfiguration(new AssetAttribute("nightSaturdayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Night Saturday trigger"))- );- setTriggerType(nightSaturday, TriggerType.TIME);- setTriggerValue(nightSaturday, Values.create("0 0 23 ? * SAT *"));- setTriggerAction(nightSaturday, new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")));--- AssetAttribute homeSunday = initProtocolConfiguration(new AssetAttribute("homeSundayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Home Sunday trigger"))- );- setTriggerType(homeSunday, TriggerType.TIME);- setTriggerValue(homeSunday, Values.create("0 0 8 ? * SUN *"));- setTriggerAction(homeSunday, new AttributeState(apartment1Id, "home", Values.create("REQUEST_START")));- AssetAttribute awaySunday = initProtocolConfiguration(new AssetAttribute("awaySundayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Away Sunday trigger"))- );- setTriggerType(awaySunday, TriggerType.TIME);- setTriggerValue(awaySunday, Values.create("0 30 9 ? * SUN *"));- setTriggerAction(awaySunday, new AttributeState(apartment1Id, "away", Values.create("REQUEST_START")));- AssetAttribute eveningSunday = initProtocolConfiguration(new AssetAttribute("eveningSundayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Evening Sunday trigger"))- );- setTriggerType(eveningSunday, TriggerType.TIME);- setTriggerValue(eveningSunday, Values.create("0 0 18 ? * SUN *"));- setTriggerAction(eveningSunday, new AttributeState(apartment1Id, "evening", Values.create("REQUEST_START")));- AssetAttribute nightSunday = initProtocolConfiguration(new AssetAttribute("nightSundayTrigger"), TriggerProtocol.PROTOCOL_NAME)- .addMeta(- new MetaItem(LABEL, Values.create("Night Sunday trigger"))- );- setTriggerType(nightSunday, TriggerType.TIME);- setTriggerValue(nightSunday, Values.create("0 0 23 ? * SUN *"));- setTriggerAction(nightSunday, new AttributeState(apartment1Id, "night", Values.create("REQUEST_START")));-- // Save the scenes and trigger agent- apartment1SceneAgent.addAttributes(- homeMonday,- homeTuesday,- homeWednesday,- homeThursday,- homeFriday,- homeSaturday,- homeSunday,- awayMonday,- awayTuesday,- awayWednesday,- awayThursday,- awayFriday,- awaySaturday,- awaySunday,- eveningMonday,- eveningTuesday,- eveningWednesday,- eveningThursday,- eveningFriday,- eveningSaturday,- eveningSunday,- nightMonday,- nightTuesday,- nightWednesday,- nightThursday,- nightFriday,- nightSaturday,- nightSunday- );apartment1SceneAgent = assetStorageService.merge(apartment1SceneAgent);apartment1SceneAgentId = apartment1SceneAgent.getId();@@ -712,7 +610,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.setMeta(new MetaItem(LABEL, Values.create("Home alarm enabled")),new MetaItem(DESCRIPTION, Values.create("Alarm enabled for home scene")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(PROPERTY_MACRO_ACTION)),new MetaItem(META_MACRO_ACTION_INDEX, Values.create(0)),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeScene").toArrayValue())),@@ -720,7 +617,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.setMeta(new MetaItem(LABEL, Values.create("Home target temperature")),new MetaItem(DESCRIPTION, Values.create("Target temperature for home scene")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(PROPERTY_MACRO_ACTION)),new MetaItem(META_MACRO_ACTION_INDEX, Values.create(1)),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeScene").toArrayValue())),@@ -735,7 +631,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.setMeta(new MetaItem(LABEL, Values.create("Away alarm enabled")),new MetaItem(DESCRIPTION, Values.create("Alarm enabled for away scene")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(PROPERTY_MACRO_ACTION)),new MetaItem(META_MACRO_ACTION_INDEX, Values.create(0)),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayScene").toArrayValue())),@@ -743,7 +638,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.setMeta(new MetaItem(LABEL, Values.create("Away target temperature")),new MetaItem(DESCRIPTION, Values.create("Target temperature for away scene")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(PROPERTY_MACRO_ACTION)),new MetaItem(META_MACRO_ACTION_INDEX, Values.create(1)),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayScene").toArrayValue())),@@ -758,7 +652,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.setMeta(new MetaItem(LABEL, Values.create("Evening alarm enabled")),new MetaItem(DESCRIPTION, Values.create("Alarm enabled for evening scene")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(PROPERTY_MACRO_ACTION)),new MetaItem(META_MACRO_ACTION_INDEX, Values.create(0)),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningScene").toArrayValue())),@@ -766,7 +659,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.setMeta(new MetaItem(LABEL, Values.create("Evening target temperature")),new MetaItem(DESCRIPTION, Values.create("Target temperature for evening scene")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(PROPERTY_MACRO_ACTION)),new MetaItem(META_MACRO_ACTION_INDEX, Values.create(1)),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningScene").toArrayValue())),@@ -781,7 +673,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.setMeta(new MetaItem(LABEL, Values.create("Night alarm enabled")),new MetaItem(DESCRIPTION, Values.create("Alarm enabled for night scene")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(PROPERTY_MACRO_ACTION)),new MetaItem(META_MACRO_ACTION_INDEX, Values.create(0)),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightScene").toArrayValue())),@@ -789,7 +680,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.setMeta(new MetaItem(LABEL, Values.create("Night target temperature")),new MetaItem(DESCRIPTION, Values.create("Target temperature for night scene")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(PROPERTY_MACRO_ACTION)),new MetaItem(META_MACRO_ACTION_INDEX, Values.create(1)),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightScene").toArrayValue())),@@ -797,364 +687,364 @@ public class ManagerDemoSetup extends AbstractManagerSetup {.setMeta(new MetaItem(LABEL, Values.create("Home time Monday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeMondayTrigger").toArrayValue())),new AssetAttribute("homeEnabledMONDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Home enabled Monday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeMondayTrigger").toArrayValue())),new AssetAttribute("awayTimeMONDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Away time Monday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayMondayTrigger").toArrayValue())),new AssetAttribute("awayEnabledMONDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Away enabled Monday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayMondayTrigger").toArrayValue())),new AssetAttribute("eveningTimeMONDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Evening time Monday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningMondayTrigger").toArrayValue())),new AssetAttribute("eveningEnabledMONDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Evening enabled Monday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningMondayTrigger").toArrayValue())),new AssetAttribute("nightTimeMONDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Night time Monday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightMondayTrigger").toArrayValue())),new AssetAttribute("nightEnabledMONDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Night enabled Monday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightMondayTrigger").toArrayValue())),new AssetAttribute("homeTimeTUESDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Home time Tuesday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeTuesdayTrigger").toArrayValue())),new AssetAttribute("homeEnabledTUESDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Home enabled Tuesday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeTuesdayTrigger").toArrayValue())),new AssetAttribute("awayTimeTUESDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Away time Tuesday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayTuesdayTrigger").toArrayValue())),new AssetAttribute("awayEnabledTUESDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Away enabled Tuesday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayTuesdayTrigger").toArrayValue())),new AssetAttribute("eveningTimeTUESDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Evening time Tuesday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningTuesdayTrigger").toArrayValue())),new AssetAttribute("eveningEnabledTUESDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Evening enabled Tuesday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningTuesdayTrigger").toArrayValue())),new AssetAttribute("nightTimeTUESDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Night time Tuesday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightTuesdayTrigger").toArrayValue())),new AssetAttribute("nightEnabledTUESDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Night enabled Tuesday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightTuesdayTrigger").toArrayValue())),new AssetAttribute("homeTimeWEDNESDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Home time Wednesday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeWednesdayTrigger").toArrayValue())),new AssetAttribute("homeEnabledWEDNESDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Home enabled Wednesday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeWednesdayTrigger").toArrayValue())),new AssetAttribute("awayTimeWEDNESDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Away time Wednesday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayWednesdayTrigger").toArrayValue())),new AssetAttribute("awayEnabledWEDNESDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Away enabled Wednesday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayWednesdayTrigger").toArrayValue())),new AssetAttribute("eveningTimeWEDNESDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Evening time Wednesday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningWednesdayTrigger").toArrayValue())),new AssetAttribute("eveningEnabledWEDNESDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Evening enabled Wednesday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningWednesdayTrigger").toArrayValue())),new AssetAttribute("nightTimeWEDNESDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Night time Wednesday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightWednesdayTrigger").toArrayValue())),new AssetAttribute("nightEnabledWEDNESDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Night enabled Wednesday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightWednesdayTrigger").toArrayValue())),new AssetAttribute("homeTimeTHURSDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Home time Thursday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeThursdayTrigger").toArrayValue())),new AssetAttribute("homeEnabledTHURSDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Home enabled Thursday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeThursdayTrigger").toArrayValue())),new AssetAttribute("awayTimeTHURSDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Away time Thursday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayThursdayTrigger").toArrayValue())),new AssetAttribute("awayEnabledTHURSDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Away enabled Thursday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayThursdayTrigger").toArrayValue())),new AssetAttribute("eveningTimeTHURSDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Evening time Thursday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningThursdayTrigger").toArrayValue())),new AssetAttribute("eveningEnabledTHURSDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Evening enabled Thursday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningThursdayTrigger").toArrayValue())),new AssetAttribute("nightTimeTHURSDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Night time Thursday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightThursdayTrigger").toArrayValue())),new AssetAttribute("nightEnabledTHURSDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Night enabled Thursday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightThursdayTrigger").toArrayValue())),new AssetAttribute("homeTimeFRIDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Home time Friday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeFridayTrigger").toArrayValue())),new AssetAttribute("homeEnabledFRIDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Home enabled Friday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeFridayTrigger").toArrayValue())),new AssetAttribute("awayTimeFRIDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Away time Friday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayFridayTrigger").toArrayValue())),new AssetAttribute("awayEnabledFRIDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Away enabled Friday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awayFridayTrigger").toArrayValue())),new AssetAttribute("eveningTimeFRIDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Evening time Friday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningFridayTrigger").toArrayValue())),new AssetAttribute("eveningEnabledFRIDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Evening enabled Friday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningFridayTrigger").toArrayValue())),new AssetAttribute("nightTimeFRIDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Night time Friday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightFridayTrigger").toArrayValue())),new AssetAttribute("nightEnabledFRIDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Night enabled Friday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightFridayTrigger").toArrayValue())),new AssetAttribute("homeTimeSATURDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Home time Saturday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeSaturdayTrigger").toArrayValue())),new AssetAttribute("homeEnabledSATURDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Home enabled Saturday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeSaturdayTrigger").toArrayValue())),new AssetAttribute("awayTimeSATURDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Away time Saturday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awaySaturdayTrigger").toArrayValue())),new AssetAttribute("awayEnabledSATURDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Away enabled Saturday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awaySaturdayTrigger").toArrayValue())),new AssetAttribute("eveningTimeSATURDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Evening time Saturday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningSaturdayTrigger").toArrayValue())),new AssetAttribute("eveningEnabledSATURDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Evening enabled Saturday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningSaturdayTrigger").toArrayValue())),new AssetAttribute("nightTimeSATURDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Night time Saturday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightSaturdayTrigger").toArrayValue())),new AssetAttribute("nightEnabledSATURDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Night enabled Saturday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightSaturdayTrigger").toArrayValue())),new AssetAttribute("homeTimeSUNDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Home time Sunday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeSundayTrigger").toArrayValue())),new AssetAttribute("homeEnabledSUNDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Home enabled Sunday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "homeSundayTrigger").toArrayValue())),new AssetAttribute("awayTimeSUNDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Away time Sunday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awaySundayTrigger").toArrayValue())),new AssetAttribute("awayEnabledSUNDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Away enabled Sunday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "awaySundayTrigger").toArrayValue())),new AssetAttribute("eveningTimeSUNDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Evening time Sunday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningSundayTrigger").toArrayValue())),new AssetAttribute("eveningEnabledSUNDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Evening enabled Sunday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "eveningSundayTrigger").toArrayValue())),new AssetAttribute("nightTimeSUNDAY", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Night time Sunday")),new MetaItem(RULE_STATE, Values.create(true)),- new MetaItem(PROTOCOL_PROPERTY, Values.create(TimeTriggerProperty.TIME.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.TIME.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightSundayTrigger").toArrayValue())),new AssetAttribute("nightEnabledSUNDAY", AttributeType.BOOLEAN).setMeta(new MetaItem(LABEL, Values.create("Night enabled Sunday")),- new MetaItem(PROTOCOL_PROPERTY, Values.create(ENABLED.toString())),+ new MetaItem(META_TIMER_VALUE_LINK, Values.create(TimerValue.ENABLED.toString())),new MetaItem(AGENT_LINK, new AttributeRef(apartment1SceneAgentId, "nightSundayTrigger").toArrayValue())));diff --git a/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy b/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovyindex 3d0aaff57..645d565e1 100644--- a/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy@@ -263,17 +263,6 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {new AttributeRef(mockAgent.getId(), "mockConfig4").toArrayValue())),- // The below attribute is handled by abstract protocol and won't reach the mock- // protocol link/unlink attribute method- new AssetAttribute("protocolEnabled", AttributeType.BOOLEAN)- .setMeta(- new MetaItem("MOCK_ATTRIBUTE_REQUIRED_META", Values.create(true)),- new MetaItem(AssetMeta.PROTOCOL_PROPERTY, Values.create("ENABLED")),- new MetaItem(- AssetMeta.AGENT_LINK,- new AttributeRef(mockAgent.getId(), "mockConfig4").toArrayValue()- )- ),new AssetAttribute("invalidToggle5", AttributeType.BOOLEAN, Values.create(false)).setMeta(new MetaItem(@@ -357,34 +346,6 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait {assert protocolMethodCalls[1] == "UNLINK_PROTOCOL"}- when: "a disabled protocol configuration is enabled"- protocolMethodCalls.clear()- assetProcessingService.sendAttributeEvent(new AttributeEvent(mockThing.getId(),"protocolEnabled", Values.create(true)))-- then: "the protocol configuration should be relinked"- conditions.eventually {- assert protocolLinkedAttributes['mockConfig4'].size() == 2- assert protocolMethodCalls.size() == 6- assert protocolMethodCalls[0] == "UNLINK_ATTRIBUTE"- assert protocolMethodCalls[1] == "UNLINK_ATTRIBUTE"- assert protocolMethodCalls[2] == "UNLINK_PROTOCOL"- assert protocolMethodCalls[3] == "LINK_PROTOCOL"- assert protocolMethodCalls[4] == "LINK_ATTRIBUTE"- assert protocolMethodCalls[5] == "LINK_ATTRIBUTE"- }-- and: "the deployment status of the relinked protocol configuration should now be LINKED_ENABLED"- def config4 = protocolLinkedConfigurations.find { it.getName().orElse("").equals("mockConfig4") }- assert config4 != null- assert agentService.getProtocolDeploymentStatus(config4.getReferenceOrThrow()) == Protocol.DeploymentStatus.LINKED_ENABLED-- when: "the mock thing is retrieved from the DB"- mockThing = assetStorageService.find(mockThing.getId(), true)-- then: "the linked attribute values should have been updated by the protocol"- assert mockThing.getAttribute("lightToggle4").get().getValueAsBoolean().orElse(false)- assert mockThing.getAttribute("tempTarget4").get().getValueAsNumber().orElse(0d) == 25.5d-when: "the mock protocol tries to update the plain readonly attribute"mockProtocol.updateAttribute(new AttributeState(mockThing.getId(),"plainAttribute", Values.create("UPDATE")))diff --git a/manager/test/src/test/groovy/org/openremote/test/protocol/TriggerProtocolTest.groovy b/manager/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovysimilarity index 98%rename from manager/test/src/test/groovy/org/openremote/test/protocol/TriggerProtocolTest.groovyrename to manager/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovyindex d06fe798e..b925a8e4f 100644--- a/manager/test/src/test/groovy/org/openremote/test/protocol/TriggerProtocolTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovy@@ -12,8 +12,8 @@ import spock.lang.Ignoreimport spock.lang.Specificationimport spock.util.concurrent.PollingConditions-class TriggerProtocolTest extends Specification implements ManagerContainerTrait {- // TODO: Test the trigger protocol+class TimerProtocolTest extends Specification implements ManagerContainerTrait {+ // TODO: Test the timer protocol@Ignoredef "Check time trigger protocol"() {diff --git a/model/src/main/java/org/openremote/model/asset/AssetMeta.java b/model/src/main/java/org/openremote/model/asset/AssetMeta.javaindex f205de16b..9426fc07a 100644--- a/model/src/main/java/org/openremote/model/asset/AssetMeta.java+++ b/model/src/main/java/org/openremote/model/asset/AssetMeta.java@@ -155,14 +155,7 @@ public enum AssetMeta implements HasUniqueResourceName {/*** Marks an attribute as being executable so it then supports values of type {@link AttributeExecuteStatus}.*/- EXECUTABLE(ASSET_META_NAMESPACE + ":executable", new Access(true, false, true), ValueType.BOOLEAN),-- /**- * Marks an agent linked attribute as being linked to a property of the linked protocol, supported values- * are protocol dependent.- * TODO: Merge this into protocols that require custom configuration- */- PROTOCOL_PROPERTY(ASSET_META_NAMESPACE + ":protocolProperty", new Access(true, false, true), ValueType.STRING);+ EXECUTABLE(ASSET_META_NAMESPACE + ":executable", new Access(true, false, true), ValueType.BOOLEAN);public enum AssetMetaValidationFailure implements ValidationFailure {VALUE_DOES_NOT_MATCH_ASSET_META_TYPE