Skip to content

armgit / core

Public Imported from GitHub
0

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

Some changes in the PID test to not use senors' id and execute commands instead

Michal Rutka6a95dd7f13dd
diff --git a/agent/src/test/groovy/org/openremote/test/rules/PIDTest.groovy b/agent/src/test/groovy/org/openremote/test/rules/PIDTest.groovy
index e75a9c683..7fdf9d27d 100644
--- a/agent/src/test/groovy/org/openremote/test/rules/PIDTest.groovy
+++ b/agent/src/test/groovy/org/openremote/test/rules/PIDTest.groovy
@@ -42,32 +42,36 @@ class PIDTest extends Specification implements ContainerTrait {
def container = startContainer(defaultConfig(serverPort), [agentService])
when: "we increase Sp"
- // can we run PID.sp.inc.ON command instead?
- def customStateEvent = new CustomSensorState(358537, "PID.sp.inc", "ON");
- agentService.getContext().update(customStateEvent);
+ // 2 ways of increasing the set point.
+ // Set the value of sensor directly:
+ //def customStateEvent = new CustomSensorState(358537, "PID.sp.inc", "ON");
+ //agentService.getContext().update(customStateEvent);
+ // Send a command linked with the button:
+ agentService.getContext().getCommands().execute("PID.sp.inc.ON")
and: "we wait"
- Thread.sleep(1000);
+ Thread.sleep(2000);
then: "set point should be 1.5"
- agentService.getContext().queryValue(358531) == "1.5" // can we check sensors by name?
- agentService.getContext().queryValue(358532) == "1.5000" // PID output
+ agentService.getContext().queryValue("GV.PID.Sp") == "1.5"
+ agentService.getContext().queryValue("PID.Output") == "1.5000"
when: "we decrease Sp"
- customStateEvent = new CustomSensorState(358525, "PID.sp.dec", "ON");
- agentService.getContext().update(customStateEvent);
+ agentService.getContext().getCommands().execute("PID.sp.dec.ON")
and: "we wait"
- Thread.sleep(1000);
+ Thread.sleep(2000);
- then: "set point should be 1.0"
- agentService.getContext().queryValue(358531) == "1.0" // set point
- agentService.getContext().queryValue(358532) == "1.0000" // PID output
+ then: "the PID output should be 1.0"
+ agentService.getContext().queryValue("GV.PID.Sp") == "1.0" // set point
+ agentService.getContext().queryValue("PID.Output") == "1.0000" // PID output
- // how can I test if there is no overshot?
- // how can I test if there are no oscillations?
+ // TODO: how can I test if there is no overshot?
+ // TODO: how can I test if there are no oscillations?
// Problem: sometimes it passes, sometimes fails...
+ // timing is not correct and requires manual tweaking - not desired. Better way would be to wait for desired
+ // output (with a timeout).
cleanup: "the server should be stopped"
stopContainer(container)
diff --git a/agent/src/test/resources/org/openremote/test/rules/pid/PID.drl b/agent/src/test/resources/org/openremote/test/rules/pid/PID.drl
index 38496b0a8..5d88a69dc 100644
--- a/agent/src/test/resources/org/openremote/test/rules/pid/PID.drl
+++ b/agent/src/test/resources/org/openremote/test/rules/pid/PID.drl
@@ -119,7 +119,7 @@ then
commands.execute($s, "off");
end
-rule "-PID: decrease Sp"
+rule "PID: decrease Sp"
timer(int:300ms)
when
SensorState(sensorName=="GV.PID.Sp", $v: value)