diff --git a/ESH-INF/thing/rts.xml b/ESH-INF/thing/rts.xml
index 609ac2b..935a8ca 100644
--- a/ESH-INF/thing/rts.xml
+++ b/ESH-INF/thing/rts.xml
@@ -24,6 +24,11 @@
Must contain the Protocol + Address + Index (using '-' as separator). For instance : RTS-123ABC-0 (According to the RFLink protocol, Index is not used for now and '0' should be used)
+
+
+
+ Reference Address Id to project the incoming message (blank by default)
+
diff --git a/src/main/java/org/openhab/binding/rflink/config/RfLinkDeviceConfiguration.java b/src/main/java/org/openhab/binding/rflink/config/RfLinkDeviceConfiguration.java
index e2b9b19..151f17c 100644
--- a/src/main/java/org/openhab/binding/rflink/config/RfLinkDeviceConfiguration.java
+++ b/src/main/java/org/openhab/binding/rflink/config/RfLinkDeviceConfiguration.java
@@ -19,6 +19,9 @@ public class RfLinkDeviceConfiguration {
// Device Id
public String deviceId;
+ // Linked Adress Id
+ public String linkedAddressId = null;
+
// Number of times to repeat a message
public int repeats = 1;
@@ -34,4 +37,8 @@ public String toString() {
+ (shutterDuration > 0 ? "timing=" + shutterDuration + "s" : "");
}
+ public boolean hasLinkedAddressId() {
+ return linkedAddressId != null && !linkedAddressId.trim().isEmpty();
+ }
+
}
diff --git a/src/main/java/org/openhab/binding/rflink/device/RfLinkAbstractDevice.java b/src/main/java/org/openhab/binding/rflink/device/RfLinkAbstractDevice.java
index 20617a4..77faec3 100644
--- a/src/main/java/org/openhab/binding/rflink/device/RfLinkAbstractDevice.java
+++ b/src/main/java/org/openhab/binding/rflink/device/RfLinkAbstractDevice.java
@@ -41,6 +41,9 @@ public abstract class RfLinkAbstractDevice implements RfLinkDevice {
public void initializeFromMessage(RfLinkDeviceConfiguration config, RfLinkMessage message) {
setConfig(config);
this.message = message;
+ if (getConfig() != null && getConfig().hasLinkedAddressId()) {
+ // must "echo" the input command to the linked DeviceId
+ }
}
@Override
@@ -77,10 +80,36 @@ public RfLinkDeviceConfiguration getConfig() {
}
@Override
- public Collection buildPackets() {
+ public Collection buildOutputPackets() {
return Collections.singleton(getMessage().buildRfLinkPacket(RfLinkPacketType.OUTPUT, getCommandSuffix()));
}
+ @Override
+ public Collection buildEchoPackets() {
+ if (config.hasLinkedAddressId()) {
+ if (getMessage() != null) {
+ String echoMessage = getMessage().getRawMessage();
+ if (echoMessage != null) {
+ String sourceAddressId = "ID=" + getMessage().getDeviceId();
+ String targetAddressId = "ID=" + config.linkedAddressId;
+ if (echoMessage.contains(sourceAddressId)) {
+ // take the input message and replace the initial AddressId by the linked addressId
+ echoMessage = echoMessage.replace(sourceAddressId, targetAddressId);
+ RfLinkPacket packet = new RfLinkPacket(RfLinkPacketType.ECHO, echoMessage);
+ return Collections.singletonList(packet);
+ } else {
+ // original AddressId not found in the input Message
+ }
+ } else {
+ // no initial raw message : unable to build echo message
+ }
+ } else {
+ // no initial message (why are we here ?!?)
+ }
+ }
+ return Collections.emptyList();
+ }
+
// to override in subClasses if needed
public String getCommandSuffix() {
return null;
diff --git a/src/main/java/org/openhab/binding/rflink/device/RfLinkColorDevice.java b/src/main/java/org/openhab/binding/rflink/device/RfLinkColorDevice.java
index 211e918..1490112 100644
--- a/src/main/java/org/openhab/binding/rflink/device/RfLinkColorDevice.java
+++ b/src/main/java/org/openhab/binding/rflink/device/RfLinkColorDevice.java
@@ -186,7 +186,7 @@ protected boolean handleCommandTransmission() {
}
@Override
- public Collection buildPackets() {
+ public Collection buildOutputPackets() {
logger.debug("Color decodeMessage: command={}, stateColor={}, stateOnOff={}", command, stateColor, stateOnOff);
if (command == null) {
@@ -231,4 +231,5 @@ public Collection buildPackets() {
}
return messages;
}
+
}
diff --git a/src/main/java/org/openhab/binding/rflink/device/RfLinkDevice.java b/src/main/java/org/openhab/binding/rflink/device/RfLinkDevice.java
index 8caa08a..afda327 100644
--- a/src/main/java/org/openhab/binding/rflink/device/RfLinkDevice.java
+++ b/src/main/java/org/openhab/binding/rflink/device/RfLinkDevice.java
@@ -41,11 +41,18 @@ public interface RfLinkDevice {
/**
* Procedure generate RfLinkPacket[s] to send to the bridge
*
- * @return Collection of RfLinkPacket messages to be send over serial (OUTPUT type) or to handle as incoming events
- * (ECHO type). Several elements in case of composite command
+ * @return Collection of RfLinkPacket messages to be send over serial (OUTPUT type)
*/
- public Collection buildPackets();
+ public Collection buildOutputPackets();
+
+ /**
+ * Procedure generate RfLinkPackets[s] to send to the handler as Incoming messages (notification service)
+ *
+ * @return Collection of RfLinkPacket[s] to handle as incoming events
+ * (ECHO type). Several elements in case of composite command
+ */
+ public Collection buildEchoPackets();
/**
* Procedure to get device unique Identifier
@@ -93,7 +100,7 @@ void initializeFromChannel(RfLinkDeviceConfiguration config, ChannelUID channelU
/**
* Initializes Device from reception message
- *
+ *
* @param config TODO
* @param message the RfLink message received from the bridge
*
diff --git a/src/main/java/org/openhab/binding/rflink/handler/RfLinkHandler.java b/src/main/java/org/openhab/binding/rflink/handler/RfLinkHandler.java
index 2c858aa..1d96bc4 100644
--- a/src/main/java/org/openhab/binding/rflink/handler/RfLinkHandler.java
+++ b/src/main/java/org/openhab/binding/rflink/handler/RfLinkHandler.java
@@ -89,15 +89,12 @@ public void handleCommand(ChannelUID channelUID, Command command) {
try {
RfLinkDevice device = RfLinkDeviceFactory.createDeviceFromType(getThing().getThingTypeUID());
device.initializeFromChannel(config, channelUID, command);
+ processEchoPackets(device);
if (isRtsPositionTrackerEnabled(device)) {
// need specific handling : the command is processed by the tracker
handleRtsPositionTracker(this, device);
} else {
- int repeats = Math.min(Math.max(getConfiguration().repeats, 1), 20);
- Collection packets = device.buildPackets();
- for (int i = 0; i < repeats; i++) {
- bridgeHandler.processPackets(packets);
- }
+ processOutputPackets(device);
updateThingStates(device);
}
} catch (RfLinkNotImpException e) {
@@ -112,9 +109,10 @@ public void handleCommand(ChannelUID channelUID, Command command) {
@Override
public boolean handleIncomingMessage(ThingUID bridge, RfLinkMessage incomingMessage) throws Exception {
String id = incomingMessage.getDeviceKey();
- if (config != null && id.equals(config.deviceId)) {
+ if (config != null && id.equalsIgnoreCase(config.deviceId)) {
RfLinkDevice device = RfLinkDeviceFactory.createDeviceFromMessage(incomingMessage);
device.initializeFromMessage(config, incomingMessage);
+ processEchoPackets(device);
updateStatus(ThingStatus.ONLINE);
if (isRtsPositionTrackerEnabled(device)) {
handleRtsPositionTracker(this, device);
@@ -124,7 +122,19 @@ public boolean handleIncomingMessage(ThingUID bridge, RfLinkMessage incomingMess
return true;
}
return false;
+ }
+
+ private void processOutputPackets(RfLinkDevice device) throws RfLinkException {
+ int repeats = Math.min(Math.max(getConfiguration().repeats, 1), 20);
+ Collection packets = device.buildOutputPackets();
+ for (int i = 0; i < repeats; i++) {
+ bridgeHandler.processPackets(packets);
+ }
+ }
+ private void processEchoPackets(RfLinkDevice device) throws RfLinkException {
+ Collection echoPackets = device.buildEchoPackets();
+ bridgeHandler.processPackets(echoPackets);
}
@Override
@@ -221,4 +231,9 @@ private RfLinkRtsPositionHandler getShutterInfos(RfLinkHandler handler, RfLinkDe
return shutterInfos;
}
+ @Override
+ public String toString() {
+ return "RfLinkHandler [" + config + "]";
+ }
+
}
diff --git a/src/main/java/org/openhab/binding/rflink/handler/RfLinkRtsPositionHandler.java b/src/main/java/org/openhab/binding/rflink/handler/RfLinkRtsPositionHandler.java
index 0072b08..3558c6f 100644
--- a/src/main/java/org/openhab/binding/rflink/handler/RfLinkRtsPositionHandler.java
+++ b/src/main/java/org/openhab/binding/rflink/handler/RfLinkRtsPositionHandler.java
@@ -190,7 +190,7 @@ private void sendCommand(Command command) {
private void sendDeviceCommand(RfLinkDevice device) {
try {
- handler.getBridgeHandler().processPackets(device.buildPackets());
+ handler.getBridgeHandler().processPackets(device.buildOutputPackets());
} catch (RfLinkException e) {
logger.error("Could not send Device event " + device + " on bridge " + handler.getBridgeHandler(), e);
}
diff --git a/src/main/java/org/openhab/binding/rflink/message/RfLinkMessage.java b/src/main/java/org/openhab/binding/rflink/message/RfLinkMessage.java
index 744f41b..4270b6c 100644
--- a/src/main/java/org/openhab/binding/rflink/message/RfLinkMessage.java
+++ b/src/main/java/org/openhab/binding/rflink/message/RfLinkMessage.java
@@ -102,13 +102,18 @@ public String getRawMessage() {
}
public String getDeviceKey() {
- String deviceIdKey = protocol + ID_DELIMITER + deviceId;
- if (deviceSubId != null) {
- deviceIdKey += ID_DELIMITER + deviceSubId;
+ String deviceIdKey = getBaseDeviceKey();
+ if (getDeviceSubId() != null) {
+ deviceIdKey += ID_DELIMITER + getDeviceSubId();
}
return deviceIdKey;
}
+ public String getBaseDeviceKey() {
+ String deviceIdKey = getProtocol() + ID_DELIMITER + getDeviceId();
+ return deviceIdKey;
+ }
+
public String getProtocol() {
return protocol;
}
diff --git a/src/main/java/org/openhab/binding/rflink/packet/RfLinkPacket.java b/src/main/java/org/openhab/binding/rflink/packet/RfLinkPacket.java
index 26a097f..d8c3c4c 100644
--- a/src/main/java/org/openhab/binding/rflink/packet/RfLinkPacket.java
+++ b/src/main/java/org/openhab/binding/rflink/packet/RfLinkPacket.java
@@ -18,8 +18,6 @@ public class RfLinkPacket {
private RfLinkPacketType type;
private String packet;
- public static String PING = "10;PING;";
-
public RfLinkPacket(RfLinkPacketType type, String packet) {
super();
this.type = type;