Skip to content

armgit / core

Public Imported from GitHub
0

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

Added new ValueType for 0-255 levels (8bit unsigned int)

Eric Bariauxe816c8b75de0
diff --git a/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties b/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
index 94bd891fa..70e61fb78 100644
--- a/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
+++ b/client/src/main/resources/org/openremote/app/client/i18n/ManagerMessages.properties
@@ -194,6 +194,7 @@ attributeValueType[BOOLEAN]=On/Off toggle
attributeValueType[OBJECT]=JSON object
attributeValueType[ARRAY]=JSON array
attributeValueType[PERCENTAGE]=Percentage
+attributeValueType[LEVEL_UINT8]=Level 0-255
attributeValueType[TIMESTAMP_MILLIS]=Timestamp milliseconds since epoch
attributeValueType[TIMESTAMP_SECONDS]=Timestamp seconds since epoch
attributeValueType[DATETIME]=Timestamp in ISO 8601
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
index 5abd8e2c1..9b7dcc859 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
@@ -64,6 +64,15 @@ public enum AttributeValueType implements AttributeValueDescriptor {
FORMAT.withInitialValue(Values.create("%3d %%"))
),
+ LEVEL_UINT8("level", ValueType.NUMBER,
+ value -> Values.getNumber(value)
+ .filter(number -> number < 0 || number > 255)
+ .map(number -> new ValidationFailure(ValueHolder.ValueFailureReason.VALUE_INVALID)),
+ RANGE_MIN.withInitialValue(Values.create(0)),
+ RANGE_MAX.withInitialValue(Values.create(255)),
+ FORMAT.withInitialValue(Values.create("%3d"))
+ ),
+
TIMESTAMP_MILLIS("clock-o", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%d ms"))),
TIMESTAMP_SECONDS("clock-o", ValueType.NUMBER, FORMAT.withInitialValue(Values.create("%d s"))),
@@ -245,4 +254,4 @@ public enum AttributeValueType implements AttributeValueDescriptor {
public Optional<Function<Value, Optional<ValidationFailure>>> getValidator() {
return Optional.ofNullable(validator);
}
-}
\ No newline at end of file
+}