Skip to content

armgit / core

Public Imported from GitHub
0

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

Prepare for multiple controller instances in the same process

Christian Bauer84b7d16657b7
diff --git a/controller/src/main/java/org/openremote/controller/ControllerService.java b/controller/src/main/java/org/openremote/controller/ControllerService.java
index 7e4951e04..f7dd745e0 100644
--- a/controller/src/main/java/org/openremote/controller/ControllerService.java
+++ b/controller/src/main/java/org/openremote/controller/ControllerService.java
@@ -3,14 +3,12 @@ package org.openremote.controller;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
import org.openremote.controller.command.CommandBuilder;
+import org.openremote.controller.context.ControllerContext;
+import org.openremote.controller.context.InMemoryStateStorage;
import org.openremote.controller.deploy.DeploymentDefinition;
import org.openremote.controller.deploy.xml.ControllerDOMParser;
import org.openremote.controller.event.EventProcessor;
-import org.openremote.controller.event.EventProcessorChain;
-import org.openremote.controller.rules.CommandFacade;
-import org.openremote.controller.model.Deployment;
-import org.openremote.controller.model.Sensor;
-import org.openremote.controller.context.DataContext;
+import org.openremote.controller.deploy.Deployment;
import java.io.InputStream;
@@ -23,9 +21,7 @@ public class ControllerService implements ContainerService {
final protected EventProcessor[] eventProcessors;
protected DeploymentDefinition deploymentDefinition;
- protected Deployment deployment;
- protected CommandFacade commandFacade;
- protected DataContext dataContext;
+ protected ControllerContext controllerContext;
public ControllerService(InputStream deploymentXml, CommandBuilder commandBuilder, EventProcessor[] eventProcessors) {
this.deploymentXml = deploymentXml;
@@ -40,41 +36,31 @@ public class ControllerService implements ContainerService {
@Override
public void configure(Container container) throws Exception {
- deployment = new Deployment(deploymentDefinition, commandBuilder);
-
- commandFacade = new CommandFacade(deployment);
-
- EventProcessorChain eventProcessorChain = new EventProcessorChain(commandFacade, eventProcessors);
-
- dataContext = new DataContext(deployment, eventProcessorChain);
+ // TODO Support booting of multiple controller instances
+ Deployment deployment = new Deployment(
+ deploymentDefinition,
+ commandBuilder,
+ new InMemoryStateStorage(),
+ eventProcessors
+ );
+ controllerContext = new ControllerContext("OpenRemoteController1", deployment);
}
@Override
public void start(Container container) throws Exception {
- if (dataContext != null) {
- dataContext.start();
- for (Sensor sensor : deployment.getSensors()) {
- dataContext.registerAndStartSensor(sensor);
- }
+ if (controllerContext != null) {
+ controllerContext.start();
}
}
@Override
public void stop(Container container) throws Exception {
- if (dataContext != null) {
- dataContext.stop();
+ if (controllerContext != null) {
+ controllerContext.stop();
}
}
- public Deployment getDeployment() {
- return deployment;
- }
-
- public CommandFacade getCommandFacade() {
- return commandFacade;
- }
-
- public DataContext getDataContext() {
- return dataContext;
+ public ControllerContext getContext() {
+ return controllerContext;
}
}
diff --git a/controller/src/main/java/org/openremote/controller/rules/CommandFacade.java b/controller/src/main/java/org/openremote/controller/command/Commands.java
similarity index 69%
rename from controller/src/main/java/org/openremote/controller/rules/CommandFacade.java
rename to controller/src/main/java/org/openremote/controller/command/Commands.java
index c6e02899e..80760707f 100644
--- a/controller/src/main/java/org/openremote/controller/rules/CommandFacade.java
+++ b/controller/src/main/java/org/openremote/controller/command/Commands.java
@@ -1,10 +1,8 @@
-package org.openremote.controller.rules;
+package org.openremote.controller.command;
-import org.openremote.controller.command.Command;
-import org.openremote.controller.command.ExecutableCommand;
import org.openremote.controller.event.EventProcessor;
import org.openremote.controller.deploy.CommandDefinition;
-import org.openremote.controller.model.Deployment;
+import org.openremote.controller.deploy.Deployment;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -13,25 +11,25 @@ import java.util.logging.Logger;
* Can be used directly and/or by {@link EventProcessor}s to trigger
* {@link ExecutableCommand}s (e.g. in rules or from simple client call).
*/
-public class CommandFacade {
+public class Commands {
- private static final Logger LOG = Logger.getLogger(CommandFacade.class.getName());
+ private static final Logger LOG = Logger.getLogger(Commands.class.getName());
final protected Deployment deployment;
- public CommandFacade(Deployment deployment) {
+ public Commands(Deployment deployment) {
this.deployment = deployment;
}
- public void command(String commandName) {
- command(commandName, null);
+ public void execute(String commandName) {
+ execute(commandName, null);
}
- public void command(String commandName, int arg) {
- command(commandName, Integer.toString(arg));
+ public void execute(String commandName, int arg) {
+ execute(commandName, Integer.toString(arg));
}
- public void command(String commandName, String arg) {
+ public void execute(String commandName, String arg) {
CommandDefinition commandDefinition = deployment.getCommandDefinition(commandName);
if (commandDefinition == null) {
LOG.warning("Command definition not found, ignoring execution: " + commandName);
@@ -62,18 +60,18 @@ public class CommandFacade {
"No command was produced (does the protocol have an ExecutableCommand?): " + commandDefinition
);
} else if (command instanceof ExecutableCommand) {
- LOG.fine("Executing command '" + command + "' with: " + arg);
+ LOG.fine("Executing '" + commandDefinition.getName() + "' with: " + arg);
ExecutableCommand executableCommand = (ExecutableCommand) command;
try {
executableCommand.send(arg);
} catch (Exception ex) {
- LOG.log(Level.SEVERE, "Error executing command '" + command + "' with: " + arg, ex);
+ LOG.log(Level.SEVERE, "Error executing '" + commandDefinition.getName() + "' with: " + arg, ex);
}
} else {
LOG.log(Level.WARNING, "Ignoring, not an ExecutableCommand: " + command);
}
} catch (Throwable t) {
- LOG.log(Level.SEVERE, "Error building command: " + commandDefinition, t);
+ LOG.log(Level.SEVERE, "Error building: " + commandDefinition, t);
}
}
}
diff --git a/controller/src/main/java/org/openremote/controller/command/PushCommand.java b/controller/src/main/java/org/openremote/controller/command/PushCommand.java
index ecc0a7e87..015dfc06a 100644
--- a/controller/src/main/java/org/openremote/controller/command/PushCommand.java
+++ b/controller/src/main/java/org/openremote/controller/command/PushCommand.java
@@ -11,8 +11,8 @@ import org.openremote.controller.model.Sensor;
* implementation but push commands can be used to override this default implementation.
*
* Push commands are expected to create their own threads (if needed) which implement the
- * push functionality and also directly push received events to the
- * data context of the controller using the sensor callback API provided.
+ * push functionality and also directly push received events to the context of the controller
+ * using the sensor callback API provided.
*
* Push command implementations use the sensor
* {@link org.openremote.controller.model.Sensor#update} method to push state changes
diff --git a/controller/src/main/java/org/openremote/controller/context/DataContext.java b/controller/src/main/java/org/openremote/controller/context/ControllerContext.java
similarity index 50%
rename from controller/src/main/java/org/openremote/controller/context/DataContext.java
rename to controller/src/main/java/org/openremote/controller/context/ControllerContext.java
index 7f6b8fb6a..7c005b249 100644
--- a/controller/src/main/java/org/openremote/controller/context/DataContext.java
+++ b/controller/src/main/java/org/openremote/controller/context/ControllerContext.java
@@ -3,84 +3,91 @@ package org.openremote.controller.context;
import org.openremote.controller.event.Event;
import org.openremote.controller.event.EventProcessingContext;
import org.openremote.controller.event.EventProcessorChain;
-import org.openremote.controller.model.Deployment;
+import org.openremote.controller.deploy.Deployment;
import org.openremote.controller.model.Sensor;
+import org.openremote.controller.command.Commands;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-public class DataContext {
+/**
+ * An instance of a controller, bootstrapped from {@link Deployment}, this is the main API.
+ */
+public class ControllerContext {
- private static final Logger LOG = Logger.getLogger(DataContext.class.getName());
+ private static final Logger LOG = Logger.getLogger(ControllerContext.class.getName());
+ final protected String controllerID;
final protected Deployment deployment;
+ final protected Commands commands;
final protected EventProcessorChain eventProcessorChain;
- final protected Map<Integer, Sensor> sensors = new ConcurrentHashMap<>();
- final protected StateStorage stateStorage = new InMemoryStateStorage();
+ private volatile Boolean shutdownInProgress = false;
- private volatile Boolean isShutdownInProcess = false;
-
- public DataContext(Deployment deployment, EventProcessorChain eventProcessorChain) {
+ public ControllerContext(String controllerID, Deployment deployment) {
+ this.controllerID = controllerID;
this.deployment = deployment;
- this.eventProcessorChain = eventProcessorChain;
+ this.commands = new Commands(deployment);
+ this.eventProcessorChain = new EventProcessorChain(commands, deployment.getEventProcessors());
+ }
+
+ public String getControllerID() {
+ return controllerID;
+ }
+
+ public Deployment getDeployment() {
+ return deployment;
+ }
+
+ public Commands getCommands() {
+ return commands;
+ }
+
+ protected StateStorage getStateStorage() {
+ return getDeployment().getStateStorage();
}
public synchronized void start() {
- if (isShutdownInProcess)
+ if (shutdownInProgress)
return;
+ LOG.info("Starting context: " + getControllerID());
eventProcessorChain.start();
+ for (Sensor sensor : deployment.getSensors()) {
+ // Put initial state "unknown" for each sensor
+ getStateStorage().put(new SensorState(new Sensor.UnknownEvent(sensor)));
+ sensor.start(this);
+ }
}
/**
* <ul>
- * <li>registered sensors are stopped</li>
+ * <li>event processors are stopped</li>
+ * <li>sensors are stopped</li>
* <li>the current state is cleared</li>
- * <li>registered sensors are unregistered</li>
* </ul>
*/
public synchronized void stop() {
try {
- isShutdownInProcess = true;
+ LOG.info("Stopping context: " + getControllerID());
+ shutdownInProgress = true;
eventProcessorChain.stop();
- for (Sensor sensor : sensors.values()) {
- LOG.info("Stopping sensor: " + sensor);
+ for (Sensor sensor : deployment.getSensors()) {
try {
sensor.stop();
} catch (Throwable t) {
LOG.log(Level.SEVERE, "Failed to stop sensor: " + sensor, t);
}
}
- stateStorage.clear();
- sensors.clear();
+ getStateStorage().clear();
} finally {
- isShutdownInProcess = false;
- }
- }
-
- public synchronized void registerAndStartSensor(Sensor sensor) {
- if (isShutdownInProcess) {
- return;
+ shutdownInProgress = false;
}
-
- Sensor previous = sensors.put(sensor.getSensorDefinition().getSensorID(), sensor);
- if (previous != null) {
- throw new IllegalArgumentException("Duplicate registration: " + sensor.getSensorDefinition());
- }
-
- // Initial state
- stateStorage.put(new SensorState(new Sensor.UnknownEvent(sensor)));
-
- sensor.start(this);
- LOG.info("Registered and started sensor: " + sensor);
}
public synchronized void update(Event event) {
LOG.fine("==> Update from event: " + event);
- if (isShutdownInProcess) {
- LOG.fine("<== Data context is shutting down. Ignoring update from: " + event.getSource());
+ if (shutdownInProgress) {
+ LOG.fine("<== Shutting down. Ignoring update from: " + event.getSource());
return;
}
@@ -89,21 +96,20 @@ public class DataContext {
// Early exist if one of the processors decided to terminate the chain
if (ctx.hasTerminated()) {
- LOG.fine("<== Updating status complete, event context terminated, no update was made to data context for event: " + ctx.getEvent());
+ LOG.fine("<== Updating status complete, event context terminated, no update was made for event: " + ctx.getEvent());
return;
}
- stateStorage.put(new SensorState(event));
+ getStateStorage().put(new SensorState(event));
LOG.fine("<== Updating status complete for event: " + event);
- // TODO: Trigger notification of client that stuff has changed? Put it in a message broker/queue/topic?
}
public String queryValue(int sensorID) {
- if (!stateStorage.contains(sensorID)) {
+ if (!getStateStorage().contains(sensorID)) {
LOG.info("Requested sensor id '" + sensorID + "' was not found. Defaulting to: " + Sensor.UNKNOWN_STATUS);
return Sensor.UNKNOWN_STATUS;
}
- return stateStorage.get(sensorID).getEvent().serialize();
+ return getStateStorage().get(sensorID).getEvent().serialize();
}
public String queryValue(String sensorName) {
@@ -111,7 +117,7 @@ public class DataContext {
}
public Event queryEvent(int sensorID) {
- return stateStorage.get(sensorID).getEvent();
+ return getStateStorage().get(sensorID).getEvent();
}
public Event queryEvent(String sensorName) {
diff --git a/controller/src/main/java/org/openremote/controller/context/StateStorage.java b/controller/src/main/java/org/openremote/controller/context/StateStorage.java
index 1c7e96787..a8dc90879 100644
--- a/controller/src/main/java/org/openremote/controller/context/StateStorage.java
+++ b/controller/src/main/java/org/openremote/controller/context/StateStorage.java
@@ -1,9 +1,13 @@
package org.openremote.controller.context;
+/**
+ * Store controller context (sensor) state.
+ */
public interface StateStorage {
void clear();
+ // TODO: Trigger notification of client that stuff has changed? Put it in a message broker/queue/topic?
void put(SensorState sensorState);
boolean contains(int sensorID);
diff --git a/controller/src/main/java/org/openremote/controller/model/Deployment.java b/controller/src/main/java/org/openremote/controller/deploy/Deployment.java
similarity index 84%
rename from controller/src/main/java/org/openremote/controller/model/Deployment.java
rename to controller/src/main/java/org/openremote/controller/deploy/Deployment.java
index de76c5d1c..cf9b696d9 100644
--- a/controller/src/main/java/org/openremote/controller/model/Deployment.java
+++ b/controller/src/main/java/org/openremote/controller/deploy/Deployment.java
@@ -1,23 +1,40 @@
-package org.openremote.controller.model;
+package org.openremote.controller.deploy;
import org.openremote.controller.command.Command;
import org.openremote.controller.command.CommandBuilder;
import org.openremote.controller.command.EventProducerCommand;
-import org.openremote.controller.deploy.CommandDefinition;
-import org.openremote.controller.deploy.DeploymentDefinition;
-import org.openremote.controller.deploy.SensorDefinition;
+import org.openremote.controller.context.StateStorage;
+import org.openremote.controller.event.EventProcessor;
+import org.openremote.controller.model.*;
-import java.util.HashMap;
import java.util.Map;
-
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Encapsulates:
+ * <pre>
+ * - How protocol-specific commands are build
+ * - How controller sensor state is stored
+ * - How sensor events are processed
+ * - All known sensors and devices
+ * </pre>
+ */
public class Deployment {
final protected CommandBuilder commandBuilder;
- final protected Map<String, Device> devices = new HashMap<>();
- final protected Map<Integer, Sensor> sensors = new HashMap<>();
+ final protected StateStorage stateStorage;
+ final protected EventProcessor[] eventProcessors;
+ final protected Map<String, Device> devices = new ConcurrentHashMap<>();
+ final protected Map<Integer, Sensor> sensors = new ConcurrentHashMap<>();
+
+ public Deployment(DeploymentDefinition deploymentDefinition,
+ CommandBuilder commandBuilder,
+ StateStorage stateStorage,
+ EventProcessor... eventProcessors) {
- public Deployment(DeploymentDefinition deploymentDefinition, CommandBuilder commandBuilder) {
this.commandBuilder = commandBuilder;
+ this.stateStorage = stateStorage;
+ this.eventProcessors = eventProcessors;
for (SensorDefinition sensorDefinition : deploymentDefinition.getSensorDefinitions()) {
Sensor sensor = buildSensor(sensorDefinition);
@@ -42,6 +59,14 @@ public class Deployment {
return commandBuilder;
}
+ public StateStorage getStateStorage() {
+ return stateStorage;
+ }
+
+ public EventProcessor[] getEventProcessors() {
+ return eventProcessors;
+ }
+
public CommandDefinition getCommandDefinition(int commandID) {
for (Device device : devices.values()) {
CommandDefinition commandDefinition = device.getCommandDefinition(commandID);
diff --git a/controller/src/main/java/org/openremote/controller/event/Event.java b/controller/src/main/java/org/openremote/controller/event/Event.java
index 614aecdc6..6b35a83c1 100644
--- a/controller/src/main/java/org/openremote/controller/event/Event.java
+++ b/controller/src/main/java/org/openremote/controller/event/Event.java
@@ -28,7 +28,7 @@ public abstract class Event<T> {
/**
* This method implementation should return an appropriate string representation of the event value.
- * This value will be returned by {@link org.openremote.controller.context.DataContext#queryValue(int)}.
+ * This value will be returned by {@link org.openremote.controller.context.ControllerContext#queryValue(int)}.
*/
public abstract String serialize();
diff --git a/controller/src/main/java/org/openremote/controller/event/EventProcessingContext.java b/controller/src/main/java/org/openremote/controller/event/EventProcessingContext.java
index f9a8d1c47..523686d9c 100644
--- a/controller/src/main/java/org/openremote/controller/event/EventProcessingContext.java
+++ b/controller/src/main/java/org/openremote/controller/event/EventProcessingContext.java
@@ -1,21 +1,17 @@
package org.openremote.controller.event;
-import org.openremote.controller.context.DataContext;
+import org.openremote.controller.context.ControllerContext;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
import java.util.logging.Logger;
/**
- * Before the {@link DataContext} accepts an update from an event, it executes the
+ * Before the {@link ControllerContext} accepts an update from an event, it executes the
* {@link EventProcessorChain} with a fresh instance of {@link EventProcessingContext}.
* The event processing context encapsulates a single event and its journey through the
* system.
*
* Processors can access the event context and if they desire, terminate it. This means the
- * original event will be discarded and not make it into the data context.
+ * original event will be discarded and not make it into the {@link ControllerContext}.
*
* TODO Or, as we call it now, a Camel Exchange.
*/
@@ -23,12 +19,12 @@ public class EventProcessingContext {
private static final Logger LOG = Logger.getLogger(EventProcessingContext.class.getName());
- private DataContext dataContext;
+ private ControllerContext controllerContext;
private Event event;
private boolean terminated = false;
- public EventProcessingContext(DataContext dataContext, Event evt) {
- this.dataContext = dataContext;
+ public EventProcessingContext(ControllerContext controllerContext, Event evt) {
+ this.controllerContext = controllerContext;
this.event = evt;
}
@@ -41,8 +37,8 @@ public class EventProcessingContext {
return terminated;
}
- public DataContext getDataContext() {
- return dataContext;
+ public ControllerContext getControllerContext() {
+ return controllerContext;
}
public Event getEvent() {
diff --git a/controller/src/main/java/org/openremote/controller/event/EventProcessor.java b/controller/src/main/java/org/openremote/controller/event/EventProcessor.java
index c580b71dd..7f347a9ac 100644
--- a/controller/src/main/java/org/openremote/controller/event/EventProcessor.java
+++ b/controller/src/main/java/org/openremote/controller/event/EventProcessor.java
@@ -1,10 +1,13 @@
package org.openremote.controller.event;
-import org.openremote.controller.rules.CommandFacade;
+import org.openremote.controller.command.Commands;
+/**
+ * Process events before they are reaching the controller context.
+ */
public abstract class EventProcessor {
- public void start(CommandFacade commandFacade) throws Exception{
+ public void start(Commands commands) throws Exception{
}
public void stop() {
diff --git a/controller/src/main/java/org/openremote/controller/event/EventProcessorChain.java b/controller/src/main/java/org/openremote/controller/event/EventProcessorChain.java
index 4f8b38a09..5a122d7de 100644
--- a/controller/src/main/java/org/openremote/controller/event/EventProcessorChain.java
+++ b/controller/src/main/java/org/openremote/controller/event/EventProcessorChain.java
@@ -1,18 +1,17 @@
package org.openremote.controller.event;
-import org.openremote.controller.rules.CommandFacade;
+import org.openremote.controller.command.Commands;
-import java.util.Arrays;
-import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A chain of event processors that incoming events (values) are passing through before
- * a value might change in the data context.
+ * a value might change in the {@link org.openremote.controller.context.ControllerContext}.
*
* Event processors may modify the existing event payload value, discard events
- * entirely or spawn multiple other events that are interacting with the data context.
+ * entirely or spawn multiple other events that are interacting with the
+ * @{link {@link org.openremote.controller.context.ControllerContext}.
*
* TODO Or, as we call it now, a Camel route.
*/
@@ -20,24 +19,19 @@ public class EventProcessorChain {
private static final Logger LOG = Logger.getLogger(EventProcessorChain.class.getName());
- final protected CommandFacade commandFacade;
+ final protected Commands commands;
+ final protected EventProcessor[] processors;
- /**
- * Contains the ordered list of configured event processors for this chain.
- */
- final protected List<EventProcessor> processors;
-
- public EventProcessorChain(CommandFacade commandFacade, EventProcessor... processors) {
- this.processors = Arrays.asList(processors);
- this.commandFacade = commandFacade;
+ public EventProcessorChain(Commands commands, EventProcessor... eventProcessors) {
+ this.processors = eventProcessors;
+ this.commands = commands;
}
public void start() {
for (EventProcessor ep : processors) {
try {
- LOG.fine("Starting event processor: " + ep.getName());
- ep.start(commandFacade);
- LOG.info("Started event processor: " + ep.getName());
+ LOG.info("Starting event processor: " + ep.getName());
+ ep.start(commands);
} catch (Throwable t) {
LOG.log(Level.SEVERE, "Cannot start event processor: " + ep.getName(), t);
}
@@ -47,9 +41,8 @@ public class EventProcessorChain {
public void stop() {
for (EventProcessor ep : processors) {
try {
- LOG.fine("Stopping event processor: " + ep.getName());
+ LOG.info("Stopping event processor: " + ep.getName());
ep.stop();
- LOG.info("Stopped event processor: " + ep.getName());
} catch (Throwable t) {
LOG.log(Level.SEVERE, "Cannot stop event processor: " + ep.getName(), t);
}
diff --git a/controller/src/main/java/org/openremote/controller/model/CustomStateSensor.java b/controller/src/main/java/org/openremote/controller/model/CustomStateSensor.java
index 799d55415..847eaaf3a 100644
--- a/controller/src/main/java/org/openremote/controller/model/CustomStateSensor.java
+++ b/controller/src/main/java/org/openremote/controller/model/CustomStateSensor.java
@@ -48,7 +48,7 @@ public class CustomStateSensor extends Sensor {
* enabled, only state values explicitly declared for this sensor will be accepted and returned.
* If set to false, all values are allowed but those with value mappings will be converted.
*/
- protected CustomStateSensor(SensorDefinition sensorDefinition, EventProducerCommand producer, DistinctStates states, boolean strictStateMapping) {
+ public CustomStateSensor(SensorDefinition sensorDefinition, EventProducerCommand producer, DistinctStates states, boolean strictStateMapping) {
super(sensorDefinition, producer);
if (states == null) {
this.states = new DistinctStates();
diff --git a/controller/src/main/java/org/openremote/controller/model/Sensor.java b/controller/src/main/java/org/openremote/controller/model/Sensor.java
index 4b08d592d..b1f7157d2 100644
--- a/controller/src/main/java/org/openremote/controller/model/Sensor.java
+++ b/controller/src/main/java/org/openremote/controller/model/Sensor.java
@@ -3,9 +3,9 @@ package org.openremote.controller.model;
import org.openremote.controller.command.EventProducerCommand;
import org.openremote.controller.command.PullCommand;
import org.openremote.controller.command.PushCommand;
+import org.openremote.controller.context.ControllerContext;
import org.openremote.controller.deploy.SensorDefinition;
import org.openremote.controller.event.Event;
-import org.openremote.controller.context.DataContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -25,7 +25,7 @@ import java.util.logging.Logger;
* push or pull commands. These properties may be used by protocol implementers to
* direct their event producer output values to suit the sensor's configuration.
* <p>
- * Sensors are registered with {@link DataContext}.
+ * Sensors are registered with {@link ControllerContext}.
* Sensors create {@link org.openremote.controller.event.Event}s, which represent the
* data from devices.
*/
@@ -48,15 +48,7 @@ public abstract class Sensor {
}
private SensorDefinition sensorDefinition;
-
- /**
- * Reference to the data context that receives and processes the events generated from this sensor.
- */
- private DataContext dataContext;
-
- /**
- * An event producer command provides values to a sensor, typically through pull or push.
- */
+ private ControllerContext controllerContext;
private EventProducerCommand eventProducerCommand;
/**
@@ -77,26 +69,28 @@ public abstract class Sensor {
}
/**
- * Call path for push commands. Allow direct update of the sensor's value in the controller's
- * data context.
+ * Call path for push commands. Allow direct update of the sensor's value in
+ * the {@link ControllerContext}.
*
- * Before updating the data context, the value is first validated by concrete sensor
+ * Before updating the context, the value is first validated by concrete sensor
* implementation's {@link Sensor#processEvent(String)} method.
*
* @param state the new value for this sensor
*/
public void update(String state) {
- if (dataContext == null) {
+ if (controllerContext == null) {
LOG.fine("Ignoring update, sensor is not running: " + getSensorDefinition());
return;
}
- // Allow for sensor type specific processing of the value. This can be used for
- // mappings, validating value ranges, etc. before the value is pushed through
- // the event processor chain and ultimately into the data context.
+ /*
+ * Allow for sensor type specific processing of the value. This can be used for
+ * mappings, validating value ranges, etc. before the value is pushed through
+ * the event processor chain and ultimately into context.
+ */
Event evt = processEvent(state);
LOG.fine("Update on ID " + getSensorDefinition().getSensorID() + ", processed '" + state + "', created: " + evt);
- dataContext.update(evt);
+ controllerContext.update(evt);
}
/**
@@ -111,8 +105,9 @@ public abstract class Sensor {
* {@link PushCommand#start(Sensor)} method. For {@link PullCommand} implementations,
* this will start a polling thread to invoke their {@link PullCommand#read(Sensor)} method.
*/
- public void start(DataContext dataContext) {
- this.dataContext = dataContext;
+ public void start(ControllerContext controllerContext) {
+ LOG.info("Starting sensor: " + this);
+ this.controllerContext = controllerContext;
if (isPushCommand()) {
PushCommand pushCommand = (PushCommand) eventProducerCommand;
try {
@@ -135,7 +130,8 @@ public abstract class Sensor {
* is stopped.
*/
public void stop() {
- dataContext = null;
+ LOG.info("Stopping sensor: " + this);
+ controllerContext = null;
if (isPushCommand()) {
PushCommand pushCommand = (PushCommand) eventProducerCommand;
try {
@@ -156,7 +152,7 @@ public abstract class Sensor {
/**
* Callback to subclasses to apply their event validations and other processing
* if necessary. This method is called both when a value is pulled and when a
- * command pushes a new sensor value into data context state.
+ * command pushes a new sensor value into {@link ControllerContext} state.
*
* @param value value returned by the event producer
* @return validated and processed value of the event producer
diff --git a/controller/src/main/java/org/openremote/controller/rules/EventFacade.java b/controller/src/main/java/org/openremote/controller/rules/EventFacade.java
index 6b3c263cf..18b518d76 100644
--- a/controller/src/main/java/org/openremote/controller/rules/EventFacade.java
+++ b/controller/src/main/java/org/openremote/controller/rules/EventFacade.java
@@ -19,7 +19,7 @@ public abstract class EventFacade {
eventProcessingContext.terminate();
LOG.fine("Dispatching on new thread: " + event);
Thread t = new Thread(
- () -> eventProcessingContext.getDataContext().update(event)
+ () -> eventProcessingContext.getControllerContext().update(event)
);
t.start();
}
diff --git a/controller/src/main/java/org/openremote/controller/rules/RuleEngine.java b/controller/src/main/java/org/openremote/controller/rules/RuleEngine.java
index 0e9fa5f76..35a9b893d 100644
--- a/controller/src/main/java/org/openremote/controller/rules/RuleEngine.java
+++ b/controller/src/main/java/org/openremote/controller/rules/RuleEngine.java
@@ -43,6 +43,7 @@ import org.openremote.container.Container;
import org.openremote.controller.event.Event;
import org.openremote.controller.event.EventProcessingContext;
import org.openremote.controller.event.EventProcessor;
+import org.openremote.controller.command.Commands;
import java.util.Collection;
import java.util.HashMap;
@@ -144,7 +145,7 @@ public abstract class RuleEngine extends EventProcessor {
}
@Override
- public void start(CommandFacade commandFacade) throws Exception {
+ public void start(Commands commands) throws Exception {
KieServices kieServices = KieServices.Factory.get();
KieModuleModel kieModuleModel = kieServices.newKieModuleModel();
@@ -176,7 +177,7 @@ public abstract class RuleEngine extends EventProcessor {
rulePersistence = new RulePersistence();
ruleUtil = new RuleUtil();
- setGlobal("execute", commandFacade);
+ setGlobal("commands", commands);
setGlobal("switches", switchFacade);
setGlobal("ranges", rangeFacade);
setGlobal("levels", levelFacade);
diff --git a/controller/src/main/java/org/openremote/controller/rules/SingleValueEventFacade.java b/controller/src/main/java/org/openremote/controller/rules/SingleValueEventFacade.java
index 6ef234884..ed38284d8 100644
--- a/controller/src/main/java/org/openremote/controller/rules/SingleValueEventFacade.java
+++ b/controller/src/main/java/org/openremote/controller/rules/SingleValueEventFacade.java
@@ -6,7 +6,7 @@ import org.openremote.controller.model.Sensor;
public abstract class SingleValueEventFacade<T, U extends Event> extends EventFacade {
public T name(String sensorName) throws Exception {
- Event evt = eventProcessingContext.getDataContext().queryEvent(sensorName);
+ Event evt = eventProcessingContext.getControllerContext().queryEvent(sensorName);
if (evt instanceof Sensor.UnknownEvent) {
evt = createDefaultEvent(evt.getSourceID(), evt.getSource());
diff --git a/controller/src/main/java/org/openremote/controller/rules/SwitchFacade.java b/controller/src/main/java/org/openremote/controller/rules/SwitchFacade.java
index 09da471c4..839fca922 100644
--- a/controller/src/main/java/org/openremote/controller/rules/SwitchFacade.java
+++ b/controller/src/main/java/org/openremote/controller/rules/SwitchFacade.java
@@ -7,7 +7,7 @@ import org.openremote.controller.event.SwitchEvent;
public class SwitchFacade extends EventFacade {
public SwitchAdapter name(String sensorName) throws Exception {
- Event evt = eventProcessingContext.getDataContext().queryEvent(sensorName);
+ Event evt = eventProcessingContext.getControllerContext().queryEvent(sensorName);
if (evt instanceof Sensor.UnknownEvent) {
evt = new SwitchEvent(
diff --git a/controller/src/test/groovy/org/openremote/test/rules/MixedWithErrorsTest.groovy b/controller/src/test/groovy/org/openremote/test/rules/MixedWithErrorsTest.groovy
index c55bf6c11..f26d41383 100644
--- a/controller/src/test/groovy/org/openremote/test/rules/MixedWithErrorsTest.groovy
+++ b/controller/src/test/groovy/org/openremote/test/rules/MixedWithErrorsTest.groovy
@@ -5,7 +5,6 @@ import org.kie.api.io.Resource
import org.openremote.controller.ControllerService
import org.openremote.controller.rules.RuleEngine
import org.openremote.test.ContainerTrait
-import org.openremote.test.util.EventGrabProcessor
import spock.lang.Specification
import java.util.stream.Stream
@@ -60,8 +59,8 @@ class MixedWithErrorsTest extends Specification implements ContainerTrait {
Thread.sleep(500)
then: "the state should match"
- controllerService.getDataContext().queryValue(444) == "12345" // TODO This should be limited to max, which is 1000
- controllerService.getDataContext().queryValue(555) == "55"
+ controllerService.getContext().queryValue(444) == "12345" // TODO This should be limited to max, which is 1000
+ controllerService.getContext().queryValue(555) == "55"
cleanup: "the server should be stopped"
stopContainer(container)
diff --git a/controller/src/test/groovy/org/openremote/test/rules/SimpleRuleTest.groovy b/controller/src/test/groovy/org/openremote/test/rules/SimpleRuleTest.groovy
index 4445e74f4..c6f956a6d 100644
--- a/controller/src/test/groovy/org/openremote/test/rules/SimpleRuleTest.groovy
+++ b/controller/src/test/groovy/org/openremote/test/rules/SimpleRuleTest.groovy
@@ -63,28 +63,29 @@ class SimpleRuleTest extends Specification implements ContainerTrait {
and: "the total event count is 1, as the event fired in the rule terminates processing of our switch event"
grabProcessor.totalEventCount == 1
- and: "the data context state of the sensor should be 'off'"
- controllerService.getDataContext().queryValue(123) == "off"
+ and: "the context state of the sensor should be 'off'"
+ controllerService.getContext().queryValue(123) == "off"
and: "the deployment model should work"
- controllerService.getDeployment().getCommandDefinition(456).getCommandID() == 456
- controllerService.getDeployment().getCommandDefinition(123123) == null
- controllerService.getDeployment().getCommandDefinition("TestDevice", "TestCommand").getCommandID() == 456
- controllerService.getDeployment().getCommandDefinition("TestDevice", "NoSuchThing") == null
- controllerService.getDeployment().getCommandDefinition("NoSuchThing", "NoSuchThing") == null
- controllerService.getDeployment().getCommandDefinition("", "") == null
- controllerService.getDeployment().getCommandDefinition(null, "") == null
- controllerService.getDeployment().getCommandDefinition("", null) == null
- controllerService.getDeployment().getCommandDefinition(null, null) == null
- controllerService.getDeployment().getCommandDefinition("TestCommand").getCommandID() == 456
- controllerService.getDeployment().getCommandDefinition("NoSuchThing") == null
- controllerService.getDeployment().getCommandDefinition("") == null
- controllerService.getDeployment().getCommandDefinition(null) == null
- controllerService.getDeployment().getDevices().length == 1
- controllerService.getDeployment().getDevices()[0].getName() == "TestDevice"
- controllerService.getDeployment().getDevices()[0].getDeviceID() == 111
- controllerService.getDeployment().getDevice("TestDevice").getName() == "TestDevice"
- controllerService.getDeployment().getDevice("TestDevice").getDeviceID() == 111
+ def deployment = controllerService.getContext().getDeployment()
+ deployment.getCommandDefinition(456).getCommandID() == 456
+ deployment.getCommandDefinition(123123) == null
+ deployment.getCommandDefinition("TestDevice", "TestCommand").getCommandID() == 456
+ deployment.getCommandDefinition("TestDevice", "NoSuchThing") == null
+ deployment.getCommandDefinition("NoSuchThing", "NoSuchThing") == null
+ deployment.getCommandDefinition("", "") == null
+ deployment.getCommandDefinition(null, "") == null
+ deployment.getCommandDefinition("", null) == null
+ deployment.getCommandDefinition(null, null) == null
+ deployment.getCommandDefinition("TestCommand").getCommandID() == 456
+ deployment.getCommandDefinition("NoSuchThing") == null
+ deployment.getCommandDefinition("") == null
+ deployment.getCommandDefinition(null) == null
+ deployment.getDevices().length == 1
+ deployment.getDevices()[0].getName() == "TestDevice"
+ deployment.getDevices()[0].getDeviceID() == 111
+ deployment.getDevice("TestDevice").getName() == "TestDevice"
+ deployment.getDevice("TestDevice").getDeviceID() == 111
cleanup: "the server should be stopped"
stopContainer(container)
diff --git a/controller/src/test/groovy/org/openremote/test/rules/VacationTest.groovy b/controller/src/test/groovy/org/openremote/test/rules/VacationTest.groovy
index cc1528fa0..940e40209 100644
--- a/controller/src/test/groovy/org/openremote/test/rules/VacationTest.groovy
+++ b/controller/src/test/groovy/org/openremote/test/rules/VacationTest.groovy
@@ -7,7 +7,6 @@ import org.openremote.controller.event.CustomStateEvent
import org.openremote.controller.event.SwitchEvent
import org.openremote.controller.rules.RuleEngine
import org.openremote.test.ContainerTrait
-import org.openremote.test.util.EventGrabProcessor
import spock.lang.Specification
import java.util.stream.Stream
@@ -48,7 +47,7 @@ class VacationTest extends Specification implements ContainerTrait {
when: "the time of day is day"
def customStateEvent = new CustomStateEvent(123, "time of day", "day");
- controllerService.getDataContext().update(customStateEvent);
+ controllerService.getContext().update(customStateEvent);
and: "we wait a bit for the rules to fire"
Thread.sleep(100);
@@ -58,7 +57,7 @@ class VacationTest extends Specification implements ContainerTrait {
when: "the time of day is night"
customStateEvent = new CustomStateEvent(123, "time of day", "night");
- controllerService.getDataContext().update(customStateEvent);
+ controllerService.getContext().update(customStateEvent);
and: "we wait a bit for the rules to fire"
Thread.sleep(100);
@@ -68,7 +67,7 @@ class VacationTest extends Specification implements ContainerTrait {
when: "we go on vacation"
def switchEvent = new SwitchEvent(789, "vacation start", "on", SwitchEvent.State.ON);
- controllerService.getDataContext().update(switchEvent);
+ controllerService.getContext().update(switchEvent);
and: "we wait a bit for the rules to fire"
Thread.sleep(100);
@@ -78,7 +77,7 @@ class VacationTest extends Specification implements ContainerTrait {
when: "the time of day is day"
customStateEvent = new CustomStateEvent(123, "time of day", "day");
- controllerService.getDataContext().update(customStateEvent);
+ controllerService.getContext().update(customStateEvent);
and: "we wait a bit for the rules to fire"
Thread.sleep(100);
@@ -87,7 +86,7 @@ class VacationTest extends Specification implements ContainerTrait {
testCommandBuilder.lastExecutionArgument == "15"
when: "we manually set the temperature"
- controllerService.getCommandFacade().command("temp", 19)
+ controllerService.getContext().getCommands().execute("temp", 19)
then: "the temperature change should be executed"
testCommandBuilder.lastExecutionArgument == "19"
diff --git a/controller/src/test/resources/org/openremote/test/rules/climatecontrol/ClimateControl.drl b/controller/src/test/resources/org/openremote/test/rules/climatecontrol/ClimateControl.drl
index b140967a6..96e78a33f 100644
--- a/controller/src/test/resources/org/openremote/test/rules/climatecontrol/ClimateControl.drl
+++ b/controller/src/test/resources/org/openremote/test/rules/climatecontrol/ClimateControl.drl
@@ -6,9 +6,8 @@ import java.text.SimpleDateFormat;
import java.io.*;
import org.openremote.controller.model.*;
import org.openremote.controller.event.*;
-import org.openremote.controller.event.*;
-global org.openremote.controller.rules.CommandFacade execute;
+global org.openremote.controller.command.Commands commands;
global org.openremote.controller.rules.RulePersistence persistence;
global org.openremote.controller.rules.RuleUtil util;
global com.fasterxml.jackson.databind.ObjectMapper JSON;
@@ -21,41 +20,41 @@ end
rule "-PSB: Init"
salience 10
then
- execute.command("VR1.ET", persistence.readData("VR1.ET","--:--"));
- execute.command("VR1.ET.inc", "OFF");
- execute.command("VR1.ET.dec", "OFF");
- execute.command("VETA.inc", "OFF");
- execute.command("VETA.dec", "OFF");
- execute.command("VETD.inc", "OFF");
- execute.command("VETD.dec", "OFF");
- execute.command("VR1.COMFORT",persistence.readData("VR1.COMFORT","20.0\u00B0"));
- execute.command("VR1.COMFORT.inc","OFF");
- execute.command("VR1.COMFORT.dec","OFF");
- execute.command("VR1.TEMPERATURE","19.5\u00B0");
- execute.command("VR1.TEMPERATURE.inc","OFF");
- execute.command("VR1.TEMPERATURE.dec","OFF");
- execute.command("VNEXTACTION",persistence.readData("VNEXTACTION","-")); // Earlier arrive with reset
- execute.command("VPERSONSENSETIME","-");
- execute.command("VLEAVES", "1.0");
- execute.command("VSCORE", "0");
- execute.command("VHEATINGSETPOINT", "16");
- execute.command("VWINDOW","Closed");
- execute.command("VADVICEDONE", "OFF");
- execute.command("VSUMMER", "No");
- execute.command("VADVICE", "You're doing great!");
- execute.command("VACATION.inc", "OFF");
- execute.command("VACATION.dec", "OFF");
- execute.command("VACATION", persistence.readData("VACATION", "0"));
- execute.command("VTOTALSCORE",persistence.readData("VTOTALSCORE", "0"));
- execute.command("VLEVEL", persistence.readData("VLEVEL", "0"));
- execute.command("VATA", persistence.readData("VATA","-"));
- execute.command("VATD", persistence.readData("VATD","-"));
- execute.command("VPRESENCE","No");
- execute.command("GVconfig",persistence.readData("GVconfig", "OpenRemote"));
- execute.command("GVtestsPassed",persistence.readData("GVtestsPassed", "0"));
- execute.command("GVtestsFailed",persistence.readData("GVtestsFailed", "0"));
- execute.command("VArrivalBackground", "on");
- execute.command("VDepartureBackground", "off");
+ commands.execute("VR1.ET", persistence.readData("VR1.ET","--:--"));
+ commands.execute("VR1.ET.inc", "OFF");
+ commands.execute("VR1.ET.dec", "OFF");
+ commands.execute("VETA.inc", "OFF");
+ commands.execute("VETA.dec", "OFF");
+ commands.execute("VETD.inc", "OFF");
+ commands.execute("VETD.dec", "OFF");
+ commands.execute("VR1.COMFORT",persistence.readData("VR1.COMFORT","20.0\u00B0"));
+ commands.execute("VR1.COMFORT.inc","OFF");
+ commands.execute("VR1.COMFORT.dec","OFF");
+ commands.execute("VR1.TEMPERATURE","19.5\u00B0");
+ commands.execute("VR1.TEMPERATURE.inc","OFF");
+ commands.execute("VR1.TEMPERATURE.dec","OFF");
+ commands.execute("VNEXTACTION",persistence.readData("VNEXTACTION","-")); // Earlier arrive with reset
+ commands.execute("VPERSONSENSETIME","-");
+ commands.execute("VLEAVES", "1.0");
+ commands.execute("VSCORE", "0");
+ commands.execute("VHEATINGSETPOINT", "16");
+ commands.execute("VWINDOW","Closed");
+ commands.execute("VADVICEDONE", "OFF");
+ commands.execute("VSUMMER", "No");
+ commands.execute("VADVICE", "You're doing great!");
+ commands.execute("VACATION.inc", "OFF");
+ commands.execute("VACATION.dec", "OFF");
+ commands.execute("VACATION", persistence.readData("VACATION", "0"));
+ commands.execute("VTOTALSCORE",persistence.readData("VTOTALSCORE", "0"));
+ commands.execute("VLEVEL", persistence.readData("VLEVEL", "0"));
+ commands.execute("VATA", persistence.readData("VATA","-"));
+ commands.execute("VATD", persistence.readData("VATD","-"));
+ commands.execute("VPRESENCE","No");
+ commands.execute("GVconfig",persistence.readData("GVconfig", "OpenRemote"));
+ commands.execute("GVtestsPassed",persistence.readData("GVtestsPassed", "0"));
+ commands.execute("GVtestsFailed",persistence.readData("GVtestsFailed", "0"));
+ commands.execute("VArrivalBackground", "on");
+ commands.execute("VDepartureBackground", "off");
end
rule "PSB: Init ETA when empty"
@@ -63,7 +62,7 @@ salience 9
when
Event(source matches "VETA.*", $s: source, value=="")
then
- execute.command($s, persistence.readData($s, "09:00"));
+ commands.execute($s, persistence.readData($s, "09:00"));
end
rule "PSB: Init ETD when empty"
@@ -71,7 +70,7 @@ salience 8
when
Event(source matches "VETD.*", $s: source, value=="")
then
- execute.command($s, persistence.readData($s, "17:00"));
+ commands.execute($s, persistence.readData($s, "17:00"));
end
rule "PSB: store values"
@@ -102,9 +101,9 @@ when
Event(source == "VR1.ET", $v: value)
Event(source == "VR1.ET.inc" , value == "ON")
then
- execute.command("VR1.ET", util.shiftTime($v.toString(), 5));
- execute.command("VR1.ET.inc", "off");
- execute.command("VR1.ET.dec", "OFF");
+ commands.execute("VR1.ET", util.shiftTime($v.toString(), 5));
+ commands.execute("VR1.ET.inc", "off");
+ commands.execute("VR1.ET.dec", "OFF");
end
rule "-PSB: VETA Inc"
@@ -113,9 +112,9 @@ when
Event(source == "VETA", $v: value)
Event(source == "VETA.inc" , value == "ON")
then
- execute.command("VETA", util.shiftTime($v.toString(), 5));
- execute.command("VETA.inc", "off");
- execute.command("VETA.dec", "OFF");
+ commands.execute("VETA", util.shiftTime($v.toString(), 5));
+ commands.execute("VETA.inc", "off");
+ commands.execute("VETA.dec", "OFF");
end
rule "-PSB: VETD Inc"
@@ -124,9 +123,9 @@ when
Event(source == "VETD", $v: value)
Event(source == "VETD.inc" , value == "ON")
then
- execute.command("VETD", util.shiftTime($v.toString(), 5));
- execute.command("VETD.inc", "off");
- execute.command("VETD.dec", "OFF");
+ commands.execute("VETD", util.shiftTime($v.toString(), 5));
+ commands.execute("VETD.inc", "off");
+ commands.execute("VETD.dec", "OFF");
end
rule "-PSB: VR1.ET Dec"
@@ -135,9 +134,9 @@ when
Event(source == "VR1.ET", $v: value)
Event(source == "VR1.ET.dec" , value == "ON")
then
- execute.command("VR1.ET", util.shiftTime($v.toString(), -15));
- execute.command("VR1.ET.inc", "OFF");
- execute.command("VR1.ET.dec", "off");
+ commands.execute("VR1.ET", util.shiftTime($v.toString(), -15));
+ commands.execute("VR1.ET.inc", "OFF");
+ commands.execute("VR1.ET.dec", "off");
end
rule "-PSB: VETA Dec"
@@ -146,9 +145,9 @@ when
Event(source == "VETA", $v: value)
Event(source == "VETA.dec" , value == "ON")
then
- execute.command("VETA", util.shiftTime($v.toString(), -15));
- execute.command("VETA.inc", "OFF");
- execute.command("VETA.dec", "off");
+ commands.execute("VETA", util.shiftTime($v.toString(), -15));
+ commands.execute("VETA.inc", "OFF");
+ commands.execute("VETA.dec", "off");
end
rule "-PSB: VETD Dec"
@@ -157,9 +156,9 @@ when
Event(source == "VETD", $v: value)
Event(source == "VETD.dec" , value == "ON")
then
- execute.command("VETD", util.shiftTime($v.toString(), -15));
- execute.command("VETD.inc", "OFF");
- execute.command("VETD.dec", "off");
+ commands.execute("VETD", util.shiftTime($v.toString(), -15));
+ commands.execute("VETD.inc", "OFF");
+ commands.execute("VETD.dec", "off");
end
rule "PSB: VUSERSCHEDULECHANGES change counter"
@@ -176,7 +175,7 @@ when
then
// off - changed by user
// OFF - idle state after restart
- execute.command($s, "OFF");
+ commands.execute($s, "OFF");
int cnt = 0;
try{
cnt = Integer.parseInt(persistence.readData("VUSERSCHEDULECHANGES","0"));
@@ -199,7 +198,7 @@ when
)
Event(source == "VNEXTACTION", value == "-")
then
- execute.command("VNEXTACTION", "Departure");
+ commands.execute("VNEXTACTION", "Departure");
end
rule "PSB: VR1.COMFORT inc"
@@ -208,9 +207,9 @@ when
Event(source == "VR1.COMFORT", $v: value, eval(util.parseDouble(value) < 24))
Event(source == "VR1.COMFORT.inc" , value == "ON")
then
- execute.command("VR1.COMFORT.inc","off");
- execute.command("VR1.COMFORT.dec","OFF");
- execute.command("VR1.COMFORT", util.shiftDouble($v.toString(), 0.5, "\u00B0"));
+ commands.execute("VR1.COMFORT.inc","off");
+ commands.execute("VR1.COMFORT.dec","OFF");
+ commands.execute("VR1.COMFORT", util.shiftDouble($v.toString(), 0.5, "\u00B0"));
end
rule "PSB: VR1.COMFORT dec"
@@ -219,9 +218,9 @@ when
Event(source == "VR1.COMFORT", $v: value, eval(util.parseDouble(value) > 18))
Event(source == "VR1.COMFORT.dec" , value == "ON")
then
- execute.command("VR1.COMFORT.inc","OFF");
- execute.command("VR1.COMFORT.dec","off");
- execute.command("VR1.COMFORT", util.shiftDouble($v.toString(), -0.5, "\u00B0"));
+ commands.execute("VR1.COMFORT.inc","OFF");
+ commands.execute("VR1.COMFORT.dec","off");
+ commands.execute("VR1.COMFORT", util.shiftDouble($v.toString(), -0.5, "\u00B0"));
end
rule "PSB: VR1.COMFORT INC/dec" // needed when change on the boundary
@@ -230,8 +229,8 @@ rule "PSB: VR1.COMFORT INC/dec" // needed when change on the boundary
when
Event(source == "VR1.COMFORT.inc" , value == "ON")
then
- execute.command("VR1.COMFORT.inc","off");
- execute.command("VR1.COMFORT.dec","OFF");
+ commands.execute("VR1.COMFORT.inc","off");
+ commands.execute("VR1.COMFORT.dec","OFF");
end
rule "PSB: VR1.COMFORT inc/DEC" // needed when change on the boundary
@@ -240,8 +239,8 @@ rule "PSB: VR1.COMFORT inc/DEC" // needed when change on the boundary
when
Event(source == "VR1.COMFORT.dec" , value == "ON")
then
- execute.command("VR1.COMFORT.inc","OFF");
- execute.command("VR1.COMFORT.dec","off");
+ commands.execute("VR1.COMFORT.inc","OFF");
+ commands.execute("VR1.COMFORT.dec","off");
end
rule "PSB: VR1.TEMPERATURE inc"
@@ -251,9 +250,9 @@ when
Event(source == "VR1.TEMPERATURE", $v: value, eval(util.parseDouble(value) <26))
Event(source == "VR1.TEMPERATURE.inc" , value == "ON")
then
- execute.command("VR1.TEMPERATURE.inc","off");
- execute.command("VR1.TEMPERATURE.dec","OFF"); // Do not increase change counter
- execute.command("VR1.TEMPERATURE", util.shiftDouble($v.toString(), 0.5, "\u00B0"));
+ commands.execute("VR1.TEMPERATURE.inc","off");
+ commands.execute("VR1.TEMPERATURE.dec","OFF"); // Do not increase change counter
+ commands.execute("VR1.TEMPERATURE", util.shiftDouble($v.toString(), 0.5, "\u00B0"));
end
rule "PSB: VR1.TEMPERATURE dec"
@@ -263,9 +262,9 @@ when
Event(source == "VR1.TEMPERATURE", $v: value, eval(util.parseDouble(value) > 16)) // Lower temp limit
Event(source == "VR1.TEMPERATURE.dec" , value == "ON")
then
- execute.command("VR1.TEMPERATURE.inc","OFF");
- execute.command("VR1.TEMPERATURE.dec","off");
- execute.command("VR1.TEMPERATURE", util.shiftDouble($v.toString(), -0.5, "\u00B0"));
+ commands.execute("VR1.TEMPERATURE.inc","OFF");
+ commands.execute("VR1.TEMPERATURE.dec","off");
+ commands.execute("VR1.TEMPERATURE", util.shiftDouble($v.toString(), -0.5, "\u00B0"));
end
rule "PSB: VR1.TEMPERATURE INC/dec" // needed when on the boundary and in summer
@@ -274,8 +273,8 @@ rule "PSB: VR1.TEMPERATURE INC/dec" // needed when on the boundary and in summer
when
Event(source == "VR1.TEMPERATURE.inc" , value == "ON")
then
- execute.command("VR1.TEMPERATURE.inc","off");
- execute.command("VR1.TEMPERATURE.dec","OFF");
+ commands.execute("VR1.TEMPERATURE.inc","off");
+ commands.execute("VR1.TEMPERATURE.dec","OFF");
end
rule "PSB: VR1.TEMPERATURE inc/DEC" // needed when on the boundary and in summer
@@ -284,8 +283,8 @@ rule "PSB: VR1.TEMPERATURE inc/DEC" // needed when on the boundary and in summer
when
Event(source == "VR1.TEMPERATURE.dec" , value == "ON")
then
- execute.command("VR1.TEMPERATURE.inc","OFF");
- execute.command("VR1.TEMPERATURE.dec","off");
+ commands.execute("VR1.TEMPERATURE.inc","OFF");
+ commands.execute("VR1.TEMPERATURE.dec","off");
end
rule "PSB: VR1.TEMPERATURE change counter"
@@ -300,7 +299,7 @@ when
then
// off - changed by user
// OFF - idle state after restart
- execute.command($s, "OFF");
+ commands.execute($s, "OFF");
int cnt = 0;
try{
cnt = Integer.parseInt(persistence.readData("VSETTEMPCHANGES","0"));
@@ -319,7 +318,7 @@ when
Event(source == "VR1.TEMPERATURE.dec", $s: source, value == "ON")
)
then
- execute.command($s, "OFF");
+ commands.execute($s, "OFF");
end
rule "PSB: set departure on manual TEMPERATURE change after expected attendance"
@@ -335,9 +334,9 @@ when
Event(source == "VNEXTACTION", value == "-")
then
// Set departure time when temp manually adjusted after leave
- execute.command("VNEXTACTION", "Departure");
- execute.command("VR1.ET", util.shiftTime($et.toString(), 60));
- execute.command("VETD", util.shiftTime($et.toString(), 60));
+ commands.execute("VNEXTACTION", "Departure");
+ commands.execute("VR1.ET", util.shiftTime($et.toString(), 60));
+ commands.execute("VETD", util.shiftTime($et.toString(), 60));
end
rule "PSB: Move ETA to ET at midnight"
@@ -349,10 +348,10 @@ when
Event(source=="VNEXTACTION", value=="-")
Event(source=="VACATION", eval(Integer.parseInt(value.toString())==0))
then
- execute.command("VR1.ET", $va.toString());
- execute.command("VETA", $va.toString());
- execute.command("VETD", $vd.toString());
- execute.command("VNEXTACTION", "Arrive");
+ commands.execute("VR1.ET", $va.toString());
+ commands.execute("VETA", $va.toString());
+ commands.execute("VETD", $vd.toString());
+ commands.execute("VNEXTACTION", "Arrive");
end
rule "Move ETA ETD for current day"
@@ -361,22 +360,22 @@ when
Event(source matches ("VETA."+$e), $va:value)
Event(source matches ("VETD."+$e), $vd: value)
then
- execute.command("VETA", $va.toString());
- execute.command("VETD", $vd.toString());
+ commands.execute("VETA", $va.toString());
+ commands.execute("VETD", $vd.toString());
end
rule "PSB: reset VATA"
when
Event(source=="VNEXTACTION", value=="Arrive")
then
- execute.command("VATA","-");
+ commands.execute("VATA","-");
end
rule "PSB: reset VATD"
when
Event(source=="VATA",value=="-")
then
- execute.command("VATD","-");
+ commands.execute("VATD","-");
end
rule "PSB: decrease vacation counter at midnight"
@@ -384,15 +383,15 @@ when
$timer: Event(source=="TimerHH", eval(value.toString().substring(0,5).equals("00:00"))) // more reliable than timer(cron: )
Event(source=="VACATION", $v: value, eval(Integer.parseInt(value.toString())>0), this before $timer)
then
- execute.command("VACATION", Integer.parseInt($v.toString())-1);
+ commands.execute("VACATION", Integer.parseInt($v.toString())-1);
end
rule "PSB: reset action at midnight"
when
Event(source=="TimerHH", eval(value.toString().substring(0,5).equals("00:00"))) // more reliable than timer(cron: )
then
- execute.command("VR1.ET", "-");
- execute.command("VNEXTACTION", "-");
+ commands.execute("VR1.ET", "-");
+ commands.execute("VNEXTACTION", "-");
end
rule "PSB: Move ETD to ET at arrive init"
@@ -405,9 +404,9 @@ when
// Event(source=="VNEXTACTION", value=="-")
Event(source=="VR1.ET", value == "--:--")
then
- execute.command("VR1.ET", $vd.toString());
- execute.command("VETD", $vd.toString());
- execute.command("VNEXTACTION", "Departure");
+ commands.execute("VR1.ET", $vd.toString());
+ commands.execute("VETD", $vd.toString());
+ commands.execute("VNEXTACTION", "Departure");
end
rule "PSB: Move ETD to ET at arrive"
@@ -420,8 +419,8 @@ when
Event(source=="VETA", eval(util.parseTimestamp(value) < util.parseTimestamp($h)))
Event(source=="VACATION", eval(Integer.parseInt(value.toString())==0))
then
- execute.command("VR1.ET", $vd.toString());
- execute.command("VNEXTACTION", "Departure");
+ commands.execute("VR1.ET", $vd.toString());
+ commands.execute("VNEXTACTION", "Departure");
end
rule "PSB: actual arrival time earlier when temperature increased and person detected"
@@ -438,7 +437,7 @@ when
Event(source=="VPERSONSENSE", value == "1")
Event(source=="VATA",value=="-")
then
- execute.command("VR1.ET", $h.toString().substring(0,5));
+ commands.execute("VR1.ET", $h.toString().substring(0,5));
end
rule "PSB: fetch actual arrival time"
@@ -448,7 +447,7 @@ when
Event(source=="VNEXTACTION", value=="Departure")
Event(source=="VPERSONSENSE", value=="1")
then
- execute.command("VATA", $h.toString().substring(0,5));
+ commands.execute("VATA", $h.toString().substring(0,5));
end
rule "PSB: fetch earlier actual arrival time up to 30 min v02"
@@ -460,7 +459,7 @@ when
Event(source=="VETA", value != "-", value != "--:--")
Event(source=="VETA", eval(util.parseTimestamp(util.shiftTime(value,-30)) <= util.parseTimestamp($h)))
then
- execute.command("VATA", $h.toString().substring(0,5));
+ commands.execute("VATA", $h.toString().substring(0,5));
end
rule "PSB: Move - to ET at end of work"
@@ -471,16 +470,16 @@ when
Event(source=="VETD", eval(util.parseTimestamp(value) < util.parseTimestamp($h)))
Event(source=="VNEXTACTION", value=="Departure")
then
- execute.command("VR1.ET", "-");
- execute.command("VNEXTACTION", "-");
+ commands.execute("VR1.ET", "-");
+ commands.execute("VNEXTACTION", "-");
end
rule "PSB: Move - to ET on vacation"
when
Event(source=="VACATION", eval(Integer.parseInt(value.toString())>0))
then
- execute.command("VR1.ET", "-");
- execute.command("VNEXTACTION", "-");
+ commands.execute("VR1.ET", "-");
+ commands.execute("VNEXTACTION", "-");
end
rule "PSB: fetch actual departure time"
@@ -490,8 +489,8 @@ when
Event(source=="VNEXTACTION", value=="-")
Event(source=="VPERSONSENSETIME", $v:value, eval(value.toString().length()>4))
then
- execute.command("VATD", $v.toString().substring(0,5));
- execute.command("VPERSONSENSETIME","-");
+ commands.execute("VATD", $v.toString().substring(0,5));
+ commands.execute("VPERSONSENSETIME","-");
end
rule "PSB: fetch later departure time"
@@ -506,8 +505,8 @@ when
eval(util.parseTimestamp(value)<=util.parseTimestamp("23:55"))) // Till 23:55 - does not wrap on midnight
Event(source=="VACATION", eval(Integer.parseInt(value.toString())==0))
then
- execute.command("VATD", $v.toString().substring(0,5));
- execute.command("VPERSONSENSETIME","-");
+ commands.execute("VATD", $v.toString().substring(0,5));
+ commands.execute("VPERSONSENSETIME","-");
end
rule "PSB: adjust estimated times at midnight"
@@ -522,10 +521,10 @@ when
then
Double alpha = 2.0/(3+1); // 3 stays for 3 days exponential average
long nt = (long) (alpha*util.parseTimestamp($va) + (1-alpha)*util.parseTimestamp($vea));
- execute.command("VETA."+$e.toString(), util.formatTimestamp(nt));
+ commands.execute("VETA."+$e.toString(), util.formatTimestamp(nt));
LOG.fine("EA="+$vea.toString()+" AA="+$va.toString()+" NA="+ util.formatTimestamp(nt));
nt = (long) (alpha*util.parseTimestamp($vd) + (1-alpha)*util.parseTimestamp($ved));
- execute.command("VETD."+$e.toString(), util.formatTimestamp(nt));
+ commands.execute("VETD."+$e.toString(), util.formatTimestamp(nt));
LOG.fine("ED="+$ved.toString()+" AD="+$vd.toString()+" ND="+ util.formatTimestamp(nt));
end
@@ -535,7 +534,7 @@ when
Event(source=="TimerHH", $h:value)
then
LOG.fine("Move sense on "+$s);
- execute.command("VPERSONSENSETIME", $h.toString());
+ commands.execute("VPERSONSENSETIME", $h.toString());
end
rule "-PSB: person sense"
@@ -543,7 +542,7 @@ when
Event($s:source=="FS.PIR", value=="on")
Event(source=="VPERSONSENSE", value!="1")
then
- execute.command("VPERSONSENSE", "1");
+ commands.execute("VPERSONSENSE", "1");
end
rule "-PSB: no person sense"
@@ -552,28 +551,28 @@ when
Event(source=="FS.PIR", value!="on")
Event(source=="VPERSONSENSE", value!="0")
then
- execute.command("VPERSONSENSE", "0");
+ commands.execute("VPERSONSENSE", "0");
end
rule "-PSB: window open sense"
when
Event(source=="FS.Window", value=="on")
then
- execute.command("VWINDOW","Open");
+ commands.execute("VWINDOW","Open");
end
rule "-PSB: window closed sense"
when
Event(source=="FS.Window", value=="off")
then
- execute.command("VWINDOW","Closed");
+ commands.execute("VWINDOW","Closed");
end
rule "--FS outside temperature sense"
when
Event(source=="FS.Toutside", $v: value)
then
- execute.command("VOUTSIDE", $v.toString() );
+ commands.execute("VOUTSIDE", $v.toString() );
LOG.fine("Fake outside temperature: "+$v.toString() );
end
@@ -582,7 +581,7 @@ when
Event(source=="FS.Tinside", $v: value)
then
LOG.fine("Fake inside temperature: "+ $v.toString() );
- execute.command("VROOMTEMPERATURE", $v.toString() );
+ commands.execute("VROOMTEMPERATURE", $v.toString() );
end
rule "PSB: Presence"
@@ -590,7 +589,7 @@ when
Event(source == "VPERSONSENSE", value == "1")
Event(source=="VNEXTACTION", value=="Departure") // within expected attendance schedule
then
- execute.command("VPRESENCE","Yes");
+ commands.execute("VPRESENCE","Yes");
end
rule "PSB: Absence when 30 min no movement"
@@ -599,7 +598,7 @@ when
Event(source == "VPERSONSENSE", value == "0")
Event(source=="VNEXTACTION", value=="Departure") // within expected attendance schedule
then
- execute.command("VPRESENCE","No");
+ commands.execute("VPRESENCE","No");
end
rule "PSB: Absence after 15 min v02"
@@ -607,14 +606,14 @@ timer(int: 15m)
when
Event(source == "VPERSONSENSE", value == "0")
then
- execute.command("VPRESENCE","No");
+ commands.execute("VPRESENCE","No");
end
rule "PSB: Absence after scheduled presence time"
when
Event(source=="VNEXTACTION", value!="Departure") // outsidse expected attendance schedule
then
- execute.command("VPRESENCE","No");
+ commands.execute("VPRESENCE","No");
end
rule "-PSB: heating ECO"
@@ -624,7 +623,7 @@ when
Event(source=="VSUMMER", value=="Yes")
)
then
- execute.command("VHEATING","ECO");
+ commands.execute("VHEATING","ECO");
end
rule "-PSB: heating Stand-by from ECO"
@@ -635,8 +634,8 @@ when
Event(source=="VHEATING", value == "ECO")
Event(source=="VR1.COMFORT", $vc: value)
then
- execute.command("VR1.TEMPERATURE", $vc.toString());
- execute.command("VHEATING", "Stand-by");
+ commands.execute("VR1.TEMPERATURE", $vc.toString());
+ commands.execute("VHEATING", "Stand-by");
end
rule "-PSB: heating Stand-by from ECO preheating 30 min v02"
@@ -650,8 +649,8 @@ when
Event(source=="VETA", value != "-", value != "--:--")
Event(source=="VETA", eval(util.parseTimestamp(util.shiftTime(value,-30)) <= util.parseTimestamp($h)))
then
- execute.command("VR1.TEMPERATURE", $vc.toString());
- execute.command("VHEATING", "Stand-by");
+ commands.execute("VR1.TEMPERATURE", $vc.toString());
+ commands.execute("VHEATING", "Stand-by");
end
rule "-PSB: heating Stand-by from Comfort"
@@ -663,7 +662,7 @@ when
Event(source=="VR1.COMFORT", $vc: value)
Event(source=="VR1.TEMPERATURE", value==$vc) // Only when no manual temperature increase
then
- execute.command("VHEATING","Stand-by");
+ commands.execute("VHEATING","Stand-by");
end
rule "-PSB: heating Comfort on presence"
@@ -672,8 +671,8 @@ when
Event(source=="VPRESENCE", value=="Yes")
Event(source=="VR1.COMFORT", $v: value)
then
- execute.command("VHEATING","Comfort");
- execute.command("VR1.TEMPERATURE", $v.toString());
+ commands.execute("VHEATING","Comfort");
+ commands.execute("VR1.TEMPERATURE", $v.toString());
end
rule "-PSB: heating Comfort on temperature increase"
@@ -684,7 +683,7 @@ when
Event(source=="VR1.TEMPERATURE", eval(util.parseDouble(value) > util.parseDouble($vc)))
Event(source=="VHEATING", value != "Comfort")
then
- execute.command("VHEATING","Comfort");
+ commands.execute("VHEATING","Comfort");
end
rule "-PSB: heating setpoint ECO"
@@ -700,8 +699,8 @@ then
} catch (NumberFormatException e){
t = 16.0;
}
- execute.command("VHEATINGSETPOINT", String.format("%.1f",t));
- execute.command("VR1.TEMPERATURE", String.format("%.1f\u00B0",t));
+ commands.execute("VHEATINGSETPOINT", String.format("%.1f",t));
+ commands.execute("VR1.TEMPERATURE", String.format("%.1f\u00B0",t));
end
rule "-PSB: heating setpoint ECO summer"
@@ -712,8 +711,8 @@ when
then
String s = $v.toString();
Double t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1))-5); // 5 degrees below comfort
- execute.command("VHEATINGSETPOINT", String.format("%.1f",t));
- execute.command("VR1.TEMPERATURE", "-");
+ commands.execute("VHEATINGSETPOINT", String.format("%.1f",t));
+ commands.execute("VR1.TEMPERATURE", "-");
end
rule "-PSB: heating setpoint Stand-by"
@@ -725,8 +724,8 @@ when
then
String s = $v.toString();
Double t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1))-1); // 1 degree below comfort
- execute.command("VHEATINGSETPOINT", String.format("%.1f",t));
- execute.command("VR1.TEMPERATURE", s);
+ commands.execute("VHEATINGSETPOINT", String.format("%.1f",t));
+ commands.execute("VR1.TEMPERATURE", s);
end
rule "-PSB: heating setpoint Comfort"
@@ -738,70 +737,70 @@ when
then
String s = $v.toString();
Double t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1)));
- execute.command("VHEATINGSETPOINT", String.format("%.1f",t));
+ commands.execute("VHEATINGSETPOINT", String.format("%.1f",t));
end
rule "-PSB: leaves 0"
when
Event(source=="VLEAVES", value=="0.0")
then
- execute.command("VLEAF1", "l0.png");
- execute.command("VLEAF2", "l0.png");
- execute.command("VLEAF3", "l0.png");
+ commands.execute("VLEAF1", "l0.png");
+ commands.execute("VLEAF2", "l0.png");
+ commands.execute("VLEAF3", "l0.png");
end
rule "-PSB: leaves 0.5"
when
Event(source=="VLEAVES", value=="0.5")
then
- execute.command("VLEAF1", "l1.png");
- execute.command("VLEAF2", "l0.png");
- execute.command("VLEAF3", "l0.png");
+ commands.execute("VLEAF1", "l1.png");
+ commands.execute("VLEAF2", "l0.png");
+ commands.execute("VLEAF3", "l0.png");
end
rule "-PSB: leaves 1"
when
Event(source=="VLEAVES", value=="1.0")
then
- execute.command("VLEAF1", "l2.png");
- execute.command("VLEAF2", "l0.png");
- execute.command("VLEAF3", "l0.png");
+ commands.execute("VLEAF1", "l2.png");
+ commands.execute("VLEAF2", "l0.png");
+ commands.execute("VLEAF3", "l0.png");
end
rule "-PSB: leaves 1.5"
when
Event(source=="VLEAVES", value=="1.5")
then
- execute.command("VLEAF1", "l2.png");
- execute.command("VLEAF2", "l1.png");
- execute.command("VLEAF3", "l0.png");
+ commands.execute("VLEAF1", "l2.png");
+ commands.execute("VLEAF2", "l1.png");
+ commands.execute("VLEAF3", "l0.png");
end
rule "-PSB: leaves 2"
when
Event(source=="VLEAVES", value=="2.0")
then
- execute.command("VLEAF1", "l2.png");
- execute.command("VLEAF2", "l2.png");
- execute.command("VLEAF3", "l0.png");
+ commands.execute("VLEAF1", "l2.png");
+ commands.execute("VLEAF2", "l2.png");
+ commands.execute("VLEAF3", "l0.png");
end
rule "-PSB: leaves 2.5"
when
Event(source=="VLEAVES", value=="2.5")
then
- execute.command("VLEAF1", "l2.png");
- execute.command("VLEAF2", "l2.png");
- execute.command("VLEAF3", "l1.png");
+ commands.execute("VLEAF1", "l2.png");
+ commands.execute("VLEAF2", "l2.png");
+ commands.execute("VLEAF3", "l1.png");
end
rule "-PSB: leaves 3"
when
Event(source=="VLEAVES", value=="3.0")
then
- execute.command("VLEAF1", "l2.png");
- execute.command("VLEAF2", "l2.png");
- execute.command("VLEAF3", "l2.png");
+ commands.execute("VLEAF1", "l2.png");
+ commands.execute("VLEAF2", "l2.png");
+ commands.execute("VLEAF3", "l2.png");
end
rule "-PSB: energy efficiency 1"
@@ -811,8 +810,8 @@ when
Event(source=="VHEATING", value!="ECO") // needed because of race
Event(source=="VPRESENCE", value=="No")
then
- execute.command("VLEAVES", "0.0");
- execute.command("VSCORE", 0);
+ commands.execute("VLEAVES", "0.0");
+ commands.execute("VSCORE", 0);
end
rule "-PSB: energy efficiency 2"
@@ -823,8 +822,8 @@ when
Event(source=="VPRESENCE", value=="Yes")
Event(source=="VWINDOW", value=="Open")
then
- execute.command("VLEAVES", "0.5");
- execute.command("VSCORE", 0);
+ commands.execute("VLEAVES", "0.5");
+ commands.execute("VSCORE", 0);
end
// v02
@@ -838,8 +837,8 @@ when
Event(source=="VOUTSIDE", $t: value)
Event(source=="VR1.TEMPERATURE", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
then
- execute.command("VLEAVES", "0.5");
- execute.command("VSCORE", 0);
+ commands.execute("VLEAVES", "0.5");
+ commands.execute("VSCORE", 0);
end
rule "-PSB: energy efficiency 2-2 v02"
@@ -850,8 +849,8 @@ when
Event(source=="VHEATING", value!="ECO") // needed because of race
Event(source=="VPRESENCE", value=="No")
then
- execute.command("VLEAVES", "0.5");
- execute.command("VSCORE", 0);
+ commands.execute("VLEAVES", "0.5");
+ commands.execute("VSCORE", 0);
end
rule "-PSB: energy efficiency 2-3 v02"
@@ -862,8 +861,8 @@ when
Event(source=="VHEATING", value!="ECO") // needed because of race
Event(source=="VPRESENCE", value=="No")
then
- execute.command("VLEAVES", "1.0");
- execute.command("VSCORE", 0);
+ commands.execute("VLEAVES", "1.0");
+ commands.execute("VSCORE", 0);
end
// v02
@@ -874,8 +873,8 @@ when
Event(source=="VHEATING", value!="ECO") // needed because of race
Event(source=="VPRESENCE", value=="No")
then
- execute.command("VLEAVES", "1.0");
- execute.command("VSCORE", 0);
+ commands.execute("VLEAVES", "1.0");
+ commands.execute("VSCORE", 0);
end
rule "-PSB: energy efficiency 4"
@@ -886,8 +885,8 @@ when
Event(source=="VHEATING", value!="ECO") // needed because of race
Event(source=="VPRESENCE", value=="Yes")
then
- execute.command("VLEAVES", "1.0");
- execute.command("VSCORE", 0);
+ commands.execute("VLEAVES", "1.0");
+ commands.execute("VSCORE", 0);
end
rule "-PSB: energy efficiency 5"
@@ -897,8 +896,8 @@ when
Event(source=="VPRESENCE", value=="No")
Event(source=="VWINDOW", value=="Open")
then
- execute.command("VLEAVES", "1.0");
- execute.command("VSCORE", 0);
+ commands.execute("VLEAVES", "1.0");
+ commands.execute("VSCORE", 0);
end
rule "-PSB: energy efficiency 6"
@@ -909,8 +908,8 @@ when
Event(source=="VPRESENCE", value=="Yes")
Event(source=="VWINDOW", value=="Open")
then
- execute.command("VLEAVES", "1.0");
- execute.command("VSCORE", 0);
+ commands.execute("VLEAVES", "1.0");
+ commands.execute("VSCORE", 0);
end
rule "-PSB: energy efficiency 7"
@@ -922,8 +921,8 @@ when
Event(source=="VOUTSIDE", $t: value)
Event(source=="VR1.TEMPERATURE", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
then
- execute.command("VLEAVES", "1.5");
- execute.command("VSCORE", 1);
+ commands.execute("VLEAVES", "1.5");
+ commands.execute("VSCORE", 1);
end
rule "-PSB: energy efficiency 8"
@@ -935,8 +934,8 @@ when
Event(source=="VOUTSIDE", $t: value)
Event(source=="VR1.TEMPERATURE", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
then
- execute.command("VLEAVES", "1.5");
- execute.command("VSCORE", 1);
+ commands.execute("VLEAVES", "1.5");
+ commands.execute("VSCORE", 1);
end
rule "-PSB: energy efficiency 9"
@@ -947,8 +946,8 @@ when
Event(source=="VHEATING", value!="ECO") // needed because of race
Event(source=="VPRESENCE", value=="Yes")
then
- execute.command("VLEAVES", "1.5");
- execute.command("VSCORE", 1);
+ commands.execute("VLEAVES", "1.5");
+ commands.execute("VSCORE", 1);
end
rule "-PSB: energy efficiency 10"
@@ -961,8 +960,8 @@ when
Event(source=="VOUTSIDE", $t: value)
Event(source=="VR1.TEMPERATURE", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
then
- execute.command("VLEAVES", "1.5");
- execute.command("VSCORE", 1);
+ commands.execute("VLEAVES", "1.5");
+ commands.execute("VSCORE", 1);
end
rule "-PSB: energy efficiency 11"
@@ -973,8 +972,8 @@ when
Event(source=="VHEATING", value!="ECO") // needed because of race
Event(source=="VPRESENCE", value=="Yes")
then
- execute.command("VLEAVES", "2.0");
- execute.command("VSCORE", 2);
+ commands.execute("VLEAVES", "2.0");
+ commands.execute("VSCORE", 2);
end
rule "-PSB: energy efficiency 12 v02"
@@ -985,8 +984,8 @@ when
Event(source=="VHEATING", value!="ECO") // needed because of race
Event(source=="VPRESENCE", value=="Yes") // v02
then
- execute.command("VLEAVES", "2.5");
- execute.command("VSCORE", 3);
+ commands.execute("VLEAVES", "2.5");
+ commands.execute("VSCORE", 3);
end
rule "-PSB: energy efficiency 13"
@@ -999,8 +998,8 @@ when
Event(source=="VOUTSIDE", $t: value)
Event(source=="VR1.TEMPERATURE", eval(util.parseDouble($t) >= util.parseDouble(value))) // Higher outside temperature
then
- execute.command("VLEAVES", "3.0");
- execute.command("VSCORE", 4);
+ commands.execute("VLEAVES", "3.0");
+ commands.execute("VSCORE", 4);
end
rule "-PSB: energy efficiency 14"
@@ -1010,8 +1009,8 @@ when
Event(source=="VHEATING", value=="ECO")
Event(source=="VPRESENCE", value=="No")
then
- execute.command("VLEAVES", "3.0");
- execute.command("VSCORE", 4);
+ commands.execute("VLEAVES", "3.0");
+ commands.execute("VSCORE", 4);
end
rule "-PSB: energy efficiency 15"
@@ -1021,16 +1020,16 @@ when
Event(source=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) < 20)) // Comfort--
Event(source=="VPRESENCE", value=="Yes") // No important IMHO
then
- execute.command("VLEAVES", "3.0");
- execute.command("VSCORE", 4);
+ commands.execute("VLEAVES", "3.0");
+ commands.execute("VSCORE", 4);
end
rule "-PSB: energy efficiency Summer"
when
Event(source=="VSUMMER", value=="Yes")
then
- execute.command("VLEAVES", "3.0");
- execute.command("VSCORE", 4);
+ commands.execute("VLEAVES", "3.0");
+ commands.execute("VSCORE", 4);
end
rule "--PSB: increase total score every 15m"
@@ -1039,7 +1038,7 @@ when
Event(source=="VSCORE", $s: value)
Event(source=="VTOTALSCORE", $ts: value, this before $timer)
then
- execute.command("VTOTALSCORE", Integer.parseInt($ts.toString())+Integer.parseInt($s.toString()));
+ commands.execute("VTOTALSCORE", Integer.parseInt($ts.toString())+Integer.parseInt($s.toString()));
end
rule "PSB: reward"
@@ -1048,15 +1047,15 @@ when
Event(source=="VLEVEL", $l: value, this before $ts)
then
Integer i = Integer.parseInt($s.toString());
- execute.command("VTOTALSCORE", i-1000); // Reset score
- execute.command("VLEVEL", Integer.parseInt($l.toString())+1);
+ commands.execute("VTOTALSCORE", i-1000); // Reset score
+ commands.execute("VLEVEL", Integer.parseInt($l.toString())+1);
end
rule "--PSB: display totalscore"
when
Event(source=="VTOTALSCORE", $ts: value)
then
- execute.command("VTOTALSCOREdisp", $ts+" / 1000");
+ commands.execute("VTOTALSCOREdisp", $ts+" / 1000");
end
rule "PSB: summer"
@@ -1069,7 +1068,7 @@ when
Event(source=="VSUMMER", value!="Yes")
then
LOG.fine("Summer is ON; outside="+$o.toString());
- execute.command("VSUMMER", "Yes");
+ commands.execute("VSUMMER", "Yes");
end
rule "PSB: no summer"
@@ -1082,7 +1081,7 @@ when
Event(source=="VSUMMER", value!="No")
then
LOG.fine("Summer is OFF; outside="+$o.toString());
- execute.command("VSUMMER", "No");
+ commands.execute("VSUMMER", "No");
end
rule "-PSB: advice 1"
@@ -1092,8 +1091,8 @@ when
Event(source=="VHEATINGSETPOINT", $sp: value)
Event(source=="VOUTSIDE", value!="", eval(Double.parseDouble($sp.toString()) > util.parseDouble(value) )) // Outside temp lower than set point
then
- execute.command("VADVICE", "It's more energy efficient to close the windows when it is colder outside than it is inside");
- execute.command("VADVICEDONE", "OFF");
+ commands.execute("VADVICE", "It's more energy efficient to close the windows when it is colder outside than it is inside");
+ commands.execute("VADVICEDONE", "OFF");
insert(new AdviceGiven("It's more energy efficient to close the windows when it is colder outside than it is inside"));
end
@@ -1106,8 +1105,8 @@ when
)
Event(source=="VADVICE",eval(value.toString().substring(0,9).equals("It's more")))
then
- execute.command("VADVICE", "You're doing great!");
- execute.command("VADVICEDONE", "OFF");
+ commands.execute("VADVICE", "You're doing great!");
+ commands.execute("VADVICEDONE", "OFF");
end
rule "-PSB: advice 2"
@@ -1115,8 +1114,8 @@ when
Event(source=="VSUMMER", value=="No")
Event(source=="VR1.COMFORT", eval(util.parseDouble(value) > 20.5)) // Average is 20 hardcoded or from sensor?
then
- execute.command("VADVICE", "Your comfort temperature is set higher than average. You can adjust it on the settings page.");
- execute.command("VADVICEDONE", "OFF");
+ commands.execute("VADVICE", "Your comfort temperature is set higher than average. You can adjust it on the settings page.");
+ commands.execute("VADVICEDONE", "OFF");
insert(new AdviceGiven("Your comfort temperature is set higher than average. You can adjust it on the settings page."));
end
@@ -1125,15 +1124,15 @@ when
Event(source=="VR1.COMFORT", eval(util.parseDouble(value) <= 20.5)) // Average is 20 hardcoded or from sensor?
Event(source=="VADVICE",eval(value.toString().substring(0,12).equals("Your comfort")))
then
- execute.command("VADVICE", "You're doing great!");
- execute.command("VADVICEDONE", "OFF");
+ commands.execute("VADVICE", "You're doing great!");
+ commands.execute("VADVICEDONE", "OFF");
end
rule "-PSB: advice 3"
when
// irregular attendence
then
- execute.command("VADVICEDONE", "OFF");
+ commands.execute("VADVICEDONE", "OFF");
end
rule "-PSB: advice 4"
@@ -1143,8 +1142,8 @@ when
Event(source=="VSUMMER", value=="Yes")
)
then
- execute.command("VADVICE", "You're doing great!");
- execute.command("VADVICEDONE", "OFF");
+ commands.execute("VADVICE", "You're doing great!");
+ commands.execute("VADVICEDONE", "OFF");
insert(new AdviceGiven("You're doing great!"));
end
@@ -1174,8 +1173,8 @@ when
Event(source=="VACATION", $v: value)
Event(source=="VACATION.inc", value=="ON")
then
- execute.command("VACATION", Integer.parseInt($v.toString())+1);
- execute.command("VACATION.inc", "OFF");
+ commands.execute("VACATION", Integer.parseInt($v.toString())+1);
+ commands.execute("VACATION.inc", "OFF");
end
rule "-PSB: vacation dec"
@@ -1184,8 +1183,8 @@ when
Event(source=="VACATION", $v: value, eval(Integer.parseInt(value.toString()) > 0))
Event(source=="VACATION.dec", value=="ON")
then
- execute.command("VACATION", Integer.parseInt($v.toString())-1);
- execute.command("VACATION.dec", "OFF");
+ commands.execute("VACATION", Integer.parseInt($v.toString())-1);
+ commands.execute("VACATION.dec", "OFF");
end
rule "-PSB: vacation inc/dec" // needed so the ON value does not hang
@@ -1194,7 +1193,7 @@ rule "-PSB: vacation inc/dec" // needed so the ON value does not hang
when
Event(source matches "VACATION...c", $s: source, value=="ON")
then
- execute.command($s, "OFF");
+ commands.execute($s, "OFF");
end
rule "PSB: start next week stats"
@@ -1240,7 +1239,7 @@ when
Event(source=="Timerd", $d: value)
Event(source=="TimerMMM", $MMM:value)
then
- execute.command("VTimer", $EEEE.toString()+" "+$d.toString()+" "+$MMM.toString()+". I will be:");
+ commands.execute("VTimer", $EEEE.toString()+" "+$d.toString()+" "+$MMM.toString()+". I will be:");
end
rule "-PSB16: background arrival on"
@@ -1249,7 +1248,7 @@ when
Event(source=="VETA", eval(util.parseTimestamp(value) > util.parseTimestamp($h)) )
Event(source=="VArrivalBackground", value!="on")
then
- execute.command("VArrivalBackground", "on");
+ commands.execute("VArrivalBackground", "on");
end
rule "-PSB16: background departure on"
@@ -1258,7 +1257,7 @@ when
Event(source=="VETD", eval(util.parseTimestamp(value) > util.parseTimestamp($h)) )
Event(source=="VDepartureBackground", value!="on")
then
- execute.command("VDepartureBackground", "on");
+ commands.execute("VDepartureBackground", "on");
end
rule "-PSB16: background arrival off"
@@ -1267,7 +1266,7 @@ when
Event(source=="VETA", eval(util.parseTimestamp(value) <= util.parseTimestamp($h)) )
Event(source=="VArrivalBackground", value!="off")
then
- execute.command("VArrivalBackground", "off");
+ commands.execute("VArrivalBackground", "off");
end
rule "-PSB16: background departure off"
@@ -1276,18 +1275,18 @@ when
Event(source=="VETD", eval(util.parseTimestamp(value) <= util.parseTimestamp($h)) )
Event(source=="VDepartureBackground", value!="off")
then
- execute.command("VDepartureBackground", "off");
+ commands.execute("VDepartureBackground", "off");
end
// PID controller start
rule "-PID: init"
then
- execute.command("GV.PID.Kp",persistence.readData("GV.PID.Kp", "0.6"));
- execute.command("GV.PID.Ki",persistence.readData("GV.PID.Ki", "0.2"));
- execute.command("GV.PID.Kd",persistence.readData("GV.PID.Kd", "0.1"));
- execute.command("GV.PID.Db",persistence.readData("GV.PID.Db", "0.0"));
- execute.command("GV.PID.Sp",persistence.readData("GV.PID.Sp", "1.0"));
+ commands.execute("GV.PID.Kp",persistence.readData("GV.PID.Kp", "0.6"));
+ commands.execute("GV.PID.Ki",persistence.readData("GV.PID.Ki", "0.2"));
+ commands.execute("GV.PID.Kd",persistence.readData("GV.PID.Kd", "0.1"));
+ commands.execute("GV.PID.Db",persistence.readData("GV.PID.Db", "0.0"));
+ commands.execute("GV.PID.Sp",persistence.readData("GV.PID.Sp", "1.0"));
end
// PID UI
@@ -1298,8 +1297,8 @@ when
Event(source=="GV.PID.Kp", $v: value)
Event($s:source=="PID.kp.inc", value=="ON")
then
- execute.command("GV.PID.Kp", String.format("%.1f", Double.parseDouble($v.toString())+0.1) );
- execute.command($s, "off");
+ commands.execute("GV.PID.Kp", String.format("%.1f", Double.parseDouble($v.toString())+0.1) );
+ commands.execute($s, "off");
end
rule "-PID: decrease Kp"
@@ -1308,8 +1307,8 @@ when
Event(source=="GV.PID.Kp", $v: value)
Event($s:source=="PID.kp.dec", value=="ON")
then
- execute.command("GV.PID.Kp", String.format("%.1f", Double.parseDouble($v.toString())-0.1) );
- execute.command($s, "off");
+ commands.execute("GV.PID.Kp", String.format("%.1f", Double.parseDouble($v.toString())-0.1) );
+ commands.execute($s, "off");
end
rule "-PID: increase Ki"
@@ -1318,8 +1317,8 @@ when
Event(source=="GV.PID.Ki", $v: value)
Event($s:source=="PID.ki.inc", value=="ON")
then
- execute.command("GV.PID.Ki", String.format("%.1f", Double.parseDouble($v.toString())+0.1) );
- execute.command($s, "off");
+ commands.execute("GV.PID.Ki", String.format("%.1f", Double.parseDouble($v.toString())+0.1) );
+ commands.execute($s, "off");
end
rule "-PID: decrease Ki"
@@ -1328,8 +1327,8 @@ when
Event(source=="GV.PID.Ki", $v: value)
Event($s:source=="PID.ki.dec", value=="ON")
then
- execute.command("GV.PID.Ki", String.format("%.1f", Double.parseDouble($v.toString())-0.1) );
- execute.command($s, "off");
+ commands.execute("GV.PID.Ki", String.format("%.1f", Double.parseDouble($v.toString())-0.1) );
+ commands.execute($s, "off");
end
rule "-PID: increase Kd"
@@ -1338,8 +1337,8 @@ when
Event(source=="GV.PID.Kd", $v: value)
Event($s:source=="PID.kd.inc", value=="ON")
then
- execute.command("GV.PID.Kd", String.format("%.1f", Double.parseDouble($v.toString())+0.1) );
- execute.command($s, "off");
+ commands.execute("GV.PID.Kd", String.format("%.1f", Double.parseDouble($v.toString())+0.1) );
+ commands.execute($s, "off");
end
rule "-PID: decrease Kd"
@@ -1348,8 +1347,8 @@ when
Event(source=="GV.PID.Kd", $v: value)
Event($s:source=="PID.kd.dec", value=="ON")
then
- execute.command("GV.PID.Kd", String.format("%.1f", Double.parseDouble($v.toString())-0.1) );
- execute.command($s, "off");
+ commands.execute("GV.PID.Kd", String.format("%.1f", Double.parseDouble($v.toString())-0.1) );
+ commands.execute($s, "off");
end
rule "-PID: increase Db"
@@ -1358,8 +1357,8 @@ when
Event(source=="GV.PID.Db", $v: value)
Event($s:source=="PID.db.inc", value=="ON")
then
- execute.command("GV.PID.Db", String.format("%.1f", Double.parseDouble($v.toString())+0.1) );
- execute.command($s, "off");
+ commands.execute("GV.PID.Db", String.format("%.1f", Double.parseDouble($v.toString())+0.1) );
+ commands.execute($s, "off");
end
rule "-PID: decrease Db"
@@ -1368,8 +1367,8 @@ when
Event(source=="GV.PID.Db", $v: value)
Event($s:source=="PID.db.dec", value=="ON")
then
- execute.command("GV.PID.Db", String.format("%.1f", Double.parseDouble($v.toString())-0.1) );
- execute.command($s, "off");
+ commands.execute("GV.PID.Db", String.format("%.1f", Double.parseDouble($v.toString())-0.1) );
+ commands.execute($s, "off");
end
rule "-PID: increase Sp"
@@ -1378,8 +1377,8 @@ when
Event(source=="GV.PID.Sp", $v: value)
Event($s:source=="PID.sp.inc", value=="ON")
then
- execute.command("GV.PID.Sp", String.format("%.1f", Double.parseDouble($v.toString())+0.5) );
- execute.command($s, "off");
+ commands.execute("GV.PID.Sp", String.format("%.1f", Double.parseDouble($v.toString())+0.5) );
+ commands.execute($s, "off");
end
rule "-PID: decrease Sp"
@@ -1388,8 +1387,8 @@ when
Event(source=="GV.PID.Sp", $v: value)
Event($s:source=="PID.sp.dec", value=="ON")
then
- execute.command("GV.PID.Sp", String.format("%.1f", Double.parseDouble($v.toString())-0.5) );
- execute.command($s, "off");
+ commands.execute("GV.PID.Sp", String.format("%.1f", Double.parseDouble($v.toString())-0.5) );
+ commands.execute($s, "off");
end
rule "-PID: reset inc/dec"
@@ -1398,7 +1397,7 @@ rule "-PID: reset inc/dec"
when
Event($s: source matches "^PID......c$", value!="off")
then
- execute.command($s, "off");
+ commands.execute($s, "off");
end
// PID algorithm
@@ -1454,8 +1453,8 @@ then
else if(output < $pv.getOutMin()) output = $pv.getOutMin();
$pv.setOutput(output);
- execute.command("PID.Se", String.format("%.4f", error) );
- execute.command("PID.Output", String.format("%.4f", output) );
+ commands.execute("PID.Se", String.format("%.4f", error) );
+ commands.execute("PID.Output", String.format("%.4f", output) );
// LOG.fine($pv.toString() + " error: "+String.format("%f", Double.parseDouble($sp.toString() ) - $pv.getOutput()));
end
@@ -1465,10 +1464,10 @@ end
rule "Fake sensors init"
then
- execute.command("FS.Toutside", "15\u00B0");
- execute.command("FS.Tinside", "19.5\u00B0");
- execute.command("FS.PIR", "off");
- execute.command("FS.Window", "off");
+ commands.execute("FS.Toutside", "15\u00B0");
+ commands.execute("FS.Tinside", "19.5\u00B0");
+ commands.execute("FS.PIR", "off");
+ commands.execute("FS.Window", "off");
end
rule "--Fake sensors Toutside inc"
@@ -1477,8 +1476,8 @@ when
Event(source == "FS.Toutside", $v: value, eval(util.parseDouble(value) < 50))
Event(source == "FS.Toutside.inc" , value == "on")
then
- execute.command("FS.Toutside.inc","off");
- execute.command("FS.Toutside", util.shiftDouble($v.toString(), 0.1, "\u00B0"));
+ commands.execute("FS.Toutside.inc","off");
+ commands.execute("FS.Toutside", util.shiftDouble($v.toString(), 0.1, "\u00B0"));
end
rule "--Fake sensors Toutside dec"
@@ -1487,8 +1486,8 @@ when
Event(source == "FS.Toutside", $v: value, eval(util.parseDouble(value) > -40))
Event(source == "FS.Toutside.dec" , value == "on")
then
- execute.command("FS.Toutside.dec","off");
- execute.command("FS.Toutside", util.shiftDouble($v.toString(), -0.1, "\u00B0"));
+ commands.execute("FS.Toutside.dec","off");
+ commands.execute("FS.Toutside", util.shiftDouble($v.toString(), -0.1, "\u00B0"));
end
rule "--Fake sensors Tinside inc"
@@ -1497,8 +1496,8 @@ when
Event(source == "FS.Tinside", $v: value, eval(util.parseDouble(value) < 40))
Event(source == "FS.Tinside.inc" , value == "on")
then
- execute.command("FS.Tinside.inc","off");
- execute.command("FS.Tinside", util.shiftDouble($v.toString(), 0.1, "\u00B0"));
+ commands.execute("FS.Tinside.inc","off");
+ commands.execute("FS.Tinside", util.shiftDouble($v.toString(), 0.1, "\u00B0"));
end
rule "--Fake sensors Tinside dec"
@@ -1507,8 +1506,8 @@ when
Event(source == "FS.Tinside", $v: value, eval(util.parseDouble(value) > 0))
Event(source == "FS.Tinside.dec" , value == "on")
then
- execute.command("FS.Tinside.dec","off");
- execute.command("FS.Tinside", util.shiftDouble($v.toString(), -0.1, "\u00B0"));
+ commands.execute("FS.Tinside.dec","off");
+ commands.execute("FS.Tinside", util.shiftDouble($v.toString(), -0.1, "\u00B0"));
end
rule "--Fake sensors PIR off"
@@ -1516,7 +1515,7 @@ rule "--Fake sensors PIR off"
when
Event(source=="FS.PIR", value=="on")
then
- execute.command("FS.PIR", "off");
+ commands.execute("FS.PIR", "off");
end
// Fake sensors end
\ No newline at end of file
diff --git a/controller/src/test/resources/org/openremote/test/rules/vacation/Vacation.drl b/controller/src/test/resources/org/openremote/test/rules/vacation/Vacation.drl
index 27b3e7c94..f7bdf023e 100644
--- a/controller/src/test/resources/org/openremote/test/rules/vacation/Vacation.drl
+++ b/controller/src/test/resources/org/openremote/test/rules/vacation/Vacation.drl
@@ -1,6 +1,6 @@
package org.openremote.test.rules;
-global org.openremote.controller.rules.CommandFacade execute;
+global org.openremote.controller.command.Commands commands;
import org.openremote.controller.command.*;
import org.openremote.controller.event.*;
@@ -42,14 +42,14 @@ rule "Set Night Temperature"
when
CustomStateEvent( source == "time of day", value == "night" ) and not Vacation()
then
- execute.command("temp", 18);
+ commands.execute("temp", 18);
end
rule "Set Night Temperature when on Vacation"
when
CustomStateEvent ( source == "time of day", value == "night" ) and exists Vacation()
then
- execute.command("temp", 15);
+ commands.execute("temp", 15);
end
/* Set day temperatures differently depending on the presence of vacation fact */
@@ -58,13 +58,13 @@ rule "Set Day Temperature"
when
CustomStateEvent ( source == "time of day", value == "day" ) and not Vacation()
then
- execute.command("temp", 21);
+ commands.execute("temp", 21);
end
rule "Set Day Temperature when on Vacation"
when
Event ( source == "time of day", value == "day" ) and exists Vacation()
then
- execute.command("temp", 15);
+ commands.execute("temp", 15);
end