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
AttributeCommand added
Rich Turner961220fc615e
diff --git a/model/src/main/java/org/openremote/model/AttributeCommand.java b/model/src/main/java/org/openremote/model/AttributeCommand.javanew file mode 100644index 000000000..4061b67ba--- /dev/null+++ b/model/src/main/java/org/openremote/model/AttributeCommand.java@@ -0,0 +1,89 @@+/*+ * 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.model;++import elemental.json.Json;+import elemental.json.JsonObject;+import elemental.json.JsonValue;++/**+ *+ */+public class AttributeCommand {+ protected boolean cancel;+ protected boolean repeat;+ protected JsonValue value;+ public static final AttributeCommand CANCEL_ATTRIBUTE_COMMAND;++ static {+ AttributeCommand cancel = new AttributeCommand();+ cancel.setCancel(true);+ CANCEL_ATTRIBUTE_COMMAND = cancel;+ }++ public AttributeCommand() {+ }++ public AttributeCommand(boolean repeat) {+ this(repeat, false, null);+ }++ public AttributeCommand(JsonValue value) {+ this(false, false, value);+ }++ public AttributeCommand(boolean repeat, boolean cancel, JsonValue value) {+ this.repeat = repeat;+ this.cancel = cancel;+ this.value = value;+ }++ public boolean isCancel() {+ return cancel;+ }++ public void setCancel(boolean cancel) {+ this.cancel = cancel;+ }++ public boolean isRepeat() {+ return repeat;+ }++ public void setRepeat(boolean repeat) {+ this.repeat = repeat;+ }++ public JsonValue getValue() {+ return value;+ }++ public void setValue(JsonValue value) {+ this.value = value != null ? value : Json.createNull();+ }++ public JsonValue asJsonValue() {+ JsonObject jsonObject = Json.createObject();+ jsonObject.put("cancel", Json.create(cancel));+ jsonObject.put("repeat", Json.create(repeat));+ jsonObject.put("value", value);+ return jsonObject;+ }+}diff --git a/model/src/main/java/org/openremote/model/CommandStatus.java b/model/src/main/java/org/openremote/model/CommandStatus.javanew file mode 100644index 000000000..66b3bc3c8--- /dev/null+++ b/model/src/main/java/org/openremote/model/CommandStatus.java@@ -0,0 +1,51 @@+/*+ * 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.model;++import elemental.json.Json;+import elemental.json.JsonObject;+import elemental.json.JsonValue;++public enum CommandStatus {+ /**+ * Command has completed+ */+ COMPLETED,+ /**+ * Command is currently executing+ */+ ACTIVE,+ /**+ * Command has been cancelled+ */+ CANCELLED,++ /**+ * Command produced an error+ */+ ERROR;++ public JsonValue asJsonValue() {+ // Use JsonObject so it can be pushed into executable attribute+ JsonObject jsonObject = Json.createObject();+ jsonObject.put("status", Json.create(this.toString()));+ return jsonObject;+ }+}diff --git a/model/src/main/java/org/openremote/model/asset/AssetMeta.java b/model/src/main/java/org/openremote/model/asset/AssetMeta.javaindex dea8fcf51..f66dec883 100644--- a/model/src/main/java/org/openremote/model/asset/AssetMeta.java+++ b/model/src/main/java/org/openremote/model/asset/AssetMeta.java@@ -134,7 +134,12 @@ public enum AssetMeta {/*** Enable flag to be used by asset attributes that could require this functionality (e.g. ProtocolConfiguration)*/- ENABLED(ASSET_META_NAMESPACE + ":enabled", new Access(true, false, true), JsonType.BOOLEAN);+ ENABLED(ASSET_META_NAMESPACE + ":enabled", new Access(true, false, true), JsonType.BOOLEAN),++ /**+ * Marks an attribute as being an executable command+ */+ COMMAND(ASSET_META_NAMESPACE + ":command", new Access(true, false, true), JsonType.BOOLEAN);final protected String name;final protected Access access;