Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

IRtrans : fix double processing of IR commands received #1364

Merged
merged 1 commit into from
Aug 24, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,13 @@ protected void parseBuffer(String itemName, Command aCommand, Direction theDirec
// IRTrans devices return a string starting with RCV_HEX each time it captures an
// infrared sequence from a remote control
if(message.contains("RCV_HEX")){
parseHexMessage(itemName,message);
parseHexMessage(itemName,message, aCommand);
}

// IRTrans devices return a string starting with RCV_COM each time it captures an
// infrared sequence from a remote control that is stored in the device's internal dB
if(message.contains("RCV_COM")){
parseIRDBMessage(itemName,message);
parseIRDBMessage(itemName,message, aCommand);
}
} else {
logger.warn("Received some non-compliant garbage ({})- Parsing is skipped",byteBuffer.toString());
Expand All @@ -468,8 +468,10 @@ protected void parseBuffer(String itemName, Command aCommand, Direction theDirec
* the qualified items
* @param message
* the message
* @param ohCommand
* the openHAB command
*/
protected void parseHexMessage(String itemName,String message){
protected void parseHexMessage(String itemName,String message, Command ohCommand){

Pattern HEX_PATTERN = Pattern.compile("RCV_HEX (.*)");
Matcher matcher = HEX_PATTERN.matcher(message);
Expand All @@ -480,7 +482,7 @@ protected void parseHexMessage(String itemName,String message){
IrCommand theCommand = getIrCommand(command);

if(theCommand != null ) {
parseDecodedCommand(itemName,theCommand);
parseDecodedCommand(itemName,theCommand,ohCommand);
} else {
logger.error("{} does not match any know IRtrans command",command);
}
Expand All @@ -491,7 +493,7 @@ protected void parseHexMessage(String itemName,String message){
}


protected void parseIRDBMessage(String itemName,String message){
protected void parseIRDBMessage(String itemName,String message, Command ohCommand){

Pattern IRDB_PATTERN = Pattern.compile("RCV_COM (.*),(.*),(.*),(.*)");
Matcher matcher = IRDB_PATTERN.matcher(message);
Expand All @@ -502,14 +504,14 @@ protected void parseIRDBMessage(String itemName,String message){
theCommand.remote = matcher.group(1);
theCommand.command = matcher.group(2);

parseDecodedCommand(itemName,theCommand);
parseDecodedCommand(itemName,theCommand,ohCommand);

} else {
logger.error("{} does not match the IRDB IRtrans message formet ({})",message,matcher.pattern());
logger.error("{} does not match the IRDB IRtrans message format ({})",message,matcher.pattern());
}
}

protected void parseDecodedCommand(String itemName, IrCommand theCommand) {
protected void parseDecodedCommand(String itemName, IrCommand theCommand, Command ohCommand) {

if(theCommand != null) {
//traverse the providers, for each provider, check each binding if it matches theCommand
Expand All @@ -525,25 +527,27 @@ protected void parseDecodedCommand(String itemName, IrCommand theCommand) {
providerCommand.remote = provider.getRemote(itemName,aCommand);
providerCommand.command = provider.getIrCommand(itemName, aCommand);

if(providerCommand.matches(theCommand)){
if(aCommand==ohCommand) {
if(providerCommand.matches(theCommand)){

List<Class<? extends State>> stateTypeList = provider.getAcceptedDataTypes(itemName,aCommand);
State newState = null;
List<Class<? extends State>> stateTypeList = provider.getAcceptedDataTypes(itemName,aCommand);
State newState = null;

if(aCommand instanceof DecimalType) {
newState = createStateFromString(stateTypeList,theCommand.remote+","+theCommand.command);
} else {
newState = createStateFromString(stateTypeList,aCommand.toString());
}
if(aCommand instanceof DecimalType) {
newState = createStateFromString(stateTypeList,theCommand.remote+","+theCommand.command);
} else {
newState = createStateFromString(stateTypeList,aCommand.toString());
}

if(newState != null) {
eventPublisher.postUpdate(itemName, newState);
} else {
logger.warn("Can not create an Item State to match command {} on item {} ",aCommand,itemName);
if(newState != null) {
eventPublisher.postUpdate(itemName, newState);
} else {
logger.warn("Can not create an Item State to match command {} on item {} ",aCommand,itemName);
}
}
else {
logger.info("The IRtrans command '{},{}' does not match the command '{}' of the binding configuration for item '{}'",new Object[] {theCommand.remote,theCommand.command,ohCommand,itemName});
}
}
else {
logger.warn("The IRtrans command does not match the command of the binding configuration for {}",itemName);
}
}
}
Expand Down