Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Added updateOnWrite optional attribute to Agents

Rich Turnerff3897e467e9
diff --git a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
index 264716abf..01639cb75 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java
@@ -230,6 +230,10 @@ public abstract class AbstractProtocol<T extends Agent<T, ?, U>, U extends Agent
}
doLinkedAttributeWrite(attribute, agent.getAgentLink(attribute), event, ignoreAndConverted.value);
+
+ if (agent.isUpdateOnWrite().orElse(false)) {
+ updateLinkedAttribute(new AttributeState(event.getAttributeRef(), ignoreAndConverted.value));
+ }
}
});
}
diff --git a/model/src/main/java/org/openremote/model/asset/agent/Agent.java b/model/src/main/java/org/openremote/model/asset/agent/Agent.java
index 889122bae..cfd75e942 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/Agent.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/Agent.java
@@ -130,6 +130,11 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
*/
public static final AttributeDescriptor<Integer> POLLING_MILLIS = new AttributeDescriptor<>("pollingMillis", ValueType.POSITIVE_INTEGER).withOptional(true);
+ /**
+ * Don't expect a response from the protocol just update the attribute immediately on write
+ */
+ public static final AttributeDescriptor<Boolean> UPDATE_ON_WRITE = new AttributeDescriptor<>("updateOnWrite", ValueType.BOOLEAN).withOptional(true);
+
protected Agent() {
}
@@ -249,6 +254,16 @@ public abstract class Agent<T extends Agent<T, U, V>, U extends Protocol<T>, V e
return getAttributes().getValue(POLLING_MILLIS);
}
+ public Optional<Boolean> isUpdateOnWrite() {
+ return getAttributes().getValue(UPDATE_ON_WRITE);
+ }
+
+ @SuppressWarnings("unchecked")
+ public T setUpdateOnWrite(boolean updateOnWrite) {
+ getAttributes().getOrCreate(UPDATE_ON_WRITE).setValue(updateOnWrite);
+ return (T) this;
+ }
+
/**
* Indicates if the specified attribute name is a configuration attribute and therefore if an {@link
* org.openremote.model.attribute.AttributeEvent} is detected for this attribute the agent should be stopped and