Skip to content

armgit / core

Public Imported from GitHub
0

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

Created AttributeUnits and a units AssetAttributeMeta item

Rich Turnerbcf525bd41a0
diff --git a/agent/src/main/java/org/openremote/agent3/protocol/simulator/element/ColorSimulatorElement.java b/agent/src/main/java/org/openremote/agent3/protocol/simulator/element/ColorSimulatorElement.java
index adb7d0a46..321d8af11 100644
--- a/agent/src/main/java/org/openremote/agent3/protocol/simulator/element/ColorSimulatorElement.java
+++ b/agent/src/main/java/org/openremote/agent3/protocol/simulator/element/ColorSimulatorElement.java
@@ -24,6 +24,6 @@ import org.openremote.model.AttributeType;
public class ColorSimulatorElement extends SimulatorElement {
public ColorSimulatorElement() {
- super(AttributeType.COLOR);
+ super(AttributeType.STRING);
}
}
diff --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.java
index 37b2abfd9..7b33c8ec0 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
@@ -160,8 +160,12 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
SimulatorProtocol.META_NAME_ELEMENT, Json.create("range")
))
),
- new Attribute("light1Color", COLOR, new Color(88, 123, 88).asJsonValue())
+ new Attribute("light1Color", STRING, new Color(88, 123, 88).asJsonValue())
.setMetadata(new Metadata()
+ .add(new MetadataItem(
+ AssetAttributeMeta.UNITS.getName(),
+ Json.create(AttributeUnits.COLOR_RGB.toString())
+ ))
.add(new MetadataItem(
AssetAttributeMeta.DESCRIPTION.getName(),
Json.create("The color of the living room light"))
diff --git a/model/src/main/java/org/openremote/model/AttributeType.java b/model/src/main/java/org/openremote/model/AttributeType.java
index 6deb13890..f14443ee9 100644
--- a/model/src/main/java/org/openremote/model/AttributeType.java
+++ b/model/src/main/java/org/openremote/model/AttributeType.java
@@ -22,10 +22,8 @@ package org.openremote.model;
import elemental.json.JsonType;
public enum AttributeType {
-
- UNKNOWN("Unknown", JsonType.STRING),
- OBJECT("Object", JsonType.OBJECT),
STRING("String", JsonType.STRING),
+ OBJECT("Object", JsonType.OBJECT),
INTEGER("Integer", JsonType.NUMBER),
DECIMAL("Decimal", JsonType.NUMBER),
BOOLEAN("Boolean", JsonType.BOOLEAN),
@@ -33,17 +31,7 @@ public enum AttributeType {
STRING_ARRAY("String[]", JsonType.ARRAY),
INTEGER_ARRAY("Integer[]", JsonType.ARRAY),
DECIMAL_ARRAY("Decimal[]", JsonType.ARRAY),
- BOOLEAN_ARRAY("Boolean[]", JsonType.ARRAY),
- TIMESTAMP("Timestamp", JsonType.STRING), // Unix timestamp
- DATE("Date", JsonType.STRING), // ISO 8601, e.g. "2012-04-23T18:25:43.511Z"
- COLOR("Color", JsonType.OBJECT), // RGB integers
- TEMPERATURE("Temperature", JsonType.NUMBER),
- CO2("CO2", JsonType.NUMBER),
- HUMIDITY("Humidity", JsonType.NUMBER),
- POWER("Power", JsonType.NUMBER),
- CHARGE("Charge", JsonType.NUMBER),
- ENERGY("Energy", JsonType.NUMBER),
- WATER("Water", JsonType.NUMBER);
+ BOOLEAN_ARRAY("Boolean[]", JsonType.ARRAY);
private String value;
private JsonType jsonType;
@@ -69,6 +57,6 @@ public enum AttributeType {
return v;
}
}
- return UNKNOWN;
+ return STRING;
}
}
diff --git a/model/src/main/java/org/openremote/model/AttributeUnits.java b/model/src/main/java/org/openremote/model/AttributeUnits.java
new file mode 100644
index 000000000..2e5ce4990
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/AttributeUnits.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2016, 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;
+
+public enum AttributeUnits {
+ TIMESTAMP, // Unix epoch timestamp
+ DATETIME, // ISO 8601, e.g. "2012-04-23T18:25:43.511Z"
+ COLOR_RGB, // RGB integers
+ COLOR_ARGB, // ARGB integers
+ COLOR_HEX, // Hex value e.g. #FFFFFF
+ TEMPERATURE_CELCIUS,
+ TEMPERATURE_KELVIN,
+ TEMPERATURE_FARENHEIT,
+ DISTANCE_M,
+ DISTANCE_CM,
+ DISTANCE_MM,
+ DISTANCE_IN,
+ DISTANCE_FT,
+ DISTANCE_YARD,
+ CO2_PPM,
+ CO2_PERCENTAGE,
+ HUMIDITY_PERCENTAGE,
+ HUMIDITY_GPCM, // Grams per cubic metre
+ POWER_WATTS,
+ POWER_KILOWATT,
+ POWER_MEGAWATT,
+ CHARGE_PERCENTAGE,
+ CHARGE_KWH,
+ PERCENTAGE,
+ ENERGY_KWH,
+ ENERGY_JOULE,
+ ENERGY_MEGAJOULE,
+ FLOW_LPM, // Litre per minute
+ FLOW_CMPS, // Cubic metres per second
+ FLOW_SCCM, // Standard cubic centimetres per minute
+ FLOW_CFPS, // Cubic feet per second
+ FLOW_GPM, // Gallons per minute
+}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetAttributeMeta.java b/model/src/main/java/org/openremote/model/asset/AssetAttributeMeta.java
index 75ec93305..97654c889 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetAttributeMeta.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetAttributeMeta.java
@@ -83,7 +83,13 @@ public enum AssetAttributeMeta {
/**
* Regex (Java syntax) constraint for string attribute values.
*/
- PATTERN("urn:openremote:asset:meta:pattern", true, JsonType.STRING);
+ PATTERN("urn:openremote:asset:meta:pattern", true, JsonType.STRING),
+
+ /**
+ * Indicates the units (data type) of the attribute value should be a valid
+ * {@link org.openremote.model.AttributeUnits} value
+ */
+ UNITS("urn:openremote:asset:meta:units", true, JsonType.STRING);
final protected String name;
final protected boolean editable; // Can the user edit an asset and apply this meta item?