[insteon] Fix x10 device message handling (#18031)

Signed-off-by: Jeremy Setton <jeremy.setton@gmail.com>
This commit is contained in:
Jeremy 2025-01-04 18:44:31 -05:00 committed by Jacob Laursen
parent 44ff26a29d
commit 0dce37ae1e
5 changed files with 37 additions and 26 deletions

View File

@ -564,16 +564,10 @@ public abstract class BaseDevice<@NonNull T extends DeviceAddress, @NonNull S ex
public void requestReplied(Msg msg) {
DeviceFeature feature = getFeatureQueried();
if (feature != null && feature.isMyReply(msg)) {
if (msg.isReplyAck()) {
// mark feature queried as acked
feature.setQueryStatus(QueryStatus.QUERY_ACKED);
} else {
logger.debug("got a reply nack msg: {}", msg);
// mark feature queried as processed and answered
setFeatureQueried(null);
feature.setQueryMessage(null);
feature.setQueryStatus(QueryStatus.QUERY_ANSWERED);
}
// mark feature queried as processed and answered
setFeatureQueried(null);
feature.setQueryMessage(null);
feature.setQueryStatus(QueryStatus.QUERY_ANSWERED);
}
}

View File

@ -906,6 +906,25 @@ public class InsteonDevice extends BaseDevice<InsteonAddress, InsteonDeviceHandl
}
}
/**
* Notifies that a message request was replied for this device
*
* @param msg the message received
*/
@Override
public void requestReplied(Msg msg) {
DeviceFeature feature = getFeatureQueried();
if (feature != null && feature.isMyReply(msg)) {
if (msg.isReplyAck()) {
// mark feature queried as acked
feature.setQueryStatus(QueryStatus.QUERY_ACKED);
} else {
logger.debug("got a reply nack msg: {}", msg);
super.requestReplied(msg);
}
}
}
/**
* Notifies that the link db has been updated for this device
*/

View File

@ -447,9 +447,6 @@ public class InsteonModem extends BaseDevice<InsteonAddress, InsteonBridgeHandle
if (address == null) {
return;
}
if (msg.isX10()) {
lastX10Address = msg.isX10Address() ? (X10Address) address : null;
}
long time = System.currentTimeMillis();
Device device = getAddress().equals(address) ? this : getDevice(address);
if (device != null) {
@ -482,13 +479,12 @@ public class InsteonModem extends BaseDevice<InsteonAddress, InsteonBridgeHandle
}
private void handleX10Message(Msg msg) throws FieldException {
X10Address address = lastX10Address;
if (msg.isX10Address()) {
// store the x10 address to use with the next cmd
lastX10Address = msg.getX10Address();
} else if (address != null) {
X10Address address = msg.isX10Address() ? msg.getX10Address() : lastX10Address;
if (address != null) {
handleMessage(address, msg);
lastX10Address = null;
// store the x10 address to use with the next cmd
lastX10Address = msg.isX10Address() ? address : null;
}
}

View File

@ -39,7 +39,7 @@ public class X10Address implements DeviceAddress {
private final byte unitCode;
public X10Address(byte address) {
this.houseCode = (byte) (address >> 4);
this.houseCode = (byte) (address >> 4 & 0x0F);
this.unitCode = (byte) (address & 0x0F);
}
@ -49,7 +49,7 @@ public class X10Address implements DeviceAddress {
}
public X10Address(String address) throws IllegalArgumentException {
String[] parts = address.replace(".", "").split("");
String[] parts = address.replace(".", "").split("", 2);
if (parts.length != 2) {
throw new IllegalArgumentException("Invalid X10 address format");
}

View File

@ -242,11 +242,13 @@ public abstract class MessageDispatcher extends BaseFeatureHandler {
@Override
public boolean dispatch(Msg msg) {
try {
byte cmd = msg.getByte("rawX10");
MessageHandler handler = feature.getOrDefaultMsgHandler(cmd);
logger.debug("{}:{}->{} X10", getX10Device().getAddress(), feature.getName(),
handler.getClass().getSimpleName());
handler.handleMessage(cmd, msg);
if (msg.isX10Command()) {
byte cmd = (byte) (msg.getByte("rawX10") & 0x0F);
MessageHandler handler = feature.getOrDefaultMsgHandler(cmd);
logger.debug("{}:{}->{} X10", getX10Device().getAddress(), feature.getName(),
handler.getClass().getSimpleName());
handler.handleMessage(cmd, msg);
}
} catch (FieldException e) {
logger.warn("error parsing, dropping msg {}", msg);
}