[enocean] Fix injector outbound channel mapping (#20791)

Signed-off-by: Sven Schad <svnsssd@gmail.com>
This commit is contained in:
Sven Schad
2026-05-25 12:54:09 +02:00
committed by GitHub
parent c10ded5d64
commit fa515647ed
2 changed files with 32 additions and 11 deletions
@@ -31,6 +31,7 @@ import org.openhab.binding.enocean.internal.eep.EEPFactory;
import org.openhab.binding.enocean.internal.eep.EEPType;
import org.openhab.binding.enocean.internal.injector.InjectorProfileType;
import org.openhab.binding.enocean.internal.messages.BasePacket;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
@@ -194,13 +195,14 @@ public class EnOceanDatagramInjectorHandler extends EnOceanBaseThingHandler {
String channelId = channelUID.getId();
ChannelTypeUID channelTypeUID = channel.getChannelTypeUID();
String channelTypeId = (channelTypeUID != null) ? channelTypeUID.getId() : "";
Configuration channelConfig = channel.getConfiguration();
if (!localSendingProfileType.isChannelSupported(channelId, channelTypeId)) {
return;
}
try {
boolean wasSent = sendMessage(localSendingProfileType, channelId, command);
boolean wasSent = sendMessage(localSendingProfileType, channelId, command, channelConfig);
if (wasSent && localSendingProfileType.getChannelId().equals(channelId) && command instanceof State state) {
updateState(channelUID, state);
}
@@ -208,7 +210,7 @@ public class EnOceanDatagramInjectorHandler extends EnOceanBaseThingHandler {
if (localSendingProfileType == InjectorProfileType.MOTION_A5_07_01
&& localSendingProfileType.getChannelId().equals(channelId) && command instanceof OnOffType onOff) {
if (onOff == OnOffType.ON) {
startMotionRetriggerJob(localSendingProfileType, channelId);
startMotionRetriggerJob(localSendingProfileType, channelId, channelConfig);
} else {
stopMotionRetriggerJob();
updateState(channelUID, OnOffType.OFF);
@@ -219,7 +221,8 @@ public class EnOceanDatagramInjectorHandler extends EnOceanBaseThingHandler {
}
}
private synchronized void startMotionRetriggerJob(InjectorProfileType profileType, String channelId) {
private synchronized void startMotionRetriggerJob(InjectorProfileType profileType, String channelId,
Configuration channelConfig) {
stopMotionRetriggerJob();
motionRetriggerJob = scheduler.scheduleWithFixedDelay(() -> {
try {
@@ -227,7 +230,7 @@ public class EnOceanDatagramInjectorHandler extends EnOceanBaseThingHandler {
logger.debug("Motion retrigger skipped: injector not operational");
return;
}
sendMessage(profileType, channelId, OnOffType.ON);
sendMessage(profileType, channelId, OnOffType.ON, channelConfig);
} catch (Exception e) {
logger.debug("Motion retrigger send failed", e);
}
@@ -264,10 +267,11 @@ public class EnOceanDatagramInjectorHandler extends EnOceanBaseThingHandler {
}
}
private boolean sendMessage(InjectorProfileType profileType, String channelId, Command command) {
private boolean sendMessage(InjectorProfileType profileType, String channelId, Command command,
Configuration channelConfig) {
EEP eep = EEPFactory.createEEP(profileType.getSendingEEPType());
ChannelUID channelUID = new ChannelUID(getThing().getUID(), channelId);
if (eep.convertFromCommand(getThing(), channelUID, command, id -> getCurrentState(id), null).hasData()) {
if (eep.convertFromCommand(channelId, profileType.getEepChannelTypeId(), command, id -> getCurrentState(id),
channelConfig).hasData()) {
BasePacket msg = eep.setSenderId(senderId).setDestinationId(destinationId)
.setSuppressRepeating(getConfiguration().suppressRepeating).getERP1Message();
if (msg == null) {
@@ -13,6 +13,7 @@
package org.openhab.binding.enocean.internal.injector;
import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANNEL_CONTACT;
import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANNEL_GENERAL_SWITCHING;
import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.CHANNEL_MOTIONDETECTION;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -23,19 +24,23 @@ import org.openhab.binding.enocean.internal.eep.EEPType;
*/
@NonNullByDefault
public enum InjectorProfileType {
FTK_D5_00_01("FTK_D5_00_01", EEPType.ContactAndSwitch01, "switch", CHANNEL_CONTACT),
MOTION_A5_07_01("MOTION_A5_07_01", EEPType.OCCUPANCYSENSOR_A5_07_01, "switch", CHANNEL_MOTIONDETECTION);
FTK_D5_00_01("FTK_D5_00_01", EEPType.ContactAndSwitch01, "switch", CHANNEL_GENERAL_SWITCHING, CHANNEL_CONTACT),
MOTION_A5_07_01("MOTION_A5_07_01", EEPType.OCCUPANCYSENSOR_A5_07_01, "switch", CHANNEL_GENERAL_SWITCHING,
CHANNEL_MOTIONDETECTION);
private final String id;
private final EEPType sendingEEPType;
private final String channelId;
private final String channelTypeId;
private final String eepChannelTypeId;
InjectorProfileType(String id, EEPType sendingEEPType, String channelId, String channelTypeId) {
InjectorProfileType(String id, EEPType sendingEEPType, String channelId, String channelTypeId,
String eepChannelTypeId) {
this.id = id;
this.sendingEEPType = sendingEEPType;
this.channelId = channelId;
this.channelTypeId = channelTypeId;
this.eepChannelTypeId = eepChannelTypeId;
}
public EEPType getSendingEEPType() {
@@ -50,6 +55,10 @@ public enum InjectorProfileType {
return channelTypeId;
}
public String getEepChannelTypeId() {
return eepChannelTypeId;
}
public static boolean isProfileChannelId(String channelId) {
for (InjectorProfileType type : values()) {
if (type.channelId.equals(channelId)) {
@@ -60,7 +69,15 @@ public enum InjectorProfileType {
}
public boolean isChannelSupported(String channelId, String channelTypeId) {
return this.channelId.equals(channelId) && this.channelTypeId.equals(channelTypeId);
if (!this.channelId.equals(channelId)) {
return false;
}
return matchesChannelType(channelTypeId, this.channelTypeId)
|| matchesChannelType(channelTypeId, eepChannelTypeId);
}
private boolean matchesChannelType(String candidateTypeId, String expectedTypeId) {
return expectedTypeId.equals(candidateTypeId) || candidateTypeId.endsWith(":" + expectedTypeId);
}
public static InjectorProfileType getType(String id) {