Skip to content

armgit / core

Public Imported from GitHub
0

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

Improved presence detection rules, minor bugfixes

Christian Baueredc27d3ccc77
diff --git a/console/android/src/main/res/values/strings.xml b/console/android/src/main/res/values/strings.xml
index f87a57ffb..7e9719267 100644
--- a/console/android/src/main/res/values/strings.xml
+++ b/console/android/src/main/res/values/strings.xml
@@ -10,14 +10,14 @@
<string name="SHARED_PREF_FCM_TOKEN">FCM_TOKEN_KEY</string>
<string name="SHARED_PREF_DEVICE_ID">FCM_DEVICE_ID_KEY</string>
<string name="reload">reload</string>
- <string name="noConnectivity">No connectivity Detected</string>
- <string name="noConnectivityExplain">This application can not work without internet connectivity, you can wait to have it back or exit app.</string>
+ <string name="noConnectivity">Network connection not available.</string>
+ <string name="noConnectivityExplain">Can't connect to the OpenRemote service.</string>
<string name="SHARED_PREF_OPENED_ALERT">OPENED_ALERT</string>
<string name="AUTH_URL">/auth</string>
<string name="SSL_IGNORE">false</string>
<string name="exit">exit</string>
- <string name="fatalErrorExplain">Service unavaible, please try again later</string>
- <string name="fatalError">Something go wrong</string>
- <string name="httpError">Failled to contact service</string>
- <string name="httpErrorExplain">Something went wrong when communicating with server.</string>
+ <string name="fatalError">A fatal error occurred.</string>
+ <string name="fatalErrorExplain">OpenRemote service is not available, please try again later.</string>
+ <string name="httpError">Invalid response from service.</string>
+ <string name="httpErrorExplain">An error occurred communicating with the OpenRemote server.</string>
</resources>
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java
index 1197fc23a..f4349f5ff 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java
@@ -294,13 +294,14 @@ public abstract class AttributesBrowser
formGroup.addStyleName(environment.getWidgetStyle().HighlightBackground());
Browser.getWindow().setTimeout(() -> formGroup.removeStyleName(environment.getWidgetStyle().HighlightBackground()), 250);
- // Refresh charts, jump to current time so the new value is visible
+ // Refresh extensions
FormGroup attributeFormGroup = attributeGroups.get(attribute);
if (attributeFormGroup != null) {
attributeFormGroup.forExtension(widget -> {
if (widget instanceof DatapointBrowser) {
+ // Refresh charts, jump to current time so the new value is visible
DatapointBrowser datapointBrowser = (DatapointBrowser) widget;
- datapointBrowser.refresh(attribute.getValueTimestamp().orElse(System.currentTimeMillis()));
+ datapointBrowser.refresh(System.currentTimeMillis());
}
});
}
diff --git a/manager/client/src/main/java/org/openremote/manager/client/widget/ValueEditors.java b/manager/client/src/main/java/org/openremote/manager/client/widget/ValueEditors.java
index 2bca7ffc7..9f3df1e0b 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/widget/ValueEditors.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/widget/ValueEditors.java
@@ -50,9 +50,9 @@ public final class ValueEditors {
}
/**
- * Maps a {@link FormGroup} which is typically one editor line to an {@link ValueHolder} and
- * encapsulates the raw value that should be set on the value holder and the consumer of validation failure
- * results. If there are no validation failures, the update was successful.
+ * Maps a {@link FormGroup} which is typically one editor line to a {@link ValueHolder} and
+ * encapsulates the raw value that should be set on the value holder and the consumer of
+ * validation failure results. If there are no validation failures, the update was successful.
*/
private static class ValueUpdate<T> {
final FormGroup formGroup;
@@ -142,14 +142,7 @@ public final class ValueEditors {
public TimestampLabel(Long timestamp) {
addStyleName("layout vertical end or-FormInfoLabel or-ValueTimestamp");
- if (timestamp != null) {
- setTimestamp(timestamp);
- }
- }
-
- public void setTimestamp(long timestamp) {
- clear();
- if (timestamp > 0) {
+ if (timestamp != null && timestamp > 0) {
add(new FormOutputText(dateFormat.format(new Date(timestamp))));
add(new FormOutputText(timeFormat.format(new Date(timestamp))));
}
@@ -174,11 +167,8 @@ public final class ValueEditors {
widgetWrapper.setStyleName("flex layout horizontal center");
widgetWrapper.add(widget);
panel.add(widgetWrapper);
- if (showTimestamp && valueHolder instanceof AbstractValueTimestampHolder) {
- AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;
- TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp().orElse(null));
- panel.add(timestampLabel);
- }
+ if (showTimestamp)
+ addTimestampLabel(valueHolder, panel);
return () -> panel;
}
@@ -203,11 +193,8 @@ public final class ValueEditors {
widgetWrapper.setStyleName("flex layout horizontal center");
widgetWrapper.add(widget);
panel.add(widgetWrapper);
- if (showTimestamp && valueHolder instanceof AbstractValueTimestampHolder) {
- AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;
- TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp().orElse(null));
- panel.add(timestampLabel);
- }
+ if (showTimestamp)
+ addTimestampLabel(valueHolder, panel);
return () -> panel;
}
@@ -230,11 +217,8 @@ public final class ValueEditors {
widgetWrapper.setStyleName("flex layout horizontal center");
widgetWrapper.add(widget);
panel.add(widgetWrapper);
- if (showTimestamp && valueHolder instanceof AbstractValueTimestampHolder) {
- AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;
- TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp().orElse(null));
- panel.add(timestampLabel);
- }
+ if (showTimestamp)
+ addTimestampLabel(valueHolder, panel);
return () -> panel;
}
@@ -260,11 +244,8 @@ public final class ValueEditors {
widgetWrapper.setStyleName("flex layout horizontal center");
widgetWrapper.add(widget);
panel.add(widgetWrapper);
- if (showTimestamp && valueHolder instanceof AbstractValueTimestampHolder) {
- AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;
- TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp().orElse(null));
- panel.add(timestampLabel);
- }
+ if (showTimestamp)
+ addTimestampLabel(valueHolder, panel);
return () -> panel;
}
@@ -291,11 +272,8 @@ public final class ValueEditors {
widgetWrapper.setStyleName("flex layout horizontal center");
widgetWrapper.add(widget);
panel.add(widgetWrapper);
- if (showTimestamp && valueHolder instanceof AbstractValueTimestampHolder) {
- AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;
- TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp().orElse(null));
- panel.add(timestampLabel);
- }
+ if (showTimestamp)
+ addTimestampLabel(valueHolder, panel);
return () -> panel;
}
@@ -314,6 +292,14 @@ public final class ValueEditors {
showValidationError(environment, error.toString());
}
+ private static void addTimestampLabel(ValueHolder valueHolder, FlowPanel editorPanel) {
+ if (valueHolder instanceof AbstractValueTimestampHolder) {
+ AbstractValueTimestampHolder timestampHolder = (AbstractValueTimestampHolder) valueHolder;
+ TimestampLabel timestampLabel = new TimestampLabel(timestampHolder.getValueTimestamp().orElse(null));
+ editorPanel.add(timestampLabel);
+ }
+ }
+
private static IsWidget createStringEditorWidget(String styleName,
String currentValue,
String defaultValue,
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
index b0c76c6d0..542a3303f 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java
@@ -247,12 +247,11 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
.setParameter("ids", Arrays.asList(ids))
.getResultList();
List<String> names = new ArrayList<>();
- idLoop:
for (String id : ids) {
for (Object[] tuple: result) {
if (tuple[0].equals(id)) {
names.add((String) tuple[1]);
- break idLoop;
+ break;
}
}
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java
index 271ecc58a..7b21f5a4e 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/datapoint/AssetDatapointService.java
@@ -166,11 +166,9 @@ public class AssetDatapointService implements ContainerService, Consumer<AssetSt
try (ResultSet rs = st.executeQuery()) {
List<NumberDatapoint> result = new ArrayList<>();
while (rs.next()) {
- result.add(new NumberDatapoint(
- labelFunction.apply(rs.getTimestamp(1)),
- rs.getBigDecimal(2)
- )
- );
+ String label = labelFunction.apply(rs.getTimestamp(1));
+ Number value = rs.getObject(2) != null ? rs.getDouble(2) : null;
+ result.add(new NumberDatapoint(label, value));
}
return result.toArray(new NumberDatapoint[result.size()]);
}
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/AbstractManagerSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/AbstractManagerSetup.java
index a96b436cd..d19effd89 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/setup/AbstractManagerSetup.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/AbstractManagerSetup.java
@@ -118,36 +118,26 @@ public abstract class AbstractManagerSetup implements Setup {
new AssetAttribute("motionSensor", NUMBER)
.setMeta(
new MetaItem(LABEL, Values.create("Motion Sensor")),
- new MetaItem(DESCRIPTION, Values.create("Value is greater than zero when motion is sensed")),
+ new MetaItem(DESCRIPTION, Values.create("Greater than zero when motion is sensed")),
new MetaItem(READ_ONLY, Values.create(true)),
new MetaItem(RULE_STATE, Values.create(true)),
- new MetaItem(RULE_EVENT, Values.create(true)),
- new MetaItem(RULE_EVENT_EXPIRES, Values.create("1h"))
+ new MetaItem(STORE_DATA_POINTS, Values.create(true))
).addMeta(shouldBeLinked ? agentLinker.get() : null),
- new AssetAttribute("motionDetected", AttributeType.BOOLEAN)
+ new AssetAttribute("presenceDetected", AttributeType.BOOLEAN)
.setMeta(
- new MetaItem(LABEL, Values.create("Motion Detected")),
- new MetaItem(DESCRIPTION, Values.create("Someone is moving around in the room")),
+ new MetaItem(LABEL, Values.create("Presence Detected")),
+ new MetaItem(DESCRIPTION, Values.create("Someone is moving or resting in the room")),
new MetaItem(RULE_STATE, Values.create(true)),
new MetaItem(PROTECTED, Values.create(true)),
new MetaItem(READ_ONLY, Values.create(true)),
new MetaItem(SHOW_ON_DASHBOARD, Values.create(true))
),
- new AssetAttribute("lastMotionDetected", TIMESTAMP_MILLIS)
+ new AssetAttribute("lastPresenceDetected", TIMESTAMP_MILLIS)
.setMeta(
- new MetaItem(LABEL, Values.create("Last time someone moved in the room")),
+ new MetaItem(LABEL, Values.create("Last time someone was present in the room")),
new MetaItem(RULE_STATE, Values.create(true)),
new MetaItem(PROTECTED, Values.create(true)),
new MetaItem(READ_ONLY, Values.create(true))
- ),
- new AssetAttribute("presenceDetected", AttributeType.BOOLEAN)
- .setMeta(
- new MetaItem(LABEL, Values.create("Presence Detected")),
- new MetaItem(DESCRIPTION, Values.create("Someone is present in the room")),
- new MetaItem(RULE_STATE, Values.create(true)),
- new MetaItem(PROTECTED, Values.create(true)),
- new MetaItem(READ_ONLY, Values.create(true)),
- new MetaItem(SHOW_ON_DASHBOARD, Values.create(true))
)
);
}
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 6419f3a08..9dc07d265 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
@@ -53,7 +53,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
final protected boolean importDemoScenes;
// Update these numbers whenever you change a RULE_STATE flag in test data
- public static final int DEMO_RULE_STATES_APARTMENT_1 = 12;
+ public static final int DEMO_RULE_STATES_APARTMENT_1 = 14;
public static final int DEMO_RULE_STATES_APARTMENT_2 = 9;
public static final int DEMO_RULE_STATES_APARTMENT_3 = 0;
public static final int DEMO_RULE_STATES_SMART_HOME = DEMO_RULE_STATES_APARTMENT_1 + DEMO_RULE_STATES_APARTMENT_2 + DEMO_RULE_STATES_APARTMENT_3;
@@ -76,6 +76,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
public String apartment1Id;
public String apartment1ServiceAgentId;
public String apartment1LivingroomId;
+ public String apartment1KitchenId;
public String apartment2Id;
public String apartment3Id;
public String apartment2LivingroomId;
@@ -351,11 +352,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
.addMeta(
new MetaItem(
SimulatorProtocol.CONFIG_MODE,
- Values.create(SimulatorProtocol.Mode.WRITE_THROUGH_DELAYED.toString())
- ),
- new MetaItem(
- SimulatorProtocol.CONFIG_WRITE_DELAY_MILLISECONDS,
- Values.create(500)
+ Values.create(SimulatorProtocol.Mode.WRITE_THROUGH_IMMEDIATE.toString())
))
);
apartment1ServiceAgent = assetStorageService.merge(apartment1ServiceAgent);
@@ -386,6 +383,15 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
apartment1Livingroom = assetStorageService.merge(apartment1Livingroom);
apartment1LivingroomId = apartment1Livingroom.getId();
+ ServerAsset apartment1Kitchen = createDemoApartmentRoom(apartment1, "Kitchen");
+ addDemoApartmentRoomMotionSensor(apartment1Kitchen, true, () -> new MetaItem[]{
+ new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()),
+ new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME))
+ });
+
+ apartment1Kitchen = assetStorageService.merge(apartment1Kitchen);
+ apartment1KitchenId = apartment1Kitchen.getId();
+
if (importDemoScenes) {
Scene[] scenes = new Scene[]{
new Scene("homeScene", "Home scene", "HOME", "0 0 7 ? *", false, 21d),
@@ -395,7 +401,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
};
ServerAsset demoApartmentSceneAgent = createDemoApartmentSceneAgent(
- apartment1, scenes, apartment1Livingroom
+ apartment1, scenes, apartment1Livingroom, apartment1Kitchen
);
demoApartmentSceneAgent = assetStorageService.merge(demoApartmentSceneAgent);
@@ -527,6 +533,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
identityService.getIdentityProvider().setRestrictedUser(keycloakDemoSetup.testuser3Id, true);
assetStorageService.storeUserAsset(keycloakDemoSetup.testuser3Id, apartment1Id);
assetStorageService.storeUserAsset(keycloakDemoSetup.testuser3Id, apartment1LivingroomId);
+ assetStorageService.storeUserAsset(keycloakDemoSetup.testuser3Id, apartment1KitchenId);
assetStorageService.storeUserAsset(keycloakDemoSetup.testuser3Id, apartment2Id);
// ################################ Demo assets for 'customerC' realm ###################################
diff --git a/manager/server/src/main/resources/demo/rules/DemoApartmentNotifyAlarmTrigger.drl b/manager/server/src/main/resources/demo/rules/DemoApartmentNotifyAlarmTrigger.drl
index abb5bc726..7b808d56d 100644
--- a/manager/server/src/main/resources/demo/rules/DemoApartmentNotifyAlarmTrigger.drl
+++ b/manager/server/src/main/resources/demo/rules/DemoApartmentNotifyAlarmTrigger.drl
@@ -17,7 +17,7 @@ declare AlarmTrigger
roomName : String
end
-// Notify the user every 30 mninutes while alarm is triggered
+// Notify the user every 30 minutes while alarm is triggered
declare UserNotified
@role(event)
@expires(30m)
@@ -39,7 +39,7 @@ rule "Stop alarm when alarm has been triggered and no presence is detected in an
when
$residence : AssetState(type == AssetType.RESIDENCE, attributeName == "alarmEnabled")
$alarmTrigger : AlarmTrigger(residenceId == $residence.id)
- $room : AssetState(parentId == $residence.id, type == AssetType.ROOM, attributeName == "presenceDetected", valueFalse)
+ not AssetState(parentId == $residence.id, type == AssetType.ROOM, attributeName == "presenceDetected", valueTrue)
then
delete($alarmTrigger);
end
diff --git a/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetection.drl b/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetection.drl
index 94b136e5d..221f09e08 100644
--- a/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetection.drl
+++ b/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetection.drl
@@ -10,60 +10,42 @@ global java.util.logging.Logger LOG;
global org.openremote.model.rules.Assets assets;
/*
-Uses 'motionSensor' and optional 'co2Level' of a room asset to set the 'motionDetected',
-'lastMotionDetected', and 'presenceDetected' attributes of the room. Motion detection
-is based on multiple triggers of the motion sensor over a time window. Presence
-detection is based on motion detection, and increasing CO2 level over a time window.
+Uses 'motionSensor' and optional 'co2Level' of a room asset to set the 'presenceDetected'
+and 'lastPresenceDetected' attributes of the room. Presence detection is based on motion
+sensing and if available for a room, increasing CO2 level over a time window. The assumption
+is that the 'motionSensor' is set to 0 or 1, depending on whether motion has been detected
+in a room over a time window that is internal to the sensor (e.g. the last minute).
*/
-rule "Set motion detected flag of room when motion sensor has been triggered"
-when
- // A room were the motion detected flag is not set
- $room: AssetState(type == AssetType.ROOM, attributeName == "motionDetected", valueFalse)
- // And the motion sensor has been triggered at least 3 times in the last 2 minutes
- accumulate(
- AssetEvent(id == $room.id, attributeName == "motionSensor", isValueGreaterThan(0)) over window:time(2m);
- $motionTriggers: count(1);
- $motionTriggers >= 3
- )
-then
- // Set the motion detected flag of the room
- assets.dispatch(
- new AttributeEvent($room.getId(), "motionDetected", Values.create(true))
- );
-end
-rule "Update the motion detected timestamp when motion sensor has been triggered"
+rule "Set presence detected flag of room when motion is detected and no CO2 sensor exists"
when
- // A room were the motion detected flag is set
- $room : AssetState(type == AssetType.ROOM, attributeName == "motionDetected", valueTrue)
+ // A room were the presence detected flag is not set
+ $room: AssetState(type == AssetType.ROOM, attributeName == "presenceDetected", valueFalse)
// And the motion sensor has been triggered
- AssetState(id == $room.id, attributeName == "motionSensor", isValueGreaterThan(0), $lastTriggerTimestamp: valueTimestamp)
- // And the last sensor trigger event is newer than the recorded last detected time
- AssetState(id == $room.id, attributeName == "lastMotionDetected", isValueLessThan($lastTriggerTimestamp))
+ AssetState(id == $room.id, attributeName == "motionSensor", isValueGreaterThan(0))
+ // And the room does not have a CO2 sensor
+ not AssetState(id == $room.id, attributeName == "co2Level")
then
- // Update the last presence detected timestamp to the latest motion sensor trigger event
+ // Set the presence detected flag of the room
assets.dispatch(
- new AttributeEvent($room.getId(), "lastMotionDetected", Values.create($lastTriggerTimestamp))
+ new AttributeEvent($room.getId(), "presenceDetected", Values.create(true))
);
end
-rule "Clear motion detected flag of a room if the motion sensor hasn't been triggered"
+
+rule "Clear presence detected flag of room if no motion is detected and no CO2 sensor exists"
when
- // A room were the motion detected flag is set
- $room: AssetState(type == AssetType.ROOM, attributeName == "motionDetected", valueTrue)
- // And the room has a motion sensor
- AssetState(id == $room.id, attributeName == "motionSensor")
- // And the motion sensor was not triggered in the last 15 minutes
- accumulate(
- AssetEvent(id == $room.id, attributeName == "motionSensor", isValueGreaterThan(0)) over window:time(15m);
- $motionTriggers: count(1);
- $motionTriggers == 0
- )
+ // A room where the presence detected flag is set
+ $room: AssetState(type == AssetType.ROOM, attributeName == "presenceDetected", valueTrue)
+ // And the motion sensor has not been triggered
+ AssetState(id == $room.id, attributeName == "motionSensor", value == null || valueAsNumber == 0)
+ // And the room does not have a CO2 sensor
+ not AssetState(id == $room.id, attributeName == "co2Level")
then
- // Clear the motion detected flag of the room
+ // Clear the presence detected flag of the room
assets.dispatch(
- new AttributeEvent($room.getId(), "motionDetected", Values.create(false))
+ new AttributeEvent($room.getId(), "presenceDetected", Values.create(false))
);
end
@@ -72,9 +54,9 @@ rule "Set presence detected flag of room when motion is detected and confirmed w
when
// A room were the presence detected flag is not set
$room: AssetState(type == AssetType.ROOM, attributeName == "presenceDetected", valueFalse)
- // And the motion detected flag is set
- AssetState(id == $room.id, attributeName == "motionDetected", valueTrue)
- // And the CO2 level increased at least 2 times in the last 11 minutes
+ // And the motion sensor has been triggered
+ AssetState(id == $room.id, attributeName == "motionSensor", isValueGreaterThan(0))
+ // And the CO2 level has increased at least 2 times in the last 11 minutes
accumulate(
AssetEvent(id == $room.id, attributeName == "co2Level", valueGreaterThanOldValue) over window:time(11m);
$increasedCO2: count(1);
@@ -88,15 +70,15 @@ then
end
-rule "Clear presence detected flag of a room if no motion or CO2 increase was sensed in a while"
+rule "Clear presence detected flag of room if no motion or CO2 increase was sensed in a while"
when
- // A room weare the presence detected flag is set
+ // A room where the presence detected flag is set
$room: AssetState(type == AssetType.ROOM, attributeName == "presenceDetected", valueTrue)
- // And the motion detected flag is not set
- AssetState(id == $room.id, attributeName == "motionDetected", valueFalse)
+ // And the motion sensor has not been triggered
+ AssetState(id == $room.id, attributeName == "motionSensor", value == null || valueAsNumber == 0)
// And the room has a CO2 sensor
AssetState(id == $room.id, attributeName == "co2Level")
- // And the CO2 level was not increased in the last 11 minutes
+ // And the CO2 level has not increased in the last 11 minutes
accumulate(
AssetEvent(id == $room.id, attributeName == "co2Level", valueGreaterThanOldValue) over window:time(11m);
$increasedCO2: count(1);
@@ -108,3 +90,21 @@ then
new AttributeEvent($room.getId(), "presenceDetected", Values.create(false))
);
end
+
+
+rule "Update presence detected timestamp of room with last trigger of motion sensor"
+when
+ // A room were the presence detected flag is set
+ $room : AssetState(type == AssetType.ROOM, attributeName == "presenceDetected", valueTrue)
+ // And the motion sensor has been triggered
+ AssetState(id == $room.id, attributeName == "motionSensor", isValueGreaterThan(0), $lastTriggerTimestamp: valueTimestamp)
+ // And the last sensor trigger event is newer than the recorded last detected time
+ AssetState(id == $room.id, attributeName == "lastPresenceDetected", isValueLessThan($lastTriggerTimestamp))
+then
+ // Update the last presence detected timestamp to the latest motion sensor trigger event
+ assets.dispatch(
+ new AttributeEvent($room.getId(), "lastPresenceDetected", Values.create($lastTriggerTimestamp))
+ );
+end
+
+
diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
index 8f61ed8e4..bf500a3ca 100644
--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
@@ -511,7 +511,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
def assets = assetResource.getCurrentUserAssets(null)
then: "result should match"
- assets.length == 3
+ assets.length == 4
Asset apartment1 = assets[0]
apartment1.id == managerDemoSetup.apartment1Id
apartment1.name == "Apartment 1"
@@ -528,7 +528,11 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
apartment1Livingroom.id == managerDemoSetup.apartment1LivingroomId
apartment1Livingroom.name == "Living Room"
- Asset apartment2 = assets[2]
+ Asset apartment1Kitchen = assets[2]
+ apartment1Kitchen.id == managerDemoSetup.apartment1KitchenId
+ apartment1Kitchen.name == "Kitchen"
+
+ Asset apartment2 = assets[3]
apartment2.id == managerDemoSetup.apartment2Id
apartment2.name == "Apartment 2"
@@ -582,7 +586,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
apartment1Livingroom.id == managerDemoSetup.apartment1LivingroomId
apartment1Livingroom.name == "Living Room"
def protectedAttributes = apartment1Livingroom.getAttributesList()
- protectedAttributes.size() == 7
+ protectedAttributes.size() == 6
def currentTemperature = apartment1Livingroom.getAttribute("currentTemperature").get()
currentTemperature.getType().get() == AttributeType.TEMPERATURE_CELCIUS
!currentTemperature.getValue().isPresent()
diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
index 361290e1a..e6027cee1 100644
--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
@@ -221,10 +221,11 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
)
then: "result should match"
- assets.size() == 3
+ assets.size() == 4
assets.get(0).id == managerDemoSetup.apartment1Id
assets.get(1).id == managerDemoSetup.apartment1ServiceAgentId
assets.get(2).id == managerDemoSetup.apartment1LivingroomId
+ assets.get(3).id == managerDemoSetup.apartment1KitchenId
when: "a query is executed"
assets = assetStorageService.findAll(
@@ -234,8 +235,9 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
)
then: "result should match"
- assets.size() == 1
+ assets.size() == 2
assets.get(0).id == managerDemoSetup.apartment1LivingroomId
+ assets.get(1).id == managerDemoSetup.apartment1KitchenId
when: "a query is executed"
assets = assetStorageService.findAll(
@@ -243,15 +245,16 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
)
then: "result should match"
- assets.size() == 3
+ assets.size() == 4
assets.get(0).id == managerDemoSetup.apartment1Id
assets.get(1).id == managerDemoSetup.apartment1LivingroomId
- assets.get(1).getAttributesList().size() == 7
+ assets.get(1).getAttributesList().size() == 6
!assets.get(1).getAttribute("currentTemperature").get().getValue().isPresent()
assets.get(1).getAttribute("currentTemperature").get().meta.size() == 6
!assets.get(1).getAttribute("targetTemperature").get().getValue().isPresent()
assets.get(1).getAttribute("targetTemperature").get().meta.size() == 4
- assets.get(2).id == managerDemoSetup.apartment2Id
+ assets.get(2).id == managerDemoSetup.apartment1KitchenId
+ assets.get(3).id == managerDemoSetup.apartment2Id
when: "a query is executed"
assets = assetStorageService.findAll(
@@ -411,7 +414,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset = assetStorageService.find(
new AssetQuery()
.id(managerDemoSetup.apartment1LivingroomId)
- .select(new Select("co2Level", "lastMotionDetected", "motionSensor").loadComplete(true))
+ .select(new Select("co2Level", "lastPresenceDetected", "motionSensor").loadComplete(true))
)
then: "result should match"
@@ -431,16 +434,16 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset.getAttributesList().size() == 3
asset.getAttribute("co2Level").isPresent()
asset.getAttribute("co2Level").get().meta.size() == 11
- asset.getAttribute("lastMotionDetected").isPresent()
- asset.getAttribute("lastMotionDetected").get().meta.size() == 4
+ asset.getAttribute("lastPresenceDetected").isPresent()
+ asset.getAttribute("lastPresenceDetected").get().meta.size() == 4
asset.getAttribute("motionSensor").isPresent()
- asset.getAttribute("motionSensor").get().meta.size() == 8
+ asset.getAttribute("motionSensor").get().meta.size() == 7
when: "a query is executed to select a subset of protected attributes"
asset = assetStorageService.find(
new AssetQuery()
.id(managerDemoSetup.apartment1LivingroomId)
- .select(new Select("co2Level", "lastMotionDetected", "motionSensor").loadComplete(true).filterProtected(true))
+ .select(new Select("co2Level", "lastPresenceDetected", "motionSensor").loadComplete(true).filterProtected(true))
)
then: "result should contain only matches that are protected"
@@ -460,8 +463,8 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset.getAttributesList().size() == 2
asset.getAttribute("co2Level").isPresent()
asset.getAttribute("co2Level").get().meta.size() == 8
- asset.getAttribute("lastMotionDetected").isPresent()
- asset.getAttribute("lastMotionDetected").get().meta.size() == 3
+ asset.getAttribute("lastPresenceDetected").isPresent()
+ asset.getAttribute("lastPresenceDetected").get().meta.size() == 3
!asset.getAttribute("motionSensor").isPresent()
cleanup: "the server should be stopped"
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentPresenceDetectionTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentPresenceDetectionTest.groovy
index aa4d3c4e6..7fc020ce3 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentPresenceDetectionTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentPresenceDetectionTest.groovy
@@ -23,7 +23,7 @@ import static org.openremote.model.attribute.AttributeEvent.Source.SENSOR
class ApartmentPresenceDetectionTest extends Specification implements ManagerContainerTrait {
- def "Motion detection with motion sensor"() {
+ def "Presence detection with motion sensor"() {
given: "the container environment is started"
def conditions = new PollingConditions(timeout: 10, delay: 1)
@@ -31,12 +31,10 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
def container = startContainerWithPseudoClock(defaultConfig(serverPort), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def rulesService = container.getService(RulesService.class)
- def assetProcessingService = container.getService(AssetProcessingService.class)
def assetStorageService = container.getService(AssetStorageService.class)
def rulesetStorageService = container.getService(RulesetStorageService.class)
def simulatorProtocol = container.getService(SimulatorProtocol.class)
RulesEngine apartment1Engine = null
- List<AssetEvent> insertedAssetEvents = []
and: "some rules"
Ruleset ruleset = new AssetRuleset(
@@ -52,110 +50,65 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
assert apartment1Engine != null
assert apartment1Engine.isRunning()
assert apartment1Engine.knowledgeSession.factCount == DEMO_RULE_STATES_APARTMENT_1
- apartment1Engine.assetEventsConsumer = { assetEvent ->
- insertedAssetEvents << assetEvent
- }
- }
-
- and: "the motion detected flag and timestamp of the room should not be set"
- def livingRoomAsset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
- assert !livingRoomAsset.getAttribute("motionDetected").get().getValue().isPresent()
- assert !livingRoomAsset.getAttribute("lastMotionDetected").get().getValue().isPresent()
-
- when: "someone enters and leaves the room a few times"
- insertedAssetEvents = []
- // The motion sensor triggers 5 times, 3 minutes apart
- for (i in 1..5) {
- // Use the loop i as value so we can identify and test if we have processed this event
- def motionSensorTrigger = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "motionSensor", Values.create(i), getClockTimeOf(apartment1Engine)
- )
-
- // Use the simulator to inject the update
- simulatorProtocol.putValue(motionSensorTrigger)
-
- // Wait until rules engine completes work asynchronously, must have processed the event
- new PollingConditions(timeout: 5, delay: 0.5).eventually {
- assert insertedAssetEvents.any() { it.matches(motionSensorTrigger, SENSOR, true) }
- // And wait until we have processed resulting events due to rules firing
- assert noEventProcessedIn(assetProcessingService, 500)
- }
-
- advancePseudoClocks(3, MINUTES, container, apartment1Engine)
}
- then: "motion should not be detected"
- new PollingConditions(initialDelay: 3).eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
- assert !asset.getAttribute("motionDetected").get().getValue().isPresent()
- assert !asset.getAttribute("lastMotionDetected").get().getValue().isPresent()
- assert !asset.getAttribute("presenceDetected").get().getValue().isPresent()
- }
+ and: "the presence detected flag and timestamp of the room should not be set"
+ def roomAsset = assetStorageService.find(managerDemoSetup.apartment1KitchenId, true)
+ assert !roomAsset.getAttribute("presenceDetected").get().getValue().isPresent()
+ assert !roomAsset.getAttribute("lastPresenceDetected").get().getValue().isPresent()
- when: "time is advanced enough for event expiration"
- advancePseudoClocks(2, HOURS, container, apartment1Engine)
+ when: "motion sensor is triggered"
+ double expectedLastPresenceDetected = getClockTimeOf(apartment1Engine)
+ def motionSensorTrigger = new AttributeEvent(
+ managerDemoSetup.apartment1KitchenId, "motionSensor", Values.create(1)
+ )
+ simulatorProtocol.putValue(motionSensorTrigger)
- then: "the events should have been expired and retracted automatically from the knowledge session"
+ then: "presence should be detected"
conditions.eventually {
- assert apartment1Engine.knowledgeSession.factCount == DEMO_RULE_STATES_APARTMENT_1
+ def asset = assetStorageService.find(managerDemoSetup.apartment1KitchenId, true)
+ assert asset.getAttribute("presenceDetected").get().getValueAsBoolean().get()
+ assert asset.getAttribute("lastPresenceDetected").get().getValueAsNumber().get() == expectedLastPresenceDetected
}
- when: "someone is moving around in the room"
- insertedAssetEvents = []
- double expectedLastMotionTimestamp = 0d
- // The motion sensor triggers 5 times, 30 seconds apart
- for (i in 1..5) {
-
- def motionSensorTrigger = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "motionSensor", Values.create(i), getClockTimeOf(apartment1Engine)
- )
- simulatorProtocol.putValue(motionSensorTrigger)
+ when: "time advances"
+ advancePseudoClocks(5, MINUTES, container, apartment1Engine)
- new PollingConditions(timeout: 5, delay: 0.5).eventually {
- assert insertedAssetEvents.any() {
- expectedLastMotionTimestamp = it.valueTimestamp
- it.matches(motionSensorTrigger, SENSOR, true)
- }
- assert noEventProcessedIn(assetProcessingService, 500)
- }
-
- advancePseudoClocks(30, SECONDS, container, apartment1Engine)
- }
+ and: "motion sensor is triggered"
+ expectedLastPresenceDetected = getClockTimeOf(apartment1Engine)
+ motionSensorTrigger = new AttributeEvent(
+ managerDemoSetup.apartment1KitchenId, "motionSensor", Values.create(1)
+ )
+ simulatorProtocol.putValue(motionSensorTrigger)
- then: "motion should be detected and the last motion counter increment is the last motion timestamp"
+ then: "presence should be detected and timestamp updated"
conditions.eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
- assert asset.getAttribute("motionDetected").get().getValueAsBoolean().get()
- assert asset.getAttribute("lastMotionDetected").get().getValueAsNumber().isPresent()
- assert asset.getAttribute("lastMotionDetected").get().getValueAsNumber().get() == expectedLastMotionTimestamp
- assert !asset.getAttribute("presenceDetected").get().getValue().isPresent()
+ def asset = assetStorageService.find(managerDemoSetup.apartment1KitchenId, true)
+ assert asset.getAttribute("presenceDetected").get().getValueAsBoolean().get()
+ assert asset.getAttribute("lastPresenceDetected").get().getValueAsNumber().get() == expectedLastPresenceDetected
}
- when: "there is no motion sensed for a while"
- advancePseudoClocks(20, MINUTES, container, apartment1Engine)
-
- then: "no motion should be detected but the last timestamp still available"
- conditions.eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
- assert !asset.getAttribute("motionDetected").get().getValueAsBoolean().get()
- assert asset.getAttribute("lastMotionDetected").get().getValueAsNumber().isPresent()
- assert asset.getAttribute("lastMotionDetected").get().getValueAsNumber().get() == expectedLastMotionTimestamp
- assert !asset.getAttribute("presenceDetected").get().getValue().isPresent()
- }
+ when: "time advances"
+ advancePseudoClocks(5, MINUTES, container, apartment1Engine)
- when: "time is advanced enough for event expiration"
- advancePseudoClocks(2, HOURS, container, apartment1Engine)
+ and: "motion sensor is not triggered"
+ def motionSensorNoTrigger = new AttributeEvent(
+ managerDemoSetup.apartment1KitchenId, "motionSensor", Values.create(0)
+ )
+ simulatorProtocol.putValue(motionSensorNoTrigger)
- then: "the events should have been expired and retracted automatically from the knowledge session"
+ then: "no presence should be detected but the last timestamp still available"
conditions.eventually {
- assert apartment1Engine.knowledgeSession.factCount == DEMO_RULE_STATES_APARTMENT_1
+ def asset = assetStorageService.find(managerDemoSetup.apartment1KitchenId, true)
+ assert !asset.getAttribute("presenceDetected").get().getValueAsBoolean().get()
+ assert asset.getAttribute("lastPresenceDetected").get().getValueAsNumber().get() == expectedLastPresenceDetected
}
cleanup: "the server should be stopped"
stopContainer(container)
}
- def "Motion detection with motion sensor and presence confirmation with CO2 level"() {
+ def "Presence detection with motion sensor and confirmation with CO2 level"() {
given: "the container environment is started"
def conditions = new PollingConditions(timeout: 10, delay: 1)
@@ -189,41 +142,39 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
}
}
- and: "the presence detected flag of the room should not be set"
- def livingRoomAsset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
- assert !livingRoomAsset.getAttribute("presenceDetected").get().getValue().isPresent()
-
- when: "someone is moving around in the room"
- insertedAssetEvents = []
- double expectedLastMotionTimestamp = 0d
- // The motion sensor triggers 5 times, 30 seconds apart
- for (i in 1..5) {
-
- def motionSensorTrigger = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "motionSensor", Values.create(i), getClockTimeOf(apartment1Engine)
- )
- simulatorProtocol.putValue(motionSensorTrigger)
+ and: "the presence detected flag and timestamp of the room should not be set"
+ def roomAsset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
+ assert !roomAsset.getAttribute("presenceDetected").get().getValue().isPresent()
+ assert !roomAsset.getAttribute("lastPresenceDetected").get().getValue().isPresent()
- new PollingConditions(timeout: 5, delay: 0.5).eventually {
- assert insertedAssetEvents.any() {
- expectedLastMotionTimestamp = it.valueTimestamp
- it.matches(motionSensorTrigger, SENSOR, true)
- }
- assert noEventProcessedIn(assetProcessingService, 500)
- }
+ when: "motion sensor is triggered"
+ double expectedLastPresenceDetected = getClockTimeOf(apartment1Engine)
+ def motionSensorTrigger = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomId, "motionSensor", Values.create(1)
+ )
+ simulatorProtocol.putValue(motionSensorTrigger)
- advancePseudoClocks(30, SECONDS, container, apartment1Engine)
+ then: "presence should not be detected"
+ new PollingConditions(initialDelay: 3, timeout: 5, delay: 1).eventually {
+ def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
+ assert !asset.getAttribute("presenceDetected").get().getValue().isPresent()
+ assert !asset.getAttribute("lastPresenceDetected").get().getValue().isPresent()
}
- and: "someone is not moving but still present in the room"
+ when: "time advances"
+ advancePseudoClocks(5, MINUTES, container, apartment1Engine)
+
+ and: "the CO2 level increases"
+ insertedAssetEvents = []
// The CO2 level increments 3 times, 5 minutes apart
for (i in 1..3) {
def co2LevelIncrement = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "co2Level", Values.create(400 + i), getClockTimeOf(apartment1Engine)
+ managerDemoSetup.apartment1LivingroomId, "co2Level", Values.create(400 + i)
)
simulatorProtocol.putValue(co2LevelIncrement)
+ // Wait for event and rule consequences to be processed
new PollingConditions(timeout: 5, delay: 0.5).eventually {
assert insertedAssetEvents.any() {
it.matches(co2LevelIncrement, SENSOR, true)
@@ -237,51 +188,24 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
then: "presence should be detected and the last motion sensor trigger is the last detected timestamp"
conditions.eventually {
def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
- assert asset.getAttribute("motionDetected").get().getValueAsBoolean().get()
- assert asset.getAttribute("lastMotionDetected").get().getValueAsNumber().isPresent()
- assert asset.getAttribute("lastMotionDetected").get().getValueAsNumber().get() == expectedLastMotionTimestamp
assert asset.getAttribute("presenceDetected").get().getValueAsBoolean().get()
+ assert asset.getAttribute("lastPresenceDetected").get().getValueAsNumber().get() == expectedLastPresenceDetected
}
- when: "someone stays in the room but doesn't move"
- insertedAssetEvents = []
- // The CO2 level increments 5 times, 5 minutes apart
- for (i in 1..5) {
-
- def co2LevelIncrement = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "co2Level", Values.create(500 + i), getClockTimeOf(apartment1Engine)
- )
- simulatorProtocol.putValue(co2LevelIncrement)
-
- new PollingConditions(timeout: 5, delay: 0.5).eventually {
- assert insertedAssetEvents.any() {
- it.matches(co2LevelIncrement, SENSOR, true)
- }
- assert noEventProcessedIn(assetProcessingService, 500)
- }
-
- advancePseudoClocks(5, MINUTES, container, apartment1Engine)
- }
-
- then: "presence should still be detected but no motion"
- conditions.eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
- assert !asset.getAttribute("motionDetected").get().getValueAsBoolean().get()
- assert asset.getAttribute("lastMotionDetected").get().getValueAsNumber().isPresent()
- assert asset.getAttribute("lastMotionDetected").get().getValueAsNumber().get() == expectedLastMotionTimestamp
- assert asset.getAttribute("presenceDetected").get().getValueAsBoolean().get()
- }
+ when: "motion sensor is not triggered"
+ def motionSensorNoTrigger = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomId, "motionSensor", Values.create(0)
+ )
+ simulatorProtocol.putValue(motionSensorNoTrigger)
- when: "there is no CO2 level increase for a while"
+ and: "there is no CO2 level increase for a while"
advancePseudoClocks(20, MINUTES, container, apartment1Engine)
then: "presence should be gone but the last timestamp still available"
conditions.eventually {
def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
- assert !asset.getAttribute("motionDetected").get().getValueAsBoolean().get()
- assert asset.getAttribute("lastMotionDetected").get().getValueAsNumber().isPresent()
- assert asset.getAttribute("lastMotionDetected").get().getValueAsNumber().get() == expectedLastMotionTimestamp
assert !asset.getAttribute("presenceDetected").get().getValueAsBoolean().get()
+ assert asset.getAttribute("lastPresenceDetected").get().getValueAsNumber().get() == expectedLastPresenceDetected
}
when: "time is advanced enough for event expiration"
diff --git a/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java b/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java
index b83f34d2f..3e5b1f598 100644
--- a/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java
+++ b/model/src/main/java/org/openremote/model/asset/AbstractAssetUpdate.java
@@ -268,16 +268,9 @@ public abstract class AbstractAssetUpdate {
/**
* <code>true</code> if this value is not null and that value is null or this value is greater than that value.
*/
- public boolean isValueGreaterThan(Double that) {
+ public boolean isValueGreaterThan(Number that) {
Double number = getValueAsNumber();
- return (number != null && that == null) || (number != null && number > that);
- }
-
- /**
- * <code>true</code> if this value is not null and that value is null or this value is greater than that value.
- */
- public boolean isValueGreaterThan(Long that) {
- return isValueGreaterThan(that != null ? (double) that : null);
+ return (number != null && that == null) || (number != null && number > that.doubleValue());
}
/**
@@ -290,16 +283,9 @@ public abstract class AbstractAssetUpdate {
/**
* <code>true</code> if this value is null and that value is not null or this value is less than that value.
*/
- public boolean isValueLessThan(Double that) {
+ public boolean isValueLessThan(Number that) {
Double number = getValueAsNumber();
- return (number == null && that != null) || (number != null && number < that);
- }
-
- /**
- * <code>true</code> if this value is null and that value is not null or this value is less than that value.
- */
- public boolean isValueLessThan(Long that) {
- return isValueLessThan(that != null ? (double) that : null);
+ return (number == null && that != null) || (number != null && number < that.doubleValue());
}
/**
diff --git a/postgresql/entrypoint.sh b/postgresql/entrypoint.sh
index 899fb4126..ce8a6eafa 100644
--- a/postgresql/entrypoint.sh
+++ b/postgresql/entrypoint.sh
@@ -15,7 +15,9 @@ if ! [ -f $PGDATA/postgresql.conf ]; then
gosu postgres ${PG_BIN}/initdb --auth='ident' -E UTF8
chown -R postgres:postgres ${PGDATA}
- # Allow IPv4 authenticated remote connections
+ # Trust all local connections, allow authenticated IPv4 remote connections
+ echo "local all all trust" > ${PGDATA}/pg_hba.conf
+ echo "host all all 127.0.0.1/32 trust" >> ${PGDATA}/pg_hba.conf
echo "host all all 0.0.0.0/0 md5" >> ${PGDATA}/pg_hba.conf
echo "listen_addresses = '0.0.0.0'" >> ${PGDATA}/postgresql.conf
diff --git a/profile/demo.yml b/profile/demo.yml
index 35de05daa..83f84dd4c 100644
--- a/profile/demo.yml
+++ b/profile/demo.yml
@@ -156,6 +156,9 @@ services:
POSTGRES_USER: openremote
POSTGRES_PASSWORD: CHANGE_ME_DB_USER_PASSWORD
+ # You can open an SQL console on a running container with:
+ # docker exec -it <container ID> psql -U openremote
+
# Durable data requires a volume mapping on your Docker host
# volumes:
# - /path/to/data/on/my/host:/var/lib/pgsql/data
diff --git a/profile/demo_rpi.yml b/profile/demo_rpi.yml
index 5aa3cc49a..7f2ac2e1b 100644
--- a/profile/demo_rpi.yml
+++ b/profile/demo_rpi.yml
@@ -113,6 +113,9 @@ services:
POSTGRES_USER: openremote
POSTGRES_PASSWORD: CHANGE_ME_DB_USER_PASSWORD
+ # You can open an SQL console on a running container with:
+ # docker exec -it <container ID> psql -U openremote
+
# Durable data requires a volume mapping on your Docker host
# volumes:
# - /path/to/data/on/my/host:/var/lib/pgsql/data