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
More tests fixed
Christian Bauer30eb1c9833a2
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.javaindex 8080a9c9a..b0175d6a0 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@@ -315,7 +315,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {new MetaItem(AssetMeta.DESCRIPTION, Values.create("Send notifications when presence is detected")),new MetaItem(AssetMeta.RULE_STATE, Values.create(true)))),- new AssetAttribute("vacationDays", AttributeType.INTEGER, null)+ new AssetAttribute("vacationDays", AttributeType.INTEGER).setMeta(new Meta(new MetaItem(AssetMeta.LABEL, Values.create("Vacation Days")),new MetaItem(AssetMeta.DESCRIPTION, Values.create("Enable vacation mode for given days")),@@ -438,7 +438,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {new MetaItem(AssetMeta.LABEL, Values.create("Waking up on Saturday")),new MetaItem(AssetMeta.RULE_STATE, Values.create(true))),- new AssetAttribute("awaySceneSATURDAY", AttributeType.STRING, null)+ new AssetAttribute("awaySceneSATURDAY", AttributeType.STRING).setMeta(new MetaItem(AssetMeta.LABEL, Values.create("Going to work on Saturday")),new MetaItem(AssetMeta.RULE_STATE, Values.create(true))@@ -458,7 +458,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {new MetaItem(AssetMeta.LABEL, Values.create("Waking up on Sunday")),new MetaItem(AssetMeta.RULE_STATE, Values.create(true))),- new AssetAttribute("awaySceneSUNDAY", AttributeType.STRING, null)+ new AssetAttribute("awaySceneSUNDAY", AttributeType.STRING).setMeta(new MetaItem(AssetMeta.LABEL, Values.create("Going to work on Sunday")),new MetaItem(AssetMeta.RULE_STATE, Values.create(true))@@ -487,13 +487,13 @@ public class ManagerDemoSetup extends AbstractManagerSetup {new MetaItem(AssetMeta.RULE_STATE, Values.create(true)),new MetaItem(AssetMeta.RULE_EVENT, Values.create(true)))),- new AssetAttribute("presenceDetected", AttributeType.BOOLEAN, Values.create(false))+ new AssetAttribute("presenceDetected", AttributeType.BOOLEAN).setMeta(new Meta(new MetaItem(AssetMeta.LABEL, Values.create("Presence Detected")),new MetaItem(AssetMeta.DESCRIPTION, Values.create("Someone is currently present in the room")),new MetaItem(AssetMeta.RULE_STATE, Values.create(true)))),- new AssetAttribute("lastPresenceDetected", AttributeType.DECIMAL, null)+ new AssetAttribute("lastPresenceDetected", AttributeType.DECIMAL).setMeta(new MetaItem(AssetMeta.LABEL, Values.create("Last Presence Timestamp")),new MetaItem(AssetMeta.DESCRIPTION, Values.create("Timestamp of last detected presence")),@@ -510,7 +510,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {ServerAsset apartment1LivingroomThermostat = new ServerAsset("Living Room Thermostat", THING, apartment1Livingroom);apartment1LivingroomThermostat.setAttributes(- new AssetAttribute("currentTemperature", DECIMAL, null)+ new AssetAttribute("currentTemperature", DECIMAL).setMeta(new MetaItem(AssetMeta.LABEL,@@ -529,7 +529,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {new MetaItem("urn:thirdparty:bar", Values.create("BAR"))),- new AssetAttribute("comfortTemperature", DECIMAL, null)+ new AssetAttribute("comfortTemperature", DECIMAL).setMeta(new MetaItem(AssetMeta.LABEL,@@ -584,7 +584,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {)),new MetaItem(AssetMeta.RULE_STATE, Values.create(true))),- new AssetAttribute("lastPresenceDetected", AttributeType.DECIMAL, null)+ new AssetAttribute("lastPresenceDetected", AttributeType.DECIMAL).setMeta(new MetaItem(AssetMeta.LABEL, Values.create("Last Presence Timestamp")),new MetaItem(AssetMeta.DESCRIPTION, Values.create(diff --git a/manager/server/src/main/resources/demo/rules/DemoApartmentAllLightsOff.drl b/manager/server/src/main/resources/demo/rules/DemoApartmentAllLightsOff.drlindex cdb095247..335b25a93 100644--- a/manager/server/src/main/resources/demo/rules/DemoApartmentAllLightsOff.drl+++ b/manager/server/src/main/resources/demo/rules/DemoApartmentAllLightsOff.drl@@ -11,7 +11,7 @@ global org.openremote.model.rules.Assets assets;rule "Switch room lights off when apartment ALL LIGHTS OFF push-button is pressed"when// In an asset of type RESIDENCE the All Lights Off push-button is pressed, which sends a 'true' value- $e: AssetEvent(attributeName == "allLightsOffSwitch", type == AssetType.RESIDENCE, valueAsBoolean )+ $e: AssetEvent(attributeName == "allLightsOffSwitch", type == AssetType.RESIDENCE, valueAsBoolean == true)thenassets.query() // Execute a query to get "other" assets.parent($e.getId()) // Where parent is the apartment in LHSdiff --git a/manager/server/src/main/resources/demo/rules/DemoApartmentNotificationWhenAlarm.drl b/manager/server/src/main/resources/demo/rules/DemoApartmentNotificationWhenAlarm.drlindex b59b5e6af..86159cdc3 100644--- a/manager/server/src/main/resources/demo/rules/DemoApartmentNotificationWhenAlarm.drl+++ b/manager/server/src/main/resources/demo/rules/DemoApartmentNotificationWhenAlarm.drl@@ -9,8 +9,8 @@ global org.openremote.model.rules.Assets assets;rule "Send notification when alarm triggered in a room"when- $residence : AssetState(type == AssetType.RESIDENCE, attributeName == "alarmEnabled", valueAsBoolean)- $room : AssetState(parentId == $residence.id, type == AssetType.ROOM, attributeName == "presenceDetected", valueAsBoolean)+ $residence : AssetState(type == AssetType.RESIDENCE, attributeName == "alarmEnabled", valueAsBoolean == true)+ $room : AssetState(parentId == $residence.id, type == AssetType.ROOM, attributeName == "presenceDetected", valueAsBoolean == true)then// users.storeAndNotify("todo", );enddiff --git a/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetectionCounter.drl b/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetectionCounter.drlindex 52872993f..f00c6f4ea 100644--- a/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetectionCounter.drl+++ b/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetectionCounter.drl@@ -21,7 +21,7 @@ when// A room has a motion counter$room : AssetState(type == AssetType.ROOM, attributeName == "motionCount")// And the presence detected flag is not set already- AssetState(id == $room.id, attributeName == "presenceDetected", !valueAsBoolean)+ AssetState(id == $room.id, attributeName == "presenceDetected", valueAsBoolean != true)// And at least 5 motion counter increments have been received in the last 10 minutesaccumulate(AssetEvent(id == $room.id, attributeName == "motionCount", valueAsNumber > 0) over window:time(10m);@@ -40,7 +40,7 @@ when// A room has a motion counter$room : AssetState(type == AssetType.ROOM, attributeName == "motionCount")// And the presence detected flag is set- AssetState(id == $room.id, attributeName == "presenceDetected", valueAsBoolean)+ AssetState(id == $room.id, attributeName == "presenceDetected", valueAsBoolean == true)// And at least 5 motion counter increments have been received in the last 10 minutesaccumulate(AssetEvent(id == $room.id, attributeName == "motionCount", valueAsNumber > 0, $ts: valueTimestamp) over window:time(10m);@@ -63,7 +63,7 @@ when// A room has a motion counter$room: AssetState(type == AssetType.ROOM, attributeName == "motionCount")// And the presence detected flag is set- AssetState(id == $room.id, attributeName == "presenceDetected", valueAsBoolean)+ AssetState(id == $room.id, attributeName == "presenceDetected", valueAsBoolean == true)// And no motion counter increments have been received in the last 10 minutesaccumulate(AssetEvent(id == $room.id, attributeName == "motionCount", valueAsNumber > 0) over window:time(10m);diff --git a/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetectionPIR.drl b/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetectionPIR.drlindex bac117d44..a5bf54124 100644--- a/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetectionPIR.drl+++ b/manager/server/src/main/resources/demo/rules/DemoApartmentPresenceDetectionPIR.drl@@ -21,10 +21,10 @@ when// A room has a motion sensor$room : AssetState(type == AssetType.ROOM, attributeName == "motionSensor")// And the presence detected flag is not set already- AssetState(id == $room.id, attributeName == "presenceDetected", !valueAsBoolean)+ AssetState(id == $room.id, attributeName == "presenceDetected", valueAsBoolean != true)// And at least 5 motion sensor triggers have been received in the last 10 minutesaccumulate(- AssetEvent(id == $room.id, attributeName == "motionSensor", valueAsBoolean) over window:time(10m);+ AssetEvent(id == $room.id, attributeName == "motionSensor", valueAsBoolean == true) over window:time(10m);$count: count(1);$count >= 5)@@ -38,9 +38,9 @@ endrule "Update the presence detected timestamp if motion sensor is triggered and we have already detected presence"when// The presence detected flag is set in a room- $room: AssetState(type == AssetType.ROOM, attributeName == "presenceDetected", valueAsBoolean)+ $room: AssetState(type == AssetType.ROOM, attributeName == "presenceDetected", valueAsBoolean == true)// And the motion sensor is triggered- $sensorState: AssetState(id == $room.id, attributeName == "motionSensor", valueAsBoolean)+ $sensorState: AssetState(id == $room.id, attributeName == "motionSensor", valueAsBoolean == true)then// Update the last presence detected timestamp of the roomassets.dispatch(@@ -53,10 +53,10 @@ when// A room has a motion sensor$room: AssetState(type == AssetType.ROOM, attributeName == "motionSensor")// And the presence detected flag is set- AssetState(id == $room.id, attributeName == "presenceDetected", valueAsBoolean)+ AssetState(id == $room.id, attributeName == "presenceDetected", valueAsBoolean == true)// And no motion sensor triggers have been received in the last 10 minutesaccumulate(- AssetEvent(id == $room.id, attributeName == "motionSensor", valueAsBoolean) over window:time(10m);+ AssetEvent(id == $room.id, attributeName == "motionSensor", valueAsBoolean == true) over window:time(10m);$count: count(1);$count == 0)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.groovyindex 714d2e904..2fca154ec 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@@ -18,10 +18,9 @@ import static java.util.concurrent.TimeUnit.*import static org.openremote.manager.server.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_APARTMENT_1import static org.openremote.manager.server.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_APARTMENT_2-// TODO: Fix this test, it doesn't work with null initial value on lastPresenceDetected attribute-class ApartmentPresenceDetectionTest extends Specification implements ManagerContainerTrait {+ // TODO: Rewrite with co2 level confirmation rules@Ignoredef "Detect presence with motion counter"() {@@ -154,7 +153,6 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerConstopContainer(container)}- @Ignoredef "Detect presence with motion sensor"() {given: "the container environment is started"@@ -178,8 +176,7 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerConand: "the presence detected flag and timestamp of the room should not be set"def livingRoomAsset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)assert !livingRoomAsset.getAttribute("presenceDetected").get().getValueAsBoolean().get()- assert livingRoomAsset.getAttribute("lastPresenceDetected").get().getValueAsDecimal().isPresent()- assert !livingRoomAsset.getAttribute("lastPresenceDetected").get().getValueAsDecimal().isPresent()+ assert !livingRoomAsset.getAttribute("lastPresenceDetected").get().getValueAsNumber().isPresent()when: "we have an events consumer for collecting test data"List<AssetEvent> insertedAssetEvents = []@@ -237,8 +234,7 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerConconditions.eventually {def asset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)assert asset.getAttribute("presenceDetected").get().getValueAsBoolean().get()- assert asset.getAttribute("lastPresenceDetected").get().getValueAsDecimal().isPresent()- assert asset.getAttribute("lastPresenceDetected").get().getValueAsDecimal().get() == expectedLastPresenceTimestamp+ assert asset.getAttribute("lastPresenceDetected").get().getValueAsNumber().orElse(null) == expectedLastPresenceTimestamp}when: "time moves on and we keep triggering the motion sensor in short intervals "@@ -260,8 +256,7 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerConconditions.eventually {def asset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)assert asset.getAttribute("presenceDetected").get().getValueAsBoolean().get()- assert asset.getAttribute("lastPresenceDetected").get().getValueAsDecimal().isPresent()- assert asset.getAttribute("lastPresenceDetected").get().getValueAsDecimal().get() == expectedLastPresenceTimestamp+ assert asset.getAttribute("lastPresenceDetected").get().getValueAsNumber().orElse(null) == expectedLastPresenceTimestamp}when: "time moves on without the motion sensor being triggered"@@ -271,7 +266,7 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerConconditions.eventually {def asset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)assert !asset.getAttribute("presenceDetected").get().getValueAsBoolean().get()- assert asset.getAttribute("lastPresenceDetected").get().getValueAsDecimal().get() == expectedLastPresenceTimestamp+ assert asset.getAttribute("lastPresenceDetected").get().getValueAsNumber().orElse(null) == expectedLastPresenceTimestamp}when: "time is advanced enough for event expiration"