use of org.openremote.agent.protocol.controller.command.ControllerCommandMapped in project openremote by openremote.
the class ControllerProtocol method doLinkAttribute.
@Override
protected void doLinkAttribute(String assetId, Attribute<?> attribute, ControllerAgentLink agentLink) {
AttributeRef attributeRef = new AttributeRef(assetId, attribute.getName());
String deviceName = agentLink.getDeviceName().orElse(null);
String sensorName = agentLink.getSensorName().orElse(null);
String commandDeviceName = agentLink.getCommandDeviceName().orElse(null);
String commandName = agentLink.getCommandName().orElse(null);
Map<String, List<String>> commandsMap = agentLink.getCommandsMap().orElse(null);
/*
* Build Sensor Status info for polling request
*/
if (sensorName != null) {
LOG.finer("### Adding new sensor [" + deviceName + "," + sensorName + "] linked to " + agent.getId() + " (" + agent.getName() + ")");
controller.addSensor(attributeRef, new ControllerSensor(deviceName, sensorName));
// Properly stop previously existing polling on device name --> use of false parameter
if (pollingSensorList.containsKey(deviceName)) {
pollingSensorList.get(deviceName).cancel(true);
}
this.initStatusDone.put(attributeRef, false);
// Get initial status of sensor
collectInitialStatus(attributeRef, deviceName, sensorName);
// Put new polling on a new device name or update previous
this.schedulePollingTask(deviceName);
}
/*
* If linked Attribute contains command info, we build {@link org.openremote.agent.protocol.controller.ControllerCommand } depending on
* attribute information.
*/
if (commandName != null || commandsMap != null) {
// If no command specific device name is set, then we're using deviceName
if (commandDeviceName == null && deviceName != null) {
commandDeviceName = deviceName;
}
if (commandName != null) {
controller.addCommand(attributeRef, new ControllerCommandBasic(commandDeviceName, commandName));
} else {
assert commandsMap.size() > 0;
controller.addCommand(attributeRef, new ControllerCommandMapped(commandDeviceName, computeCommandsMapFromMultiValue(commandsMap)));
}
}
}
Aggregations