// Bridge properties
public static final String PROPERTY_BASE_ID = "Base ID";
- public static final String PROPERTY_REMAINING_WRITE_CYCLES_Base_ID = "Remaining Base ID Write Cycles";
+ public static final String PROPERTY_REMAINING_WRITE_CYCLES_BASE_ID = "Remaining Base ID Write Cycles";
public static final String PROPERTY_APP_VERSION = "APP Version";
public static final String PROPERTY_API_VERSION = "API Version";
public static final String PROPERTY_CHIP_ID = "Chip ID";
public static final String PARAMETER_ENOCEANID = "enoceanId";
// Channel config parameter
- public static final String PARAMETER_CHANNEL_TeachInMSG = "teachInMSG";
- public static final String PARAMETER_CHANNEL_Duration = "duration";
- public static final String PARAMETER_CHANNEL_SwitchMode = "switchMode";
+ public static final String PARAMETER_CHANNEL_TEACHINMSG = "teachInMSG";
+ public static final String PARAMETER_CHANNEL_DURATION = "duration";
+ public static final String PARAMETER_CHANNEL_SWITCHMODE = "switchMode";
// Manufacturer Ids - used to recognize special EEPs during auto discovery
public static final int ELTAKOID = 0x00d;
*/
package org.openhab.binding.enocean.internal;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.thing.type.ChannelTypeUID;
/**
* This class holds information for creating a channel of an EnOcean thing like acceptedItemType and
* channelTypeUID
*/
+@NonNullByDefault
public class EnOceanChannelDescription {
public final ChannelTypeUID channelTypeUID;
public final String acceptedItemType;
- @NonNull
public final String label;
public final boolean isStateChannel;
public final boolean autoCreate;
* @param autoCreate create channel during thing initialization, otherwise channel is created
* manually/predefined
*/
- public EnOceanChannelDescription(ChannelTypeUID channelTypeUID, String itemType, String label,
+ public EnOceanChannelDescription(ChannelTypeUID channelTypeUID, @Nullable String itemType, @Nullable String label,
boolean isStateChannel, boolean autoCreate) {
this.channelTypeUID = channelTypeUID;
- this.acceptedItemType = itemType;
- if (label != null) {
- this.label = label;
- } else {
- this.label = "";
- }
+ this.acceptedItemType = itemType != null ? itemType : "";
+ this.label = label != null ? label : "";
this.isStateChannel = isStateChannel;
this.autoCreate = autoCreate;
*/
package org.openhab.binding.enocean.internal;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public enum EnOceanConfigStatusMessage {
PORT_MISSING("missing-port-configuration"),
SENDERID_MISSING("missing-senderId-configuration"),
*/
package org.openhab.binding.enocean.internal;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanException extends Exception {
/**
*/
private static final long serialVersionUID = 1L;
- public EnOceanException(String msg) {
+ public EnOceanException(@Nullable String msg) {
super(msg);
}
}
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.discovery.EnOceanDeviceDiscoveryService;
import org.openhab.binding.enocean.internal.handler.EnOceanBaseActuatorHandler;
import org.openhab.binding.enocean.internal.handler.EnOceanBaseSensorHandler;
import org.openhab.core.thing.binding.ThingHandlerFactory;
import org.openhab.core.thing.link.ItemChannelLinkRegistry;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.enocean")
public class EnOceanHandlerFactory extends BaseThingHandlerFactory {
private Map<ThingUID, ServiceRegistration<?>> discoveryServiceRegs = new HashMap<>();
- @Reference
- SerialPortManager serialPortManager;
+ private final SerialPortManager serialPortManager;
+ private final ThingManager thingManager;
+ private final ItemChannelLinkRegistry itemChannelLinkRegistry;
- @Reference
- ItemChannelLinkRegistry itemChannelLinkRegistry;
-
- @Reference
- ThingManager thingManager;
+ @Activate
+ public EnOceanHandlerFactory(final @Reference SerialPortManager serialPortManager,
+ final @Reference ThingManager thingManager,
+ final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry) {
+ // Obtain references to thes service using an OSGi reference
+ this.serialPortManager = serialPortManager;
+ this.thingManager = thingManager;
+ this.itemChannelLinkRegistry = itemChannelLinkRegistry;
+ }
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
}
@Override
- protected ThingHandler createHandler(Thing thing) {
+ protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
-
if (EnOceanBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
EnOceanBridgeHandler bridgeHandler = new EnOceanBridgeHandler((Bridge) thing, serialPortManager);
registerDeviceDiscoveryService(bridgeHandler);
@Override
protected void removeHandler(ThingHandler thingHandler) {
- if (this.discoveryServiceRegs != null) {
- ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.get(thingHandler.getThing().getUID());
- if (serviceReg != null) {
- serviceReg.unregister();
- discoveryServiceRegs.remove(thingHandler.getThing().getUID());
- }
+ ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.get(thingHandler.getThing().getUID());
+ if (serviceReg != null) {
+ serviceReg.unregister();
+ discoveryServiceRegs.remove(thingHandler.getThing().getUID());
}
}
import java.util.Arrays;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class Helper {
public static byte[] concatAll(byte[] a, byte[]... rest) {
- if (rest == null) {
+ if (rest.length == 0) {
return a;
}
offset += array.length;
}
}
- return result;
+ return result != null ? result : new byte[0];
}
public static int tryParseInt(String value, int defaultValue) {
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanActuatorConfig extends EnOceanBaseConfig {
public int channel;
- public Integer senderIdOffset = null;
- public String manufacturerId;
- public String teachInType;
+ public @Nullable Integer senderIdOffset = null;
+ public String manufacturerId = "";
+ public String teachInType = "";
- public String sendingEEPId;
+ public String sendingEEPId = "";
public int pollingInterval;
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanBridgeConfig {
public enum ESPVersion {
}
}
- public String path;
+ public String path = "";
- public String espVersion;
+ public String espVersion = "ESP3";
public boolean rs485;
- public String rs485BaseId;
+ public String rs485BaseId = "";
- public Integer nextSenderId;
+ public @Nullable Integer nextSenderId;
- public boolean enableSmack;
+ public boolean enableSmack = true;
public boolean sendTeachOuts;
- public EnOceanBridgeConfig() {
- espVersion = "ESP3";
- sendTeachOuts = false;
- enableSmack = true;
- nextSenderId = null;
- }
-
public ESPVersion getESPVersion() {
return ESPVersion.getESPVersion(espVersion);
}
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Holger Englert - Initial contribution
*/
+@NonNullByDefault
public class EnOceanChannelContactConfig {
// Swap Open/Closed value, e.g.
// Eltako FPE-1: false, Eltako FPE-2: true
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class EnOceanChannelDimmerConfig {
public int rampingTime = 0;
import java.security.InvalidParameterException;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanChannelRockerSwitchConfigBase {
public String switchMode;
return value;
}
- public static SwitchMode getSwitchMode(String value) {
+ public static SwitchMode getSwitchMode(@Nullable String value) {
if (value == null) {
return SwitchMode.Unkown;
}
this.value = value;
}
- public static Channel getChannel(String value) {
+ public static Channel getChannel(@Nullable String value) {
if (value == null) {
return Channel.Unkown;
}
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanChannelRockerSwitchListenerConfig extends EnOceanChannelRockerSwitchConfigBase {
- public String enoceanId;
- public boolean handleSecondAction;
+ public String enoceanId = "";
+ public boolean handleSecondAction = false;
public EnOceanChannelRockerSwitchListenerConfig() {
super();
- enoceanId = null;
- handleSecondAction = false;
}
}
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanChannelRollershutterConfig {
public int shutTime;
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanChannelTariffInfoConfig {
public int tariff = 0;
}
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanChannelTeachInConfig {
- public String teachInMSG;
- public String manufacturerId;
+ public String teachInMSG = "";
+ public String manufacturerId = "";
}
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Dominik Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class EnOceanChannelTotalusageConfig {
public boolean validateValue = false;
}
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.config.core.Configuration;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanChannelTransformationConfig extends Configuration {
- public String transformationType;
- public String transformationFunction;
+ public String transformationType = "";
+ public String transformationFunction = "";
public EnOceanChannelTransformationConfig() {
- put("transformationType", "");
- put("transformationFunction", "");
+ put("transformationType", transformationType);
+ put("transformationFunction", transformationFunction);
}
}
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanChannelVirtualRockerSwitchConfig extends EnOceanChannelRockerSwitchConfigBase {
public Integer duration;
*/
package org.openhab.binding.enocean.internal.config;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* This {@link EnOceanProfileRockerSwitchActionConfig} config class is used for rockerSwitchAction profiles to define in
* which case it should react.
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanProfileRockerSwitchActionConfig {
public String channelAFilter;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base.UTEResponse;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.eep.EEP;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
import org.openhab.binding.enocean.internal.messages.EventMessage;
import org.openhab.binding.enocean.internal.messages.EventMessage.EventMessageType;
-import org.openhab.binding.enocean.internal.messages.Responses.SMACKTeachInResponse;
+import org.openhab.binding.enocean.internal.messages.responses.SMACKTeachInResponse;
import org.openhab.binding.enocean.internal.transceiver.TeachInListener;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanDeviceDiscoveryService extends AbstractDiscoveryService implements TeachInListener {
private final Logger logger = LoggerFactory.getLogger(EnOceanDeviceDiscoveryService.class);
@Override
protected void startScan() {
- if (bridgeHandler == null) {
- return;
- }
-
logger.info("Starting EnOcean discovery and accepting teach in requests");
bridgeHandler.startDiscovery(this);
}
@Override
public synchronized void stopScan() {
- if (bridgeHandler == null) {
- return;
- }
-
logger.info("Stopping EnOcean discovery scan");
bridgeHandler.stopDiscovery();
super.stopScan();
// check for bidirectional communication => do not use broadcast in this case
if (msg.getRORG() == RORG.UTE && (msg.getPayload(1, 1)[0]
- & UTEResponse.CommunicationType_MASK) == UTEResponse.CommunicationType_MASK) {
+ & UTEResponse.COMMUNICATION_TYPE_MASK) == UTEResponse.COMMUNICATION_TYPE_MASK) {
broadcastMessages = false;
}
- if (msg.getRORG() == RORG.UTE && (msg.getPayload(1, 1)[0] & UTEResponse.ResponseNeeded_MASK) == 0) {
+ if (msg.getRORG() == RORG.UTE
+ && (msg.getPayload(1, 1)[0] & UTEResponse.RESPONSE_NEEDED_MASK) == 0) {
// if ute => send response if needed
logger.debug("Sending UTE response to {}", enoceanId);
senderIdOffset = sendTeachInResponse(msg, enoceanId);
}
}
- private Integer sendTeachInResponse(ERP1Message msg, String enoceanId) {
+ private @Nullable Integer sendTeachInResponse(ERP1Message msg, String enoceanId) {
// get new sender Id
Integer offset = bridgeHandler.getNextSenderId(enoceanId);
if (offset != null) {
// send response
EEP response = EEPFactory.buildResponseEEPFromTeachInERP1(msg, newSenderId, true);
if (response != null) {
- bridgeHandler.sendMessage(response.getERP1Message(), null);
- logger.debug("Teach in response for {} with new senderId {} (= offset {}) sent", enoceanId,
- HexUtils.bytesToHex(newSenderId), offset);
+ BasePacket bPacket = response.getERP1Message();
+ if (bPacket != null) {
+ bridgeHandler.sendMessage(bPacket, null);
+ logger.debug("Teach in response for {} with new senderId {} (= offset {}) sent", enoceanId,
+ HexUtils.bytesToHex(newSenderId), offset);
+ }
} else {
logger.warn("Teach in response for enoceanId {} not supported!", enoceanId);
}
// send response
EEP response = EEPFactory.buildResponseEEPFromTeachInERP1(msg, senderId, false);
if (response != null) {
- bridgeHandler.sendMessage(response.getERP1Message(), null);
- logger.debug("Teach out response for thing {} with EnOceanId {} sent", thing.getUID().getId(), enoceanId);
+ ERP1Message message = response.getERP1Message();
+ if (message != null) {
+ bridgeHandler.sendMessage(message, null);
+ logger.debug("Teach out response for thing {} with EnOceanId {} sent", thing.getUID().getId(),
+ enoceanId);
+ }
} else {
logger.warn("Teach out response for enoceanId {} not supported!", enoceanId);
}
}
- protected void createDiscoveryResult(EEP eep, boolean broadcastMessages, Integer senderIdOffset) {
+ protected void createDiscoveryResult(EEP eep, boolean broadcastMessages, @Nullable Integer senderIdOffset) {
String enoceanId = HexUtils.bytesToHex(eep.getSenderId());
ThingTypeUID thingTypeUID = eep.getThingTypeUID();
+ if (thingTypeUID == null) {
+ logger.debug("Discovery failed, could not get ThingTypeUID for EnOceanId {}", enoceanId);
+ return;
+ }
ThingUID thingUID = new ThingUID(thingTypeUID, bridgeHandler.getThing().getUID(), enoceanId);
DiscoveryResultBuilder discoveryResultBuilder = DiscoveryResultBuilder.create(thingUID)
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
*
* @author Aitor Iturrioz - initial contribution
*/
+@NonNullByDefault
@Component(service = UsbSerialDiscoveryParticipant.class)
public class EnOceanUsbSerialDiscoveryParticipant implements UsbSerialDiscoveryParticipant {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class A5_02 extends _4BSMessage {
public A5_02(ERP1Message packet) {
protected abstract double getScaledMax();
protected int getUnscaledTemperatureValue() {
- return getDB_1Value();
+ return getDB1Value();
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
double scaledTemp = getScaledMin()
- (((getUnscaledMin() - getUnscaledTemperatureValue()) * (getScaledMin() - getScaledMax()))
/ getUnscaledMin());
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_01 extends A5_02 {
public A5_02_01(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_02 extends A5_02 {
public A5_02_02(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_03 extends A5_02 {
public A5_02_03(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_04 extends A5_02 {
public A5_02_04(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_05 extends A5_02 {
public A5_02_05(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_06 extends A5_02 {
public A5_02_06(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_07 extends A5_02 {
public A5_02_07(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_08 extends A5_02 {
public A5_02_08(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_09 extends A5_02 {
public A5_02_09(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_0A extends A5_02 {
public A5_02_0A(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_0B extends A5_02 {
public A5_02_0B(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_10 extends A5_02 {
public A5_02_10(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_11 extends A5_02 {
public A5_02_11(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_12 extends A5_02 {
public A5_02_12(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_13 extends A5_02 {
public A5_02_13(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_14 extends A5_02 {
public A5_02_14(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_15 extends A5_02 {
public A5_02_15(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_16 extends A5_02 {
public A5_02_16(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_17 extends A5_02 {
public A5_02_17(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_18 extends A5_02 {
public A5_02_18(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_19 extends A5_02 {
public A5_02_19(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_1A extends A5_02 {
public A5_02_1A(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_1B extends A5_02 {
public A5_02_1B(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_20 extends A5_02 {
public A5_02_20(ERP1Message packet) {
@Override
protected int getUnscaledTemperatureValue() {
- return getDB_1Value() + ((getDB_2Value() & 0b11) << 8);
+ return getDB1Value() + ((getDB2Value() & 0b11) << 8);
}
}
*/
package org.openhab.binding.enocean.internal.eep.A5_02;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_02_30 extends A5_02 {
public A5_02_30(ERP1Message packet) {
@Override
protected int getUnscaledTemperatureValue() {
- return getDB_1Value() + ((getDB_2Value() & 0b11) << 8);
+ return getDB1Value() + ((getDB2Value() & 0b11) << 8);
}
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class A5_04 extends _4BSMessage {
public A5_04(ERP1Message packet) {
protected abstract double getScaledTemperatureMax();
protected int getUnscaledTemperatureValue() {
- return getDB_1Value();
+ return getDB1Value();
}
protected double getUnscaledHumidityMax() {
}
protected int getUnscaledHumidityValue() {
- return getDB_2Value();
+ return getDB2Value();
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (channelId.equals(CHANNEL_TEMPERATURE)) {
double scaledTemp = getScaledTemperatureMin()
+ ((getUnscaledTemperatureValue() * (getScaledTemperatureMax() - getScaledTemperatureMin()))
*/
package org.openhab.binding.enocean.internal.eep.A5_04;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_04_01 extends A5_04 {
public A5_04_01(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_04;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_04_02 extends A5_04 {
public A5_04_02(ERP1Message packet) {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.QuantityType;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_04_02_Eltako extends A5_04_02 {
public A5_04_02_Eltako(ERP1Message packet) {
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (channelId.equals(CHANNEL_BATTERY_VOLTAGE)) {
- double voltage = getDB_3Value() * 6.58 / 255.0; // not sure if this is right
+ double voltage = getDB3Value() * 6.58 / 255.0; // not sure if this is right
return new QuantityType<>(voltage, Units.VOLT);
}
*/
package org.openhab.binding.enocean.internal.eep.A5_04;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_04_03 extends A5_04 {
public A5_04_03(ERP1Message packet) {
@Override
protected int getUnscaledTemperatureValue() {
- return getDB_1Value() + ((getDB_2Value() & 0b11) << 8);
+ return getDB1Value() + ((getDB2Value() & 0b11) << 8);
}
@Override
@Override
protected int getUnscaledHumidityValue() {
- return getDB_3Value();
+ return getDB3Value();
}
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_06_01 extends _4BSMessage {
public A5_06_01(ERP1Message packet) {
}
private State getBatteryVoltage() {
- int db3 = getDB_3Value();
+ int db3 = getDB3Value();
double voltage = db3 / 50.0; // 0..255 = 0.0..5.1V
}
private State getIllumination() {
- boolean rs = getBit(getDB_0(), 0);
+ boolean rs = getBit(getDB0(), 0);
- double illumination = rs ? getDB_2Value() * 116.48 + 300.0 : getDB_1Value() * 232.94 + 600.0;
+ double illumination = rs ? getDB2Value() * 116.48 + 300.0 : getDB1Value() * 232.94 + 600.0;
return new QuantityType<>(illumination, Units.LUX);
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_BATTERY_VOLTAGE:
return getBatteryVoltage();
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_06_01_ELTAKO extends _4BSMessage {
public A5_06_01_ELTAKO(ERP1Message packet) {
}
private State getIllumination() {
- int db2 = getDB_2Value();
+ int db2 = getDB2Value();
if (db2 == 0) {
- int db3 = getDB_3Value();
+ int db3 = getDB3Value();
return new QuantityType<>(db3 * 0.5, Units.LUX);
} else {
return new QuantityType<>(db2 * 116.48 + 300.0, Units.LUX);
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_ILLUMINATION:
return getIllumination();
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class A5_07 extends _4BSMessage {
public A5_07(ERP1Message packet) {
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (channelId.equals(CHANNEL_ILLUMINATION)) {
return getIllumination();
} else if (channelId.equals(CHANNEL_MOTIONDETECTION)) {
*/
package org.openhab.binding.enocean.internal.eep.A5_07;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.types.State;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_07_01 extends A5_07 {
- private final int PIR_OFF = 0x7f;
+ private static final int PIR_OFF = 0x7f;
public A5_07_01(ERP1Message packet) {
super(packet);
@Override
protected State getMotion() {
- return getDB_1Value() <= PIR_OFF ? OnOffType.OFF : OnOffType.ON;
+ return getDB1Value() <= PIR_OFF ? OnOffType.OFF : OnOffType.ON;
}
@Override
protected State getSupplyVoltage() {
- if (!getBit(getDB_0Value(), 0)) {
+ if (!getBit(getDB0Value(), 0)) {
return UnDefType.UNDEF;
}
- return getSupplyVoltage(getDB_3Value());
+ return getSupplyVoltage(getDB3Value());
}
}
*/
package org.openhab.binding.enocean.internal.eep.A5_07;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.types.State;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_07_02 extends A5_07 {
public A5_07_02(ERP1Message packet) {
@Override
protected State getMotion() {
- return getBit(getDB_0Value(), 7) ? OnOffType.ON : OnOffType.OFF;
+ return getBit(getDB0Value(), 7) ? OnOffType.ON : OnOffType.OFF;
}
@Override
protected State getSupplyVoltage() {
- return getSupplyVoltage(getDB_3Value());
+ return getSupplyVoltage(getDB3Value());
}
}
*/
package org.openhab.binding.enocean.internal.eep.A5_07;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_07_03 extends A5_07_02 {
public A5_07_03(ERP1Message packet) {
@Override
protected State getIllumination() {
- return new QuantityType<>((getDB_2Value() << 8) + ((getDB_1Value() & 0b11000000) >>> 6), Units.LUX);
+ return new QuantityType<>((getDB2Value() << 8) + ((getDB1Value() & 0b11000000) >>> 6), Units.LUX);
}
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class A5_08 extends _4BSMessage {
public A5_08(ERP1Message packet) {
protected abstract double getScaledIlluminationMax();
protected int getUnscaledTemperatureValue() {
- return getDB_1Value();
+ return getDB1Value();
}
protected int getUnscaledIlluminationValue() {
- return getDB_2Value();
+ return getDB2Value();
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (channelId.equals(CHANNEL_TEMPERATURE)) {
double scaledTemp = getScaledTemperatureMin()
+ ((getUnscaledTemperatureValue() * (getScaledTemperatureMax() - getScaledTemperatureMin()))
/ (getUnscaledIlluminationMax() - getUnscaledIlluminationMin()));
return new QuantityType<>(scaledIllumination, Units.LUX);
} else if (channelId.equals(CHANNEL_MOTIONDETECTION)) {
- return getBit(getDB_0(), 1) ? OnOffType.OFF : OnOffType.ON;
+ return getBit(getDB0(), 1) ? OnOffType.OFF : OnOffType.ON;
} else if (channelId.equals(CHANNEL_OCCUPANCY)) {
- return getBit(getDB_0(), 0) ? OnOffType.OFF : OnOffType.ON;
+ return getBit(getDB0(), 0) ? OnOffType.OFF : OnOffType.ON;
}
return UnDefType.UNDEF;
*/
package org.openhab.binding.enocean.internal.eep.A5_08;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_08_01 extends A5_08 {
public A5_08_01(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_08;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_08_01_FXBH extends A5_08 {
public A5_08_01_FXBH(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_08;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_08_02 extends A5_08 {
public A5_08_02(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_08;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_08_03 extends A5_08 {
public A5_08_03(ERP1Message packet) {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class A5_10 extends _4BSMessage {
public A5_10(ERP1Message packet) {
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_FANSPEEDSTAGE:
- if (getDB_3Value() > 209) {
+ if (getDB3Value() > 209) {
return new StringType("-1");
- } else if (getDB_3Value() > 189) {
+ } else if (getDB3Value() > 189) {
return new StringType("0");
- } else if (getDB_3Value() > 164) {
+ } else if (getDB3Value() > 164) {
return new StringType("1");
- } else if (getDB_3Value() > 144) {
+ } else if (getDB3Value() > 144) {
return new StringType("2");
} else {
return new StringType("3");
}
case CHANNEL_SETPOINT:
- return new DecimalType(getDB_2Value());
+ return new DecimalType(getDB2Value());
case CHANNEL_TEMPERATURE:
- double temp = (getDB_1Value() - 255) / -6.375;
+ double temp = (getDB1Value() - 255) / -6.375;
return new QuantityType<>(temp, SIUnits.CELSIUS);
case CHANNEL_OCCUPANCY:
- return getBit(getDB_0(), 0) ? OnOffType.OFF : OnOffType.ON;
+ return getBit(getDB0(), 0) ? OnOffType.OFF : OnOffType.ON;
}
return UnDefType.UNDEF;
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_01 extends A5_10 {
public A5_10_01(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_02 extends A5_10 {
public A5_10_02(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_03 extends A5_10 {
public A5_10_03(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_04 extends A5_10 {
public A5_10_04(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_05 extends A5_10 {
public A5_10_05(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_06 extends A5_10 {
public A5_10_06(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_07 extends A5_10 {
public A5_10_07(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_08 extends A5_10 {
public A5_10_08(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_09 extends A5_10 {
public A5_10_09(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_0A extends A5_10 {
public A5_10_0A(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_0B extends A5_10 {
public A5_10_0B(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_0C extends A5_10 {
public A5_10_0C(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_0D extends A5_10 {
public A5_10_0D(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_10 extends A5_10 {
public A5_10_10(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_11 extends A5_10 {
public A5_10_11(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_12 extends A5_10 {
public A5_10_12(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_13 extends A5_10 {
public A5_10_13(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_14 extends A5_10 {
public A5_10_14(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_15 extends A5_10 {
public A5_10_15(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_16 extends A5_10 {
public A5_10_16(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_17 extends A5_10 {
public A5_10_17(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_18 extends A5_10 {
public A5_10_18(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_19 extends A5_10 {
public A5_10_19(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_1A extends A5_10 {
public A5_10_1A(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_1B extends A5_10 {
public A5_10_1B(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_1C extends A5_10 {
public A5_10_1C(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_1D extends A5_10 {
public A5_10_1D(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_1E extends A5_10 {
public A5_10_1E(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_1F extends A5_10 {
public A5_10_1F(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_20 extends A5_10 {
public A5_10_20(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_21 extends A5_10 {
public A5_10_21(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_22 extends A5_10 {
public A5_10_22(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_10;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_10_23 extends A5_10 {
public A5_10_23(ERP1Message packet) {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_11_03 extends _4BSMessage {
public A5_11_03(ERP1Message packet) {
}
protected boolean isErrorState() {
- byte db1 = getDB_1();
+ byte db1 = getDB1();
int state = (db1 >> 4) & 0x03;
}
protected State getPositionData() {
- byte db1 = getDB_1();
+ byte db1 = getDB1();
boolean pvf = getBit(db1, 7);
if (pvf) {
- byte db0 = getDB_0();
+ byte db0 = getDB0();
boolean motp = getBit(db0, 6);
- int bsp = getDB_3Value();
+ int bsp = getDB3Value();
if ((bsp >= 0) && (bsp <= 100)) {
return new PercentType(motp ? 100 - bsp : bsp);
}
protected State getAngleData() {
- byte db1 = getDB_1();
+ byte db1 = getDB1();
boolean avf = getBit(db1, 6);
if (avf) {
- byte db2 = getDB_2();
+ byte db2 = getDB2();
boolean as = getBit(db2, 7);
int an = (db2 & 0x7F) * 2;
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (isErrorState()) {
return UnDefType.UNDEF;
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.eep.EEPHelper;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Vincent Bakker - Initial contribution
*/
-
+@NonNullByDefault
public class A5_11_04 extends _4BSMessage {
private enum Error {
NOT_SUPPORTED
}
- private static Logger logger = LoggerFactory.getLogger(A5_11_04.class);
+ private Logger logger = LoggerFactory.getLogger(A5_11_04.class);
public A5_11_04(ERP1Message packet) {
super(packet);
}
protected boolean isErrorState() {
- byte db0 = getDB_0();
+ byte db0 = getDB0();
int state = (db0 >> 4) & 0x03;
}
protected ParameterMode getParameterMode() {
- int pm = (getDB_0() >> 1) & 0x03;
+ int pm = (getDB0() >> 1) & 0x03;
return ParameterMode.values()[pm];
}
protected EnergyUnit getEnergyUnit() {
- int unit = getDB_1();
+ int unit = getDB1();
if (unit < 8) {
return EnergyUnit.values()[unit];
}
}
protected State getLightingStatus() {
- byte db0 = getDB_0();
+ byte db0 = getDB0();
boolean lightOn = getBit(db0, 0);
return lightOn ? OnOffType.ON : OnOffType.OFF;
protected State getDimmerStatus() {
if (getParameterMode() == ParameterMode.EIGHT_BIT_DIMMER_VALUE_AND_LAMP_OPERATING_HOURS) {
- return new PercentType(getDB_3Value() * 100 / 255);
+ return new PercentType(getDB3Value() * 100 / 255);
}
return UnDefType.UNDEF;
}
}
return new QuantityType<>(
- Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB_3(), getDB_2() }), 16) * factor,
+ Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB3(), getDB2() }), 16) * factor,
Units.KILOWATT_HOUR);
}
}
return new QuantityType<>(
- Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB_3(), getDB_2() }), 16) * factor, Units.WATT);
+ Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB3(), getDB2() }), 16) * factor, Units.WATT);
}
return UnDefType.UNDEF;
protected State getOperatingHours() {
if (getParameterMode() == ParameterMode.EIGHT_BIT_DIMMER_VALUE_AND_LAMP_OPERATING_HOURS) {
- return new DecimalType(getDB_2Value() << 8 + getDB_1Value());
+ return new DecimalType(getDB2Value() << 8 + getDB1Value());
}
return UnDefType.UNDEF;
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (isErrorState()) {
return UnDefType.UNDEF;
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelTariffInfoConfig;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.eep.EEPHelper;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public abstract class A5_12 extends _4BSMessage {
public A5_12(ERP1Message packet) {
super(packet);
}
protected State getCumulativeValue() {
- byte db0 = getDB_0();
+ byte db0 = getDB0();
boolean dt = getBit(db0, 2);
if (!dt) {
return UnDefType.UNDEF;
}
- float cumulativeValue = Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB_3(), getDB_2(), getDB_1() }),
- 16) * factor;
+ float cumulativeValue = Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB3(), getDB2(), getDB1() }), 16)
+ * factor;
return calcCumulativeValue(cumulativeValue);
}
}
protected State getCurrentValue() {
- byte db0 = getDB_0();
+ byte db0 = getDB0();
boolean dt = getBit(db0, 2);
if (dt) {
return UnDefType.UNDEF;
}
- float currentValue = Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB_3(), getDB_2(), getDB_1() }), 16)
+ float currentValue = Long.parseLong(HexUtils.bytesToHex(new byte[] { getDB3(), getDB2(), getDB1() }), 16)
* factor;
return calcCurrentValue(currentValue);
}
protected int getTariffInfo() {
- return ((getDB_0() >>> 4) & 0xff);
+ return ((getDB0() >>> 4) & 0xff);
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
EnOceanChannelTariffInfoConfig c = config.as(EnOceanChannelTariffInfoConfig.class);
if (c.tariff != getTariffInfo()) {
return UnDefType.UNDEF;
*/
package org.openhab.binding.enocean.internal.eep.A5_12;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_12_00 extends A5_12 {
public A5_12_00(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_12;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_12_01 extends A5_12 {
public A5_12_01(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_12;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SIUnits;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_12_02 extends A5_12 {
public A5_12_02(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_12;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SIUnits;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_12_03 extends A5_12 {
public A5_12_03(ERP1Message packet) {
*/
package org.openhab.binding.enocean.internal.eep.A5_13;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class A5_13 extends _4BSMessage {
public A5_13(ERP1Message packet) {
super(packet);
}
- protected final int PARTONE = 0x10;
- protected final int PARTTWO = 0x20;
+ protected static final int PARTONE = 0x10;
+ protected static final int PARTTWO = 0x20;
protected int getMessageIdentifier() {
- return getDB_0Value() & 0xF0;
+ return getDB0Value() & 0xF0;
}
protected boolean isPartOne() {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.OnOffType;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_13_01 extends A5_13 {
public A5_13_01(ERP1Message packet) {
}
protected State getIllumination() {
- return new QuantityType<>(((getDB_3Value() * 1000.0) / 255.0), Units.LUX);
+ return new QuantityType<>(((getDB3Value() * 1000.0) / 255.0), Units.LUX);
}
protected State getIllumination(double value) {
}
protected State getIlluminationWest() {
- return getIllumination(getDB_3Value());
+ return getIllumination(getDB3Value());
}
protected State getIlluminationSouthNorth() {
- return getIllumination(getDB_2Value());
+ return getIllumination(getDB2Value());
}
protected State getIlluminationEast() {
- return getIllumination(getDB_1Value());
+ return getIllumination(getDB1Value());
}
protected State getTemperature() {
- return new QuantityType<>(-40.0 + ((getDB_2Value() * 120.0) / 255.0), SIUnits.CELSIUS);
+ return new QuantityType<>(-40.0 + ((getDB2Value() * 120.0) / 255.0), SIUnits.CELSIUS);
}
protected State getWindSpeed() {
- return new QuantityType<>(((getDB_1Value() * 70.0) / 255.0), Units.METRE_PER_SECOND);
+ return new QuantityType<>(((getDB1Value() * 70.0) / 255.0), Units.METRE_PER_SECOND);
}
protected State getRainStatus() {
- return getBit(getDB_0Value(), 1) ? OnOffType.ON : OnOffType.OFF;
+ return getBit(getDB0Value(), 1) ? OnOffType.ON : OnOffType.OFF;
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (isPartOne()) {
switch (channelId) {
case CHANNEL_ILLUMINATION:
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public abstract class A5_14 extends _4BSMessage {
public A5_14(ERP1Message packet) {
super(packet);
}
private State getBatteryVoltage() {
- int db3 = getDB_3Value();
+ int db3 = getDB3Value();
if (db3 > 250) {
logger.warn("EEP A5-14 error code {}", db3);
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_BATTERY_VOLTAGE:
return getBatteryVoltage();
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_14_01 extends A5_14 {
public A5_14_01(ERP1Message packet) {
}
private State getContact(boolean inverted) {
- boolean ct = getBit(getDB_0(), 0);
+ boolean ct = getBit(getDB0(), 0);
if (inverted) {
return ct ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_CONTACT:
EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_14_01_ELTAKO extends _4BSMessage {
public A5_14_01_ELTAKO(ERP1Message packet) {
}
private State getEnergyStorage() {
- int db3 = getDB_3Value();
+ int db3 = getDB3Value();
double voltage = db3 / 51.0; // 0..255 = 0.0..5.0V
}
private State getBatteryVoltage() {
- int db2 = getDB_2Value();
+ int db2 = getDB2Value();
double voltage = db2 / 51.0; // 0..255 = 0.0..5.0V
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_ENERGY_STORAGE:
return getEnergyStorage();
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_14_09 extends A5_14 {
- public final byte CLOSED = (byte) 0x00;
- public final byte TILTED = (byte) 0x01;
- public final byte OPEN = (byte) 0x03;
+ public static final byte CLOSED = (byte) 0x00;
+ public static final byte TILTED = (byte) 0x01;
+ public static final byte OPEN = (byte) 0x03;
public A5_14_09(ERP1Message packet) {
super(packet);
}
private State getWindowhandleState() {
- byte ct = (byte) ((getDB_0() & 0x06) >> 1);
+ byte ct = (byte) ((getDB0() & 0x06) >> 1);
switch (ct) {
case CLOSED:
}
private State getContact(boolean inverted) {
- byte ct = (byte) ((getDB_0() & 0x06) >> 1);
+ byte ct = (byte) ((getDB0() & 0x06) >> 1);
switch (ct) {
case CLOSED:
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_WINDOWHANDLESTATE:
return getWindowhandleState();
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.OnOffType;
*
* @author Stefan Schimanski - Initial contribution
*/
+@NonNullByDefault
public class A5_14_0A extends A5_14_09 {
public A5_14_0A(ERP1Message packet) {
super(packet);
}
private State getVibration() {
- boolean alarm = getBit(getDB_0(), 0);
+ boolean alarm = getBit(getDB0(), 0);
return alarm ? OnOffType.ON : OnOffType.OFF;
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (channelId.equals(CHANNEL_VIBRATION)) {
return getVibration();
}
*/
package org.openhab.binding.enocean.internal.eep.A5_20;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Dominik Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_20 extends _4BSMessage {
public A5_20() {
import javax.measure.quantity.Temperature;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.DecimalType;
*
* @author Dominik Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class A5_20_04 extends A5_20 {
public A5_20_04() {
}
@Override
- protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+ protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
Configuration config) {
switch (channelId) {
case CHANNEL_STATUS_REQUEST_EVENT:
}
private String getStatusRequestEvent() {
- return Boolean.valueOf(getBit(getDB_0Value(), 6)).toString();
+ return Boolean.valueOf(getBit(getDB0Value(), 6)).toString();
// return getBit(getDB_0Value(), 6) ? "triggered" : null;
}
private byte getPos(Function<String, State> getCurrentStateFunc) {
State current = getCurrentStateFunc.apply(CHANNEL_VALVE_POSITION);
- if ((current != null) && (current instanceof DecimalType)) {
+ if (current instanceof DecimalType) {
DecimalType state = current.as(DecimalType.class);
if (state != null) {
double value = 20.0; // 20 °C
- if ((current != null) && (current instanceof QuantityType)) {
+ if (current instanceof QuantityType) {
@SuppressWarnings("unchecked")
QuantityType<Temperature> raw = current.as(QuantityType.class);
private byte getMc(Function<String, State> getCurrentStateFunc) {
State current = getCurrentStateFunc.apply(CHANNEL_MEASUREMENT_CONTROL);
- if ((current != null) && (current instanceof OnOffType)) {
+ if (current instanceof OnOffType) {
OnOffType state = current.as(OnOffType.class);
if (state != null) {
private byte getWuc(Function<String, State> getCurrentStateFunc) {
State current = getCurrentStateFunc.apply(CHANNEL_WAKEUPCYCLE);
- if ((current != null) && (current instanceof DecimalType)) {
+ if (current instanceof DecimalType) {
DecimalType state = current.as(DecimalType.class);
if (state != null) {
private byte getDso(Function<String, State> getCurrentStateFunc) {
State current = getCurrentStateFunc.apply(CHANNEL_DISPLAY_ORIENTATION);
- if ((current != null) && (current instanceof DecimalType)) {
+ if (current instanceof DecimalType) {
DecimalType state = current.as(DecimalType.class);
if (state != null) {
private byte getBlc(Function<String, State> getCurrentStateFunc) {
State current = getCurrentStateFunc.apply(CHANNEL_BUTTON_LOCK);
- if ((current != null) && (current instanceof OnOffType)) {
+ if (current instanceof OnOffType) {
OnOffType state = current.as(OnOffType.class);
if (state != null) {
private byte getSer(Function<String, State> getCurrentStateFunc) {
State current = getCurrentStateFunc.apply(CHANNEL_SERVICECOMMAND);
- if ((current != null) && (current instanceof DecimalType)) {
+ if (current instanceof DecimalType) {
DecimalType state = current.as(DecimalType.class);
if (state != null) {
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (VIRTUALCHANNEL_SEND_COMMAND.equals(channelId)) {
byte db3 = getPos(getCurrentStateFunc);
byte db2 = getTsp(getCurrentStateFunc);
byte db1 = (byte) (0x00 | getMc(getCurrentStateFunc) | getWuc(getCurrentStateFunc));
- byte db0 = (byte) (0x00 | getDso(getCurrentStateFunc) | TeachInBit | getBlc(getCurrentStateFunc)
+ byte db0 = (byte) (0x00 | getDso(getCurrentStateFunc) | TEACHIN_BIT | getBlc(getCurrentStateFunc)
| getSer(getCurrentStateFunc));
setData(db3, db2, db1, db0);
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_VALVE_POSITION:
return getValvePosition();
}
private State getTemperature() {
- boolean fl = getBit(getDB_0Value(), 0);
- boolean mst = getBit(getDB_0Value(), 7);
+ boolean fl = getBit(getDB0Value(), 0);
+ boolean mst = getBit(getDB0Value(), 7);
if (fl || mst) {
return UnDefType.UNDEF;
}
- double value = getDB_1Value() * (20.0 / 255.0) + 10.0;
+ double value = getDB1Value() * (20.0 / 255.0) + 10.0;
return new QuantityType<>(value, SIUnits.CELSIUS);
}
private State getFailureCode() {
- boolean fl = getBit(getDB_0Value(), 0);
+ boolean fl = getBit(getDB0Value(), 0);
if (!fl) {
return new QuantityType<>(-1, Units.ONE);
}
- return new QuantityType<>(getDB_1Value(), Units.ONE);
+ return new QuantityType<>(getDB1Value(), Units.ONE);
}
private State getMeasurementControl() {
- return getBit(getDB_0Value(), 7) ? OnOffType.OFF : OnOffType.ON;
+ return getBit(getDB0Value(), 7) ? OnOffType.OFF : OnOffType.ON;
}
private State getFeedTemperature() {
- boolean ts = getBit(getDB_0Value(), 1);
- boolean mst = getBit(getDB_0Value(), 7);
+ boolean ts = getBit(getDB0Value(), 1);
+ boolean mst = getBit(getDB0Value(), 7);
if (ts || mst) {
return UnDefType.UNDEF;
}
- double value = getDB_2Value() * (60.0 / 255.0) + 20.0;
+ double value = getDB2Value() * (60.0 / 255.0) + 20.0;
return new QuantityType<>(value, SIUnits.CELSIUS);
}
private State getTemperatureSetpoint() {
- boolean ts = getBit(getDB_0Value(), 1);
+ boolean ts = getBit(getDB0Value(), 1);
if (!ts) {
return UnDefType.UNDEF;
}
- double value = getDB_2Value() * (20.0 / 255.0) + 10.0;
+ double value = getDB2Value() * (20.0 / 255.0) + 10.0;
return new QuantityType<>(value, SIUnits.CELSIUS);
}
private State getButtonLock() {
- return getBit(getDB_0Value(), 2) ? OnOffType.ON : OnOffType.OFF;
+ return getBit(getDB0Value(), 2) ? OnOffType.ON : OnOffType.OFF;
}
private State getValvePosition() {
- return new QuantityType<>(getDB_3Value(), Units.PERCENT);
+ return new QuantityType<>(getDB3Value(), Units.PERCENT);
}
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_30_03 extends _4BSMessage {
protected static final byte ALL_DIGITALPINS_HIGH = 0x0F;
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_TEMPERATURE:
- double temp = (getDB_2Value() - 255) / -6.375;
+ double temp = (getDB2Value() - 255) / -6.375;
return new QuantityType<>(temp, SIUnits.CELSIUS);
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.OnOffType;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_30_03_ELTAKO extends A5_30_03 {
protected static final byte ALARM_ON = 0x0F;
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
- byte db1 = getDB_1();
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
+ byte db1 = getDB1();
switch (channelId) {
case CHANNEL_SMOKEDETECTION:
return db1 == ALARM_ON ? OnOffType.ON : (db1 == ALARM_OFF ? OnOffType.OFF : UnDefType.UNDEF);
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_38_08_Blinds extends _4BSMessage {
static final byte COMMAND_ID = 0x07;
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command outputCommand,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
switch (channelId) {
case CHANNEL_ROLLERSHUTTER:
- byte db0 = ZERO | SEND_NEW_STATE | TeachInBit;
+ byte db0 = ZERO | SEND_NEW_STATE | TEACHIN_BIT;
byte db1 = ZERO;
byte db2 = ZERO;
}
protected State getPositionData() {
- byte db0 = getDB_0();
+ byte db0 = getDB0();
boolean paf = getBit(db0, 1);
if (paf) {
- int bsp = getDB_2Value();
+ int bsp = getDB2Value();
if ((bsp >= 0) && (bsp <= 100)) {
return new PercentType(bsp);
}
protected State getAngleData() {
- byte db0 = getDB_0();
+ byte db0 = getDB0();
boolean paf = getBit(db0, 1);
if (paf) {
- byte db1 = getDB_1();
+ byte db1 = getDB1();
boolean as = getBit(db1, 7);
int an = (db1 & 0x7F) * 2;
}
@Override
- public State convertToStateImpl(String channelId, String channelTypeId, Function<String, State> getCurrentStateFunc,
- Configuration config) {
+ public State convertToStateImpl(String channelId, String channelTypeId,
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_ROLLERSHUTTER:
return getPositionData();
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelDimmerConfig;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_38_08_Dimming extends _4BSMessage {
- static final byte CommandId = 0x02;
- static final byte SwitchOff = 0x00;
- static final byte SwitchOn = 0x01;
- static final byte Switch100Percent = 0x64;
+ static final byte COMMAND_ID = 0x02;
+ static final byte SWITCH_OFF = 0x00;
+ static final byte SWITCH_ON = 0x01;
+ static final byte SWITCH_100_PERCENT = 0x64;
public A5_38_08_Dimming() {
super();
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command outputCommand,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
switch (channelId) {
case CHANNEL_DIMMER:
byte dimmValue;
if (outputCommand instanceof DecimalType) {
dimmValue = ((DecimalType) outputCommand).byteValue();
} else if (outputCommand instanceof OnOffType) {
- dimmValue = ((OnOffType) outputCommand == OnOffType.ON) ? Switch100Percent : ZERO;
+ dimmValue = ((OnOffType) outputCommand == OnOffType.ON) ? SWITCH_100_PERCENT : ZERO;
} else if (outputCommand instanceof IncreaseDecreaseType) {
dimmValue = ((IncreaseDecreaseType) outputCommand == IncreaseDecreaseType.INCREASE)
- ? Switch100Percent
+ ? SWITCH_100_PERCENT
: ZERO;
} else if (outputCommand instanceof UpDownType) {
- dimmValue = ((UpDownType) outputCommand == UpDownType.UP) ? Switch100Percent : ZERO;
+ dimmValue = ((UpDownType) outputCommand == UpDownType.UP) ? SWITCH_100_PERCENT : ZERO;
} else {
throw new IllegalArgumentException(outputCommand.toFullString() + " is no valid dimming command.");
}
+ if (config != null) {
+ EnOceanChannelDimmerConfig c = config.as(EnOceanChannelDimmerConfig.class);
- EnOceanChannelDimmerConfig c = config.as(EnOceanChannelDimmerConfig.class);
-
- byte storeByte = ZERO; // "Store final value" (standard) vs. "block value" (Eltako)
+ byte storeByte = ZERO; // "Store final value" (standard) vs. "block value" (Eltako)
- if (!c.eltakoDimmer) {
- dimmValue *= 2.55; // 0-100% = 0-255
+ if (!c.eltakoDimmer) {
+ dimmValue *= 2.55; // 0-100% = 0-255
- if (c.storeValue) {
- storeByte = 0x02; // set DB0.1
- }
- } else {
- if (c.storeValue) {
- storeByte = 0x04; // set DB0.2
+ if (c.storeValue) {
+ storeByte = 0x02; // set DB0.1
+ }
+ } else {
+ if (c.storeValue) {
+ storeByte = 0x04; // set DB0.2
+ }
}
- }
- byte rampingTime = Integer.valueOf(c.rampingTime).byteValue();
- byte switchingCommand = (dimmValue == ZERO) ? SwitchOff : SwitchOn;
+ byte rampingTime = Integer.valueOf(c.rampingTime).byteValue();
+ byte switchingCommand = (dimmValue == ZERO) ? SWITCH_OFF : SWITCH_ON;
- setData(CommandId, dimmValue, rampingTime, (byte) (TeachInBit | storeByte | switchingCommand));
+ setData(COMMAND_ID, dimmValue, rampingTime, (byte) (TEACHIN_BIT | storeByte | switchingCommand));
+ } else {
+ logger.error("Cannot handle command {}, when configuration is null", outputCommand.toFullString());
+ }
break;
}
}
@Override
- public State convertToStateImpl(String channelId, String channelTypeId, Function<String, State> getCurrentStateFunc,
- Configuration config) {
+ public State convertToStateImpl(String channelId, String channelTypeId,
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_DIMMER:
- if (!getBit(getDB_0(), 0)) {
+ if (!getBit(getDB0(), 0)) {
// Switching Command is OFF (DB0.0==0), return 0%
return new PercentType(0);
} else {
// DB2 contains the Dimming value (absolute[0...255] or relative/Eltako [0...100])
- int dimmValue = getDB_2Value();
+ int dimmValue = getDB2Value();
EnOceanChannelDimmerConfig c = config.as(EnOceanChannelDimmerConfig.class);
// if Standard dimmer and Dimming Range is absolute (DB0.2==0),
- if (!c.eltakoDimmer && !getBit(getDB_0(), 2)) {
+ if (!c.eltakoDimmer && !getBit(getDB0(), 2)) {
// map range [0...255] to [0%...100%]
dimmValue /= 2.55;
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_38_08_Switching extends _4BSMessage {
- static final byte CommandId = 0x01;
- static final byte SwitchOff = 0x00;
- static final byte SwitchOn = 0x01;
+ static final byte COMMAND_ID = 0x01;
+ static final byte SWITCH_OFF = 0x00;
+ static final byte SWITCH_ON = 0x01;
public A5_38_08_Switching() {
super();
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command outputCommand,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if ((OnOffType) outputCommand == OnOffType.ON) {
- setData(CommandId, ZERO, ZERO, (byte) (TeachInBit | SwitchOn));
+ setData(COMMAND_ID, ZERO, ZERO, (byte) (TEACHIN_BIT | SWITCH_ON));
} else {
- setData(CommandId, ZERO, ZERO, (byte) (TeachInBit | SwitchOff));
+ setData(COMMAND_ID, ZERO, ZERO, (byte) (TEACHIN_BIT | SWITCH_OFF));
}
}
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
/**
*
- * @author Andreas Hofinger
+ * @author Andreas Hofinger - Initial contribution
*/
+@NonNullByDefault
public class A5_3F_7F_EltakoFRM extends _4BSMessage {
- static final byte Stop = 0x00;
- static final byte Move = 0x03;
+ static final byte STOP = 0x00;
+ static final byte MOVE = 0x03;
- static final int Top = 0xC8;
- static final int Bottom = 0x00;
+ static final int TOP = 0xC8;
+ static final int BOTTOM = 0x00;
public A5_3F_7F_EltakoFRM() {
super();
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (command instanceof PercentType) {
PercentType target = (PercentType) command;
int rawPosition = Math.round(
- (PercentType.HUNDRED.floatValue() - target.floatValue()) * Top / PercentType.HUNDRED.floatValue());
- int position = Math.min(Top, Math.max(Bottom, rawPosition));
- setData((byte) position, ZERO, Move, TeachInBit);
+ (PercentType.HUNDRED.floatValue() - target.floatValue()) * TOP / PercentType.HUNDRED.floatValue());
+ int position = Math.min(TOP, Math.max(BOTTOM, rawPosition));
+ setData((byte) position, ZERO, MOVE, TEACHIN_BIT);
} else if (command instanceof UpDownType) {
if ((UpDownType) command == UpDownType.UP) {
- setData((byte) Top, ZERO, Move, TeachInBit); // => 0 percent
+ setData((byte) TOP, ZERO, MOVE, TEACHIN_BIT); // => 0 percent
} else if ((UpDownType) command == UpDownType.DOWN) {
- setData((byte) Bottom, ZERO, Move, TeachInBit); // => 100 percent
+ setData((byte) BOTTOM, ZERO, MOVE, TEACHIN_BIT); // => 100 percent
}
} else if (command instanceof StopMoveType) {
if ((StopMoveType) command == StopMoveType.STOP) {
- setData(ZERO, ZERO, Stop, TeachInBit);
+ setData(ZERO, ZERO, STOP, TEACHIN_BIT);
}
}
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
// 0x0A.. Move was locked for switch
// 0x0E.. Move was not locked
- if (getDB_2() == ZERO && getDB_1() == Move && (getDB_0() == 0x0A || getDB_0() == 0x0E)) {
- int position = getDB_3Value();
- float percentage = 100.0f * (Top - position) / (float) (Top - Bottom);
+ if (getDB2() == ZERO && getDB1() == MOVE && (getDB0() == 0x0A || getDB0() == 0x0E)) {
+ int position = getDB3Value();
+ float percentage = 100.0f * (TOP - position) / (float) (TOP - BOTTOM);
return new PercentType(Math.round(Math.min(100, (Math.max(0, percentage)))));
}
return UnDefType.UNDEF;
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelRollershutterConfig;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_3F_7F_EltakoFSB extends _4BSMessage {
- static final byte Stop = 0x00;
- static final byte MoveUp = 0x01;
- static final byte MoveDown = 0x02;
+ static final byte STOP = 0x00;
+ static final byte MOVE_UP = 0x01;
+ static final byte MOVE_DOWN = 0x02;
- static final byte Up = 0x70;
- static final byte Down = 0x50;
+ static final byte UP = 0x70;
+ static final byte DOWN = 0x50;
public A5_3F_7F_EltakoFSB() {
super();
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
int shutTime = 0xFF;
- if (config != null) {
+ if (config == null) {
+ logger.debug("No configuration, shutTime fallback to {}", shutTime);
+ } else {
shutTime = Math.min(255, config.as(EnOceanChannelRollershutterConfig.class).shutTime);
}
PercentType target = (PercentType) command;
if (target.intValue() == PercentType.ZERO.intValue()) {
- setData(ZERO, (byte) shutTime, MoveUp, TeachInBit); // => move completely up
+ setData(ZERO, (byte) shutTime, MOVE_UP, TEACHIN_BIT); // => move completely up
} else if (target.intValue() == PercentType.HUNDRED.intValue()) {
- setData(ZERO, (byte) shutTime, MoveDown, TeachInBit); // => move completely down
+ setData(ZERO, (byte) shutTime, MOVE_DOWN, TEACHIN_BIT); // => move completely down
} else if (channelState != null) {
PercentType current = channelState.as(PercentType.class);
- if (config != null && current != null) {
+ if (current != null) {
if (current.intValue() != target.intValue()) {
- byte direction = current.intValue() > target.intValue() ? MoveUp : MoveDown;
+ byte direction = current.intValue() > target.intValue() ? MOVE_UP : MOVE_DOWN;
byte duration = (byte) Math.min(255,
(Math.abs(current.intValue() - target.intValue()) * shutTime)
/ PercentType.HUNDRED.intValue());
- setData(ZERO, duration, direction, TeachInBit);
+ setData(ZERO, duration, direction, TEACHIN_BIT);
}
}
}
} else if (command instanceof UpDownType) {
if ((UpDownType) command == UpDownType.UP) {
- setData(ZERO, (byte) shutTime, MoveUp, TeachInBit); // => 0 percent
+ setData(ZERO, (byte) shutTime, MOVE_UP, TEACHIN_BIT); // => 0 percent
} else if ((UpDownType) command == UpDownType.DOWN) {
- setData(ZERO, (byte) shutTime, MoveDown, TeachInBit); // => 100 percent
+ setData(ZERO, (byte) shutTime, MOVE_DOWN, TEACHIN_BIT); // => 100 percent
}
} else if (command instanceof StopMoveType) {
if ((StopMoveType) command == StopMoveType.STOP) {
- setData(ZERO, (byte) 0xFF, Stop, TeachInBit);
+ setData(ZERO, (byte) 0xFF, STOP, TEACHIN_BIT);
}
}
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
State currentState = getCurrentStateFunc.apply(channelId);
if (currentState != null) {
- int duration = ((getDB_3Value() << 8) + getDB_2Value()) / 10; // => Time in DB3 and DB2 is given
- // in ms
-
- if (config != null) {
- EnOceanChannelRollershutterConfig c = config.as(EnOceanChannelRollershutterConfig.class);
- if (duration == c.shutTime) {
- return getDB_1() == MoveUp ? PercentType.ZERO : PercentType.HUNDRED;
- } else {
- PercentType current = PercentType.ZERO;
- if (currentState instanceof PercentType) {
- current = currentState.as(PercentType.class);
- }
+ int duration = ((getDB3Value() << 8) + getDB2Value()) / 10; // => Time in DB3 and DB2 is given
+ // in ms
+ EnOceanChannelRollershutterConfig c = config.as(EnOceanChannelRollershutterConfig.class);
+ if (duration == c.shutTime) {
+ return getDB1() == MOVE_UP ? PercentType.ZERO : PercentType.HUNDRED;
+ } else {
+ PercentType current = PercentType.ZERO;
+ if (currentState instanceof PercentType) {
+ current = currentState.as(PercentType.class);
+ }
- int direction = getDB_1() == MoveUp ? -1 : 1;
- if (c.shutTime != -1 && c.shutTime != 0) {
- return new PercentType(Math.min(100, (Math.max(0, current.intValue()
- + direction * ((duration * PercentType.HUNDRED.intValue()) / c.shutTime)))));
- }
+ int direction = getDB1() == MOVE_UP ? -1 : 1;
+ if (current != null && c.shutTime != -1 && c.shutTime != 0) {
+ return new PercentType(Math.min(100, (Math.max(0, current.intValue()
+ + direction * ((duration * PercentType.HUNDRED.intValue()) / c.shutTime)))));
}
}
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelTransformationConfig;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class A5_3F_7F_Universal extends _4BSMessage {
// This class is currently not used => instead use Generic4BS
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
- if (config != null) {
- try {
- EnOceanChannelTransformationConfig transformationInfo = config
- .as(EnOceanChannelTransformationConfig.class);
- String c = Transformation.transform(transformationInfo.transformationType,
- transformationInfo.transformationFunction, command.toString());
-
- if (c != null && !c.equals(command.toString())) {
- setData(HexUtils.hexToBytes(c));
- }
-
- } catch (Exception e) {
- logger.debug("Command {} could not transformed", command.toString());
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
+ if (config == null) {
+ logger.error("Command {} could not transformed without proper configuration", command.toString());
+ return;
+ }
+ try {
+ EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class);
+ String c = Transformation.transform(transformationInfo.transformationType,
+ transformationInfo.transformationFunction, command.toString());
+
+ if (c != null && !c.equals(command.toString())) {
+ setData(HexUtils.hexToBytes(c));
}
+ } catch (IllegalArgumentException e) {
+ logger.debug("Command {} could not transformed", command.toString());
+ throw e;
}
}
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class PTM200Message extends _RPSMessage {
- static final byte On = 0x70;
- static final byte Off = 0x50;
- static final byte Up = 0x70;
- static final byte Down = 0x50;
- static final byte Open = (byte) 0xE0;
- static final byte Closed = (byte) 0xF0;
+ static final byte SWITCH_ON = 0x70;
+ static final byte SWITCH_OFF = 0x50;
+ static final byte UP = 0x70;
+ static final byte DOWN = 0x50;
+ static final byte OPEN = (byte) 0xE0;
+ static final byte CLOSED = (byte) 0xF0;
public PTM200Message() {
super();
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_GENERAL_SWITCHING:
- return bytes[0] == On ? OnOffType.ON : OnOffType.OFF;
+ return bytes[0] == SWITCH_ON ? OnOffType.ON : OnOffType.OFF;
case CHANNEL_ROLLERSHUTTER:
- return bytes[0] == Up ? PercentType.ZERO : (bytes[0] == Down ? PercentType.HUNDRED : UnDefType.UNDEF);
+ return bytes[0] == UP ? PercentType.ZERO : (bytes[0] == DOWN ? PercentType.HUNDRED : UnDefType.UNDEF);
case CHANNEL_CONTACT:
EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
if (c.inverted) {
- return bytes[0] == Open ? OpenClosedType.CLOSED
- : (bytes[0] == Closed ? OpenClosedType.OPEN : UnDefType.UNDEF);
+ return bytes[0] == OPEN ? OpenClosedType.CLOSED
+ : (bytes[0] == CLOSED ? OpenClosedType.OPEN : UnDefType.UNDEF);
} else {
- return bytes[0] == Open ? OpenClosedType.OPEN
- : (bytes[0] == Closed ? OpenClosedType.CLOSED : UnDefType.UNDEF);
+ return bytes[0] == OPEN ? OpenClosedType.OPEN
+ : (bytes[0] == CLOSED ? OpenClosedType.CLOSED : UnDefType.UNDEF);
}
}
import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class UTEResponse extends _VLDMessage {
- public static final byte TeachIn_MASK = 0x3f;
- public static final byte CommunicationType_MASK = (byte) 0x80;
- public static final byte ResponseNeeded_MASK = 0x40;
- public static final byte TeachIn_NotSpecified = 0x20;
+ public static final byte TEACHIN_MASK = 0x3f;
+ public static final byte COMMUNICATION_TYPE_MASK = (byte) 0x80;
+ public static final byte RESPONSE_NEEDED_MASK = 0x40;
+ public static final byte TEACHIN_NPTSPECIFIED = 0x20;
public UTEResponse(ERP1Message packet, boolean teachIn) {
int dataLength = packet.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH;
*/
package org.openhab.binding.enocean.internal.eep.Base;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.eep.EEP;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class _1BSMessage extends EEP {
- public static final int TeachInBit = 0x08;
+ public static final int TEACHIN_BIT = 0x08;
public _1BSMessage(ERP1Message packet) {
super(packet);
*/
package org.openhab.binding.enocean.internal.eep.Base;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelTeachInConfig;
import org.openhab.binding.enocean.internal.eep.EEP;
import org.openhab.binding.enocean.internal.eep.EEPType;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class _4BSMessage extends EEP {
protected boolean supportsTeachInVariation3 = false;
super();
}
- public static final byte TeachInBit = 0x08;
- public static final byte LRN_Type_Mask = (byte) 0x80;
+ public static final byte TEACHIN_BIT = 0x08;
+ public static final byte LRN_TYPE_MASK = (byte) 0x80;
- public byte getDB_0() {
+ public byte getDB0() {
return bytes[3];
}
- public int getDB_0Value() {
- return (getDB_0() & 0xFF);
+ public int getDB0Value() {
+ return (getDB0() & 0xFF);
}
- public byte getDB_1() {
+ public byte getDB1() {
return bytes[2];
}
- public int getDB_1Value() {
- return (getDB_1() & 0xFF);
+ public int getDB1Value() {
+ return (getDB1() & 0xFF);
}
- public byte getDB_2() {
+ public byte getDB2() {
return bytes[1];
}
- public int getDB_2Value() {
- return (getDB_2() & 0xFF);
+ public int getDB2Value() {
+ return (getDB2() & 0xFF);
}
- public byte getDB_3() {
+ public byte getDB3() {
return bytes[0];
}
- public int getDB_3Value() {
- return (getDB_3() & 0xFF);
+ public int getDB3Value() {
+ return (getDB3() & 0xFF);
}
@Override
- protected void teachInQueryImpl(Configuration config) {
+ protected void teachInQueryImpl(@Nullable Configuration config) {
if (config == null) {
return;
}
EnOceanChannelTeachInConfig c = config.as(EnOceanChannelTeachInConfig.class);
- if (c.teachInMSG == null || c.teachInMSG.isEmpty()) {
+ if (c.teachInMSG.isEmpty()) {
EEPType type = getEEPType();
byte db3 = (byte) ((getEEPType().getFunc() << 2) | ((type.getType()) >>> 5));
} catch (Exception e) {
}
- setData(db3, db2, db1, LRN_Type_Mask);
+ setData(db3, db2, db1, LRN_TYPE_MASK);
} else {
try {
byte[] msg = HexUtils.hexToBytes(c.teachInMSG);
setData(msg);
- } catch (Exception e) {
+ } catch (IllegalArgumentException e) {
+ logger.debug("Command TeachIn could not transformed");
+ throw e;
}
}
}
import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
*
* @author Dominik Vorreiter - Initial contribution
*/
+@NonNullByDefault
public class _4BSTeachInVariation3Response extends _4BSMessage {
public _4BSTeachInVariation3Response(ERP1Message packet, boolean teachIn) {
*/
package org.openhab.binding.enocean.internal.eep.Base;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.eep.EEP;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class _RPSMessage extends EEP {
protected boolean t21;
protected boolean nu;
- public static final byte T21Flag = 0x20;
- public static final byte NUFlag = 0x10;
+ public static final byte T21_FLAG = 0x20;
+ public static final byte NU_FLAG = 0x10;
public _RPSMessage() {
super();
@Override
public EEP setStatus(byte status) {
super.setStatus(status);
- t21 = (status & T21Flag) != 0;
- nu = (status & NUFlag) != 0;
+ t21 = (status & T21_FLAG) != 0;
+ nu = (status & NU_FLAG) != 0;
return this;
}
import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.eep.EEP;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class _SIGMessage extends EEP {
public static final byte MID_ENERGY_STATUS = 0x06;
@Override
protected int getDataLength() {
- if (packet != null) {
- return packet.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH;
+ ERP1Message localPacket = packet;
+ if (localPacket != null) {
+ return localPacket.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH;
} else {
return bytes.length;
}
import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.eep.EEP;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class _VLDMessage extends EEP {
public _VLDMessage() {
@Override
protected int getDataLength() {
- if (packet != null) {
- return packet.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH;
- } else {
- return bytes.length;
+ ERP1Message localPacket = packet;
+ if (localPacket != null) {
+ return localPacket.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH;
}
+ return bytes.length;
}
@Override
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._SIGMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D0_06 extends _SIGMessage {
public D0_06() {
}
@Override
- public State convertToStateImpl(String channelId, String channelTypeId, Function<String, State> getCurrentStateFunc,
- Configuration config) {
+ public State convertToStateImpl(String channelId, String channelTypeId,
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (CHANNEL_BATTERY_LEVEL.equals(channelId)) {
return new QuantityType<>(bytes[1] & 0xFF, Units.PERCENT);
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelDimmerConfig;
import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
import org.openhab.binding.enocean.internal.eep.EEPHelper;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class D2_01 extends _VLDMessage {
- protected final byte cmdMask = 0x0f;
- protected final byte outputValueMask = 0x7f;
- protected final byte outputChannelMask = 0x1f;
+ protected static final byte CMD_MASK = 0x0f;
+ protected static final byte OUTPUT_VALUE_MASK = 0x7f;
+ protected static final byte OUTPUT_CHANNEL_MASK = 0x1f;
- protected final byte CMD_ACTUATOR_SET_STATUS = 0x01;
- protected final byte CMD_ACTUATOR_STATUS_QUERY = 0x03;
- protected final byte CMD_ACTUATOR_STATUS_RESPONE = 0x04;
- protected final byte CMD_ACTUATOR_MEASUREMENT_QUERY = 0x06;
- protected final byte CMD_ACTUATOR_MEASUREMENT_RESPONE = 0x07;
+ protected static final byte CMD_ACTUATOR_SET_STATUS = 0x01;
+ protected static final byte CMD_ACTUATOR_STATUS_QUERY = 0x03;
+ protected static final byte CMD_ACTUATOR_STATUS_RESPONE = 0x04;
+ protected static final byte CMD_ACTUATOR_MEASUREMENT_QUERY = 0x06;
+ protected static final byte CMD_ACTUATOR_MEASUREMENT_RESPONE = 0x07;
- protected final byte AllChannels_Mask = 0x1e;
- protected final byte ChannelA_Mask = 0x00;
- protected final byte ChannelB_Mask = 0x01;
+ protected static final byte ALL_CHANNELS_MASK = 0x1e;
+ protected static final byte CHANNEL_A_MASK = 0x00;
+ protected static final byte CHANNEL_B_MASK = 0x01;
- protected final byte STATUS_SWITCHING_ON = 0x01;
- protected final byte STATUS_SWITCHING_OFF = 0x00;
- protected final byte STATUS_DIMMING_100 = 0x64;
+ protected static final byte STATUS_SWITCHING_ON = 0x01;
+ protected static final byte STATUS_SWITCHING_OFF = 0x00;
+ protected static final byte STATUS_DIMMING_100 = 0x64;
public D2_01() {
super();
}
protected byte getCMD() {
- return (byte) (bytes[0] & cmdMask);
+ return (byte) (bytes[0] & CMD_MASK);
}
protected void setSwitchingData(OnOffType command, byte outputChannel) {
protected State getSwitchingData() {
if (getCMD() == CMD_ACTUATOR_STATUS_RESPONE) {
- return (bytes[bytes.length - 1] & outputValueMask) == STATUS_SWITCHING_OFF ? OnOffType.OFF : OnOffType.ON;
+ return (bytes[bytes.length - 1] & OUTPUT_VALUE_MASK) == STATUS_SWITCHING_OFF ? OnOffType.OFF : OnOffType.ON;
}
return UnDefType.UNDEF;
}
protected byte getChannel() {
- return (byte) (bytes[1] & outputChannelMask);
+ return (byte) (bytes[1] & OUTPUT_CHANNEL_MASK);
}
protected State getSwitchingData(byte channel) {
- if (getCMD() == CMD_ACTUATOR_STATUS_RESPONE && (getChannel() == channel || getChannel() == AllChannels_Mask)) {
- return (bytes[bytes.length - 1] & outputValueMask) == STATUS_SWITCHING_OFF ? OnOffType.OFF : OnOffType.ON;
+ if (getCMD() == CMD_ACTUATOR_STATUS_RESPONE && (getChannel() == channel || getChannel() == ALL_CHANNELS_MASK)) {
+ return (bytes[bytes.length - 1] & OUTPUT_VALUE_MASK) == STATUS_SWITCHING_OFF ? OnOffType.OFF : OnOffType.ON;
}
return UnDefType.UNDEF;
protected State getDimmingData() {
if (getCMD() == CMD_ACTUATOR_STATUS_RESPONE) {
- return new PercentType((bytes[bytes.length - 1] & outputValueMask));
+ return new PercentType((bytes[bytes.length - 1] & OUTPUT_VALUE_MASK));
}
return UnDefType.UNDEF;
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (channelId.equals(CHANNEL_GENERAL_SWITCHING)) {
if (command == RefreshType.REFRESH) {
- setSwitchingQueryData(AllChannels_Mask);
+ setSwitchingQueryData(ALL_CHANNELS_MASK);
} else {
- setSwitchingData((OnOffType) command, AllChannels_Mask);
+ setSwitchingData((OnOffType) command, ALL_CHANNELS_MASK);
}
} else if (channelId.equals(CHANNEL_GENERAL_SWITCHINGA)) {
if (command == RefreshType.REFRESH) {
- setSwitchingQueryData(ChannelA_Mask);
+ setSwitchingQueryData(CHANNEL_A_MASK);
} else {
- setSwitchingData((OnOffType) command, ChannelA_Mask);
+ setSwitchingData((OnOffType) command, CHANNEL_A_MASK);
}
} else if (channelId.equals(CHANNEL_GENERAL_SWITCHINGB)) {
if (command == RefreshType.REFRESH) {
- setSwitchingQueryData(ChannelB_Mask);
+ setSwitchingQueryData(CHANNEL_B_MASK);
} else {
- setSwitchingData((OnOffType) command, ChannelB_Mask);
+ setSwitchingData((OnOffType) command, CHANNEL_B_MASK);
}
} else if (channelId.equals(CHANNEL_DIMMER)) {
if (command == RefreshType.REFRESH) {
- setSwitchingQueryData(AllChannels_Mask);
+ setSwitchingQueryData(ALL_CHANNELS_MASK);
} else {
- setDimmingData(command, AllChannels_Mask, config);
+ if (config != null) {
+ setDimmingData(command, ALL_CHANNELS_MASK, config);
+ } else {
+ logger.error("Cannot set dimming data when config is null");
+ }
}
} else if (channelId.equals(CHANNEL_INSTANTPOWER) && command == RefreshType.REFRESH) {
- setPowerMeasurementQueryData(AllChannels_Mask);
+ setPowerMeasurementQueryData(ALL_CHANNELS_MASK);
} else if (channelId.equals(CHANNEL_TOTALUSAGE) && command == RefreshType.REFRESH) {
- setEnergyMeasurementQueryData(AllChannels_Mask);
+ setEnergyMeasurementQueryData(ALL_CHANNELS_MASK);
}
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_GENERAL_SWITCHING:
return getSwitchingData();
case CHANNEL_GENERAL_SWITCHINGA:
- return getSwitchingData(ChannelA_Mask);
+ return getSwitchingData(CHANNEL_A_MASK);
case CHANNEL_GENERAL_SWITCHINGB:
- return getSwitchingData(ChannelB_Mask);
+ return getSwitchingData(CHANNEL_B_MASK);
case CHANNEL_DIMMER:
return getDimmingData();
case CHANNEL_INSTANTPOWER:
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_00 extends D2_01 {
public D2_01_00() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_01 extends D2_01 {
public D2_01_01() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_02 extends D2_01 {
public D2_01_02() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_03 extends D2_01 {
public D2_01_03() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_04 extends D2_01 {
public D2_01_04() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_05 extends D2_01 {
public D2_01_05() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_06 extends D2_01 {
public D2_01_06() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_07 extends D2_01 {
public D2_01_07() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_08 extends D2_01 {
public D2_01_08() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_09 extends D2_01 {
public D2_01_09() {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanBindingConstants;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_09_Permundo extends D2_01 {
public D2_01_09_Permundo() {
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (channelId.equals(CHANNEL_REPEATERMODE)) {
setRepeaterMode(command);
} else if (channelId.equals(CHANNEL_ECOMODE)) {
private void setRepeaterMode(Command command) {
if (command == RefreshType.REFRESH) {
- senderId = null; // make this message invalid as we do not support refresh of repeater status
+ senderId = new byte[0]; // make this message invalid as we do not support refresh of repeater status
} else if (command instanceof StringType) {
switch (((StringType) command).toString()) {
case EnOceanBindingConstants.REPEATERMODE_LEVEL_1:
private void setEcoMode(Command command) {
if (command == RefreshType.REFRESH) {
- senderId = null; // make this message invalid as we do not support refresh of ecomode status
+ senderId = new byte[0]; // make this message invalid as we do not support refresh of ecomode status
} else if (command instanceof OnOffType) {
if (((OnOffType) command) == OnOffType.ON) {
setRORG(RORG.MSC).setData((byte) 0x03, (byte) 0x36, (byte) 0x01);
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_0A extends D2_01 {
public D2_01_0A() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_0B extends D2_01 {
public D2_01_0B() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_0C extends D2_01 {
public D2_01_0C() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_0D extends D2_01 {
public D2_01_0D() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_0E extends D2_01 {
public D2_01_0E() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_0F extends D2_01 {
public D2_01_0F() {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanBindingConstants;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_0F_NodON extends D2_01 {
public D2_01_0F_NodON() {
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (channelId.equalsIgnoreCase(CHANNEL_REPEATERMODE)) {
if (command instanceof RefreshType) {
- senderId = null; // make this message invalid as we do not support refresh of repeter status
+ senderId = new byte[0]; // make this message invalid as we do not support refresh of repeter status
} else if (command instanceof StringType) {
switch (((StringType) command).toString()) {
case EnOceanBindingConstants.REPEATERMODE_LEVEL_1:
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_11 extends D2_01 {
public D2_01_11() {
*/
package org.openhab.binding.enocean.internal.eep.D2_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_12 extends D2_01 {
public D2_01_12() {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanBindingConstants;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_01_12_NodON extends D2_01 {
public D2_01_12_NodON() {
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (channelId.equalsIgnoreCase(CHANNEL_REPEATERMODE)) {
if (command instanceof RefreshType) {
- senderId = null; // make this message invalid as we do not support refresh of repeter status
+ senderId = new byte[0]; // make this message invalid as we do not support refresh of repeter status
} else if (command instanceof StringType) {
switch (((StringType) command).toString()) {
case EnOceanBindingConstants.REPEATERMODE_LEVEL_1:
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_03_0A extends _VLDMessage {
- protected final byte ShortPress = 0x01;
- protected final byte DoublePress = 0x02;
- protected final byte LongPress = 0x03;
- protected final byte LongRelease = 0x04;
+ protected static final byte SHORT_PRESS = 0x01;
+ protected static final byte DOUBLE_PRESS = 0x02;
+ protected static final byte LONG_PRESS = 0x03;
+ protected static final byte LONG_RELEASE = 0x04;
public D2_03_0A() {
super();
}
@Override
- protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+ protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
Configuration config) {
switch (channelId) {
case CHANNEL_PUSHBUTTON:
- return (bytes[1] == ShortPress) ? CommonTriggerEvents.PRESSED : null;
+ return (bytes[1] == SHORT_PRESS) ? CommonTriggerEvents.PRESSED : null;
case CHANNEL_DOUBLEPRESS:
- return (bytes[1] == DoublePress) ? CommonTriggerEvents.PRESSED : null;
+ return (bytes[1] == DOUBLE_PRESS) ? CommonTriggerEvents.PRESSED : null;
case CHANNEL_LONGPRESS:
- return (bytes[1] == LongPress) ? CommonTriggerEvents.PRESSED
- : ((bytes[1] == LongRelease) ? CommonTriggerEvents.RELEASED : null);
+ return (bytes[1] == LONG_PRESS) ? CommonTriggerEvents.PRESSED
+ : ((bytes[1] == LONG_RELEASE) ? CommonTriggerEvents.RELEASED : null);
default:
return null;
}
}
@Override
- public State convertToStateImpl(String channelId, String channelTypeId, Function<String, State> getCurrentStateFunc,
- Configuration config) {
+ public State convertToStateImpl(String channelId, String channelTypeId,
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (CHANNEL_BATTERY_LEVEL.equals(channelId)) {
return new QuantityType<>(bytes[0] & 0xFF, Units.PERCENT);
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_05_00 extends _VLDMessage {
- protected final byte cmdMask = 0x0f;
- protected final byte outputValueMask = 0x7f;
- protected final byte outputChannelMask = 0x1f;
+ protected static final byte CMD_MASK = 0x0f;
+ protected static final byte OUTPUT_VALUE_MASK = 0x7f;
+ protected static final byte OUTPUT_CHANNEL_MASK = 0x1f;
- protected final byte CMD_ACTUATOR_SET_POSITION = 0x01;
- protected final byte CMD_ACTUATOR_STOP = 0x02;
- protected final byte CMD_ACTUATOR_POSITION_QUERY = 0x03;
- protected final byte CMD_ACTUATOR_POSITION_RESPONE = 0x04;
+ protected static final byte CMD_ACTUATOR_SET_POSITION = 0x01;
+ protected static final byte CMD_ACTUATOR_STOP = 0x02;
+ protected static final byte CMD_ACTUATOR_POSITION_QUERY = 0x03;
+ protected static final byte CMD_ACTUATOR_POSITION_RESPONE = 0x04;
- protected final byte AllChannels_Mask = 0x1e;
- protected final byte ChannelA_Mask = 0x00;
+ protected static final byte ALL_CHANNELS_MASK = 0x1e;
+ protected static final byte CHANNEL_A_MASK = 0x00;
- protected final byte DOWN = 0x64; // 100%
- protected final byte UP = 0x00; // 0%
+ protected static final byte DOWN = 0x64; // 100%
+ protected static final byte UP = 0x00; // 0%
public D2_05_00() {
super();
}
protected byte getCMD() {
- return (byte) (bytes[bytes.length - 1] & cmdMask);
+ return (byte) (bytes[bytes.length - 1] & CMD_MASK);
}
protected void setPositionData(Command command, byte outputChannel) {
}
protected byte getChannel() {
- return (byte) (bytes[1] & outputChannelMask);
+ return (byte) (bytes[1] & OUTPUT_CHANNEL_MASK);
}
@Override
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (channelId.equals(CHANNEL_ROLLERSHUTTER)) {
if (command == RefreshType.REFRESH) {
- setPositionQueryData(ChannelA_Mask);
+ setPositionQueryData(CHANNEL_A_MASK);
} else {
- setPositionData(command, ChannelA_Mask);
+ setPositionData(command, CHANNEL_A_MASK);
}
}
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_ROLLERSHUTTER:
return getPositionData();
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanBindingConstants;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
import org.openhab.core.types.State;
/**
- *
+ * @author MArcel Eckert - Initial contribution
* @author Marcel Eckert - based on D2_01_0F_NodON.java and D2_01_12_NodOn.java
*
*/
+@NonNullByDefault
public class D2_05_00_NodON extends D2_05_00 {
public D2_05_00_NodON() {
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (channelId.equals(CHANNEL_REPEATERMODE)) {
if (command == RefreshType.REFRESH) {
- senderId = null; // make this message invalid as we do not support refresh of repeter status
+ senderId = new byte[0]; // make this message invalid as we do not support refresh of repeter status
} else if (command instanceof StringType) {
switch (((StringType) command).toString()) {
case EnOceanBindingConstants.REPEATERMODE_LEVEL_1:
import java.util.Optional;
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Thomas Lauterbach - Initial contribution
*/
+@NonNullByDefault
public class D2_06_01 extends _VLDMessage {
private enum MessageType {
-
SENSORVALUES(0x00),
CONFIGURATIONREPORT(0x10),
LOGDATA01(0x20),
}
private enum SashState {
-
// WINDOWSTATEUNDEFINED(0x00, "UNDEFINED"),
NOTTILTED(0x01, "NOT TILTED"),
TILTED(0x02, "TILTED");
}
private enum HandleState {
-
// HANDLEPOSITIONUNDEFINED(0x00, "UNDEFINED"),
HANDLEUP(0x01, "UP"),
HANDLEDOWN(0x02, "DOWN"),
}
private enum MotionState {
-
MOTIONNOTTRIGGERED(0x00, "OFF"),
MOTIONTRIGGERED(0x01, "ON");
}
@Override
- protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+ protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
Configuration config) {
-
// Sensor values
if (bytes[0] == MessageType.SENSORVALUES.getIntValue()) {
switch (channelId) {
}
@Override
- public State convertToStateImpl(String channelId, String channelTypeId, Function<String, State> getCurrentStateFunc,
- Configuration config) {
-
+ public State convertToStateImpl(String channelId, String channelTypeId,
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
// Sensor values
if (bytes[0] == MessageType.SENSORVALUES.getIntValue()) {
switch (channelId) {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Thomas Lauterbach - Initial contribution
*/
+@NonNullByDefault
public class D2_06_50 extends _VLDMessage {
public D2_06_50() {
}
@Override
- protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+ protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
Configuration config) {
-
// Alarm
if (bytes[0] == 0x02) {
switch (channelId) {
@Override
public State convertToStateImpl(String channelId, String channelTypeId, Function<String, State> getCurrentStateFunc,
Configuration config) {
-
// Window status
if (bytes[0] == 0x01) {
switch (channelId) {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_14_30 extends _VLDMessage {
private final String[] hygroComfortIndexValues = { "GOOD", "MEDIUM", "BAD", "ERROR" };
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.Helper;
import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D2_50 extends _VLDMessage {
- protected static final byte mtMask = (byte) 0xf0;
+ protected static final byte MT_MASK = (byte) 0xf0;
protected static final byte MT_REMOTE_TRANSMISSION_REQUEST = 0x00;
protected static final byte MT_CONTROL = 0x20;
protected static final byte MT_BASIC_STATUS = 0x40;
protected static final byte MT_EXTENDED_STATUS = 0x60; // not yet implemented
protected static final byte MT_UNKNOWN_STATUS = (byte) 0x80; // Sent by some systems during teach in
- protected static final byte rmtMask = (byte) 0x0f;
+ protected static final byte RMT_MASK = (byte) 0x0f;
protected static final byte RMT_BASIC_STATUS = 0x00;
protected static final byte RMT_EXTENDED_STATUS = 0x01; // not yet implemented
}
protected byte getMessageType(byte b) {
- return (byte) (b & mtMask);
+ return (byte) (b & MT_MASK);
}
@Override
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
// we need to send just a single message to refresh all channel states, hence just send refresh for OM
if (command == RefreshType.REFRESH && CHANNEL_VENTILATIONOPERATIONMODE.equals(channelId)) {
setData((byte) (MT_REMOTE_TRANSMISSION_REQUEST + RMT_BASIC_STATUS));
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
Function<String, State> getCurrentStateFunc, Configuration config) {
-
if (getMessageType(bytes[0]) != MT_BASIC_STATUS) {
return UnDefType.UNDEF;
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig;
import org.openhab.binding.enocean.internal.eep.Base._1BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class D5_00_01 extends _1BSMessage {
- final byte OPEN = 0 | TeachInBit;
- final byte CLOSED = 1 | TeachInBit;
+ protected static final byte OPEN = 0 | TEACHIN_BIT;
+ protected static final byte CLOSED = 1 | TEACHIN_BIT;
public D5_00_01() {
super();
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (channelId.equals(CHANNEL_CONTACT)) {
EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
if (c.inverted) {
import java.util.Arrays;
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.Helper;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class EEP {
protected RORG newRORG = RORG.Unknown;
- protected byte[] bytes;
- protected byte[] optionalData;
- protected byte[] senderId;
- protected byte status;
+ protected byte[] bytes = new byte[0];
+ protected byte[] optionalData = new byte[0];
+ protected byte[] senderId = new byte[0];
+ protected byte status = 0x00;
- protected byte[] destinationId;
+ protected byte[] destinationId = new byte[0];
protected boolean suppressRepeating;
protected Logger logger = LoggerFactory.getLogger(EEP.class);
- private EEPType eepType = null;
- protected ERP1Message packet = null;
+ private @Nullable EEPType eepType = null;
+ protected @Nullable ERP1Message packet = null;
public EEP() {
// ctor for sending
-
- status = 0x00;
- senderId = null;
- bytes = null;
}
public EEP(ERP1Message packet) {
}
public EEP convertFromCommand(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (!getEEPType().isChannelSupported(channelId, channelTypeId)) {
throw new IllegalArgumentException(String.format("Command %s of channel %s(%s) is not supported",
command.toString(), channelId, channelTypeId));
}
public State convertToState(String channelId, String channelTypeId, Configuration config,
- Function<String, State> getCurrentStateFunc) {
+ Function<String, @Nullable State> getCurrentStateFunc) {
if (!getEEPType().isChannelSupported(channelId, channelTypeId)) {
throw new IllegalArgumentException(
String.format("Channel %s(%s) is not supported", channelId, channelTypeId));
switch (channelTypeId) {
case CHANNEL_RSSI:
- if (this.optionalData == null || this.optionalData.length < 6) {
+ if (this.optionalData.length < 6) {
return UnDefType.UNDEF;
}
return new DecimalType((this.optionalData[5] & 0xFF) * -1);
case CHANNEL_REPEATCOUNT:
- if (this.optionalData == null || this.optionalData.length < 6) {
+ if (this.optionalData.length < 6) {
return UnDefType.UNDEF;
}
return convertToStateImpl(channelId, channelTypeId, getCurrentStateFunc, config);
}
- public String convertToEvent(String channelId, String channelTypeId, String lastEvent, Configuration config) {
+ public @Nullable String convertToEvent(String channelId, String channelTypeId, String lastEvent,
+ Configuration config) {
if (!getEEPType().isChannelSupported(channelId, channelTypeId)) {
throw new IllegalArgumentException(
String.format("Channel %s(%s) is not supported", channelId, channelTypeId));
return this;
}
- public EEP setData(byte... bytes) {
+ public EEP setData(byte... bytes) throws IllegalArgumentException {
if (!validateData(bytes)) {
throw new IllegalArgumentException();
}
}
public boolean hasData() {
- return (this.bytes != null) && (this.bytes.length > 0);
+ return (this.bytes.length > 0);
}
public EEP setOptionalData(byte... bytes) {
- if (bytes != null) {
+ if (bytes.length > 0) {
this.optionalData = Arrays.copyOf(bytes, bytes.length);
}
}
public EEP setSenderId(byte[] senderId) {
- if (senderId == null || senderId.length != ESP3_SENDERID_LENGTH) {
+ if (senderId.length != ESP3_SENDERID_LENGTH) {
throw new IllegalArgumentException();
}
return this;
}
- public final ERP1Message getERP1Message() {
+ public final @Nullable ERP1Message getERP1Message() {
if (isValid()) {
- int optionalDataLength = 0;
- if (optionalData != null) {
- optionalDataLength = optionalData.length;
- }
-
byte[] payLoad = new byte[ESP3_RORG_LENGTH + getDataLength() + ESP3_SENDERID_LENGTH + ESP3_STATUS_LENGTH
- + optionalDataLength];
+ + optionalData.length];
Arrays.fill(payLoad, ZERO);
byte rorgValue = getEEPType().getRORG().getValue();
payLoad = Helper.concatAll(new byte[] { rorgValue }, bytes, senderId,
new byte[] { (byte) (status | (suppressRepeating ? 0b1111 : 0)) }, optionalData);
- return new ERP1Message(payLoad.length - optionalDataLength, optionalDataLength, payLoad);
+ return new ERP1Message(payLoad.length - optionalData.length, optionalData.length, payLoad);
} else {
logger.warn("ERP1Message for EEP {} is not valid!", this.getClass().getName());
}
}
protected boolean validateData(byte[] bytes) {
- return bytes != null && bytes.length == getDataLength();
+ return bytes.length == getDataLength();
}
public boolean isValid() {
- return validateData(bytes) && senderId != null && senderId.length == ESP3_SENDERID_LENGTH;
+ return validateData(bytes) && senderId.length == ESP3_SENDERID_LENGTH;
}
protected EEPType getEEPType() {
- if (eepType == null) {
- eepType = EEPType.getType(this.getClass());
+ EEPType localType = eepType;
+ if (localType == null) {
+ localType = EEPType.getType(this.getClass());
}
- return eepType;
+ return localType;
}
protected int getDataLength() {
- if (getEEPType() != null) {
- return getEEPType().getRORG().getDataLength();
- }
-
- return 0;
+ return getEEPType().getRORG().getDataLength();
}
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
logger.warn("No implementation for sending data from channel {}/{} for this EEP!", channelId, channelTypeId);
}
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
return UnDefType.UNDEF;
}
- protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+ protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
Configuration config) {
return null;
}
- protected void teachInQueryImpl(Configuration config) {
+ protected void teachInQueryImpl(@Nullable Configuration config) {
logger.warn("No implementation for sending a response for this teach in!");
}
return (byteData & mask) != 0;
}
- public ThingTypeUID getThingTypeUID() {
+ public @Nullable ThingTypeUID getThingTypeUID() {
return getEEPType().getThingTypeUID();
}
}
public EEP setDestinationId(byte[] destinationId) {
- if (destinationId != null) {
+ if (destinationId.length > 0) {
this.destinationId = Arrays.copyOf(destinationId, destinationId.length);
setOptionalData(Helper.concatAll(new byte[] { 0x01 }, destinationId, new byte[] { (byte) 0xff, 0x00 }));
}
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base.UTEResponse;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.eep.Base._4BSTeachInVariation3Response;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
import org.openhab.binding.enocean.internal.messages.EventMessage;
import org.openhab.binding.enocean.internal.messages.EventMessage.EventMessageType;
-import org.openhab.binding.enocean.internal.messages.Responses.SMACKTeachInResponse;
+import org.openhab.binding.enocean.internal.messages.responses.SMACKTeachInResponse;
import org.openhab.core.util.HexUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EEPFactory {
private static final Logger logger = LoggerFactory.getLogger(EEPFactory.class);
}
}
- private static EEPType getGenericEEPTypeFor(byte rorg) {
+ private static @Nullable EEPType getGenericEEPTypeFor(byte rorg) {
logger.info("Received unsupported EEP teach in, trying to fallback to generic thing");
RORG r = RORG.getRORG(rorg);
if (r == RORG._4BS) {
}
}
- public static EEP buildEEPFromTeachInERP1(ERP1Message msg) {
+ public static @Nullable EEP buildEEPFromTeachInERP1(ERP1Message msg) {
if (!msg.getIsTeachIn() && !(msg.getRORG() == RORG.RPS)) {
return null;
}
case _1BS:
return new D5_00_01(msg);
case _4BS: {
- int db_0 = msg.getPayload()[4];
- if ((db_0 & _4BSMessage.LRN_Type_Mask) == 0) { // Variation 1
+ int db0 = msg.getPayload()[4];
+ if ((db0 & _4BSMessage.LRN_TYPE_MASK) == 0) { // Variation 1
logger.info("Received 4BS Teach In variation 1 without EEP, fallback to generic thing");
return buildEEP(EEPType.Generic4BS, msg);
}
- byte db_3 = msg.getPayload()[1];
- byte db_2 = msg.getPayload()[2];
- byte db_1 = msg.getPayload()[3];
+ byte db3 = msg.getPayload()[1];
+ byte db2 = msg.getPayload()[2];
+ byte db1 = msg.getPayload()[3];
- int func = (db_3 & 0xFF) >>> 2;
- int type = ((db_3 & 0b11) << 5) + ((db_2 & 0xFF) >>> 3);
- int manufId = ((db_2 & 0b111) << 8) + (db_1 & 0xff);
+ int func = (db3 & 0xFF) >>> 2;
+ int type = ((db3 & 0b11) << 5) + ((db2 & 0xFF) >>> 3);
+ int manufId = ((db2 & 0b111) << 8) + (db1 & 0xff);
logger.debug("Received 4BS Teach In with EEP A5-{}-{} and manufacturerID {}",
HexUtils.bytesToHex(new byte[] { (byte) func }),
return null;
}
- public static EEP buildEEPFromTeachInSMACKEvent(EventMessage event) {
+ public static @Nullable EEP buildEEPFromTeachInSMACKEvent(EventMessage event) {
if (event.getEventMessageType() != EventMessageType.SA_CONFIRM_LEARN) {
return null;
}
eepType = getGenericEEPTypeFor(rorg);
}
- return createEEP(eepType).setSenderId(senderId);
+ return (eepType == null) ? null : createEEP(eepType).setSenderId(senderId);
}
- public static EEP buildResponseEEPFromTeachInERP1(ERP1Message msg, byte[] senderId, boolean teachIn) {
+ public static @Nullable EEP buildResponseEEPFromTeachInERP1(ERP1Message msg, byte[] senderId, boolean teachIn) {
switch (msg.getRORG()) {
case UTE:
EEP result = new UTEResponse(msg, teachIn);
import javax.measure.quantity.Energy;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelTotalusageConfig;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.QuantityType;
* @author Dominik Vorreiter - initial contribution
*
*/
+@NonNullByDefault
public abstract class EEPHelper {
- public static State validateTotalUsage(State value, State currentState, Configuration config) {
+ public static State validateTotalUsage(State value, @Nullable State currentState, Configuration config) {
EnOceanChannelTotalusageConfig c = config.as(EnOceanChannelTotalusageConfig.class);
if (c.validateValue && (value instanceof QuantityType) && (currentState instanceof QuantityType)) {
import java.util.Hashtable;
import java.util.Map;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanChannelDescription;
import org.openhab.binding.enocean.internal.config.EnOceanChannelTransformationConfig;
import org.openhab.binding.enocean.internal.eep.A5_02.A5_02_01;
import org.openhab.binding.enocean.internal.eep.F6_10.F6_10_00;
import org.openhab.binding.enocean.internal.eep.F6_10.F6_10_00_EltakoFPE;
import org.openhab.binding.enocean.internal.eep.F6_10.F6_10_01;
-import org.openhab.binding.enocean.internal.eep.Generic.Generic4BS;
-import org.openhab.binding.enocean.internal.eep.Generic.GenericRPS;
-import org.openhab.binding.enocean.internal.eep.Generic.GenericVLD;
+import org.openhab.binding.enocean.internal.eep.generic.Generic4BS;
+import org.openhab.binding.enocean.internal.eep.generic.GenericRPS;
+import org.openhab.binding.enocean.internal.eep.generic.GenericVLD;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Channel;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public enum EEPType {
- Undef(RORG.Unknown, 0, 0, false, null, null, 0),
+ Undef(RORG.Unknown, 0, 0, false, EEP.class, null, 0),
UTEResponse(RORG.UTE, 0, 0, false, UTEResponse.class, null),
_4BSTeachInVariation3Response(RORG._4BS, 0, 0, false, _4BSTeachInVariation3Response.class, null),
put(CHANNEL_ROLLERSHUTTER, new Configuration());
put(CHANNEL_TEACHINCMD, new Configuration() {
{
- put(PARAMETER_CHANNEL_TeachInMSG, "fff80d80");
+ put(PARAMETER_CHANNEL_TEACHINMSG, "fff80d80");
}
});
}
put(CHANNEL_ROLLERSHUTTER, new Configuration());
put(CHANNEL_TEACHINCMD, new Configuration() {
{
- put(PARAMETER_CHANNEL_TeachInMSG, "fff80d80");
+ put(PARAMETER_CHANNEL_TEACHINMSG, "fff80d80");
}
});
}
private String manufactorSuffix;
private int manufactorId;
- private ThingTypeUID thingTypeUID;
+ private @Nullable ThingTypeUID thingTypeUID;
private Hashtable<String, Configuration> channelIdsWithConfig = new Hashtable<>();
private Hashtable<String, EnOceanChannelDescription> supportedChannels = new Hashtable<>();
private boolean requestsResponse;
EEPType(RORG rorg, int func, int type, boolean supportsRefresh, Class<? extends EEP> eepClass,
- ThingTypeUID thingTypeUID, String... channelIds) {
+ @Nullable ThingTypeUID thingTypeUID, String... channelIds) {
this(rorg, func, type, supportsRefresh, eepClass, thingTypeUID, -1, channelIds);
}
}
EEPType(RORG rorg, int func, int type, boolean supportsRefresh, Class<? extends EEP> eepClass,
- ThingTypeUID thingTypeUID, int command, String... channelIds) {
+ @Nullable ThingTypeUID thingTypeUID, int command, String... channelIds) {
this(rorg, func, type, supportsRefresh, false, "", 0, eepClass, thingTypeUID, command, channelIds);
}
}
EEPType(RORG rorg, int func, int type, boolean supportsRefresh, boolean requestsResponse, String manufactorSuffix,
- int manufId, Class<? extends EEP> eepClass, ThingTypeUID thingTypeUID, int command, String... channelIds) {
+ int manufId, Class<? extends EEP> eepClass, @Nullable ThingTypeUID thingTypeUID, int command,
+ String... channelIds) {
this.rorg = rorg;
this.func = func;
this.type = type;
this.requestsResponse = requestsResponse;
for (String id : channelIds) {
- this.channelIdsWithConfig.put(id, new Configuration());
- this.supportedChannels.put(id, CHANNELID2CHANNELDESCRIPTION.get(id));
+ if (id != null) {
+ this.channelIdsWithConfig.put(id, new Configuration());
+ EnOceanChannelDescription description = CHANNELID2CHANNELDESCRIPTION.get(id);
+ if (description != null) {
+ this.supportedChannels.put(id, description);
+ }
+ }
}
addDefaultChannels();
}
EEPType(RORG rorg, int func, int type, boolean supportsRefresh, boolean requestsResponse, String manufactorSuffix,
- int manufId, Class<? extends EEP> eepClass, ThingTypeUID thingTypeUID, int command,
+ int manufId, Class<? extends EEP> eepClass, @Nullable ThingTypeUID thingTypeUID, int command,
Hashtable<String, Configuration> channelConfigs) {
this.rorg = rorg;
this.func = func;
this.requestsResponse = requestsResponse;
for (String id : channelConfigs.keySet()) {
- this.supportedChannels.put(id, CHANNELID2CHANNELDESCRIPTION.get(id));
+ this.supportedChannels = addChannelDescription(supportedChannels, id, CHANNELID2CHANNELDESCRIPTION.get(id));
}
addDefaultChannels();
}
private void addDefaultChannels() {
-
if (THING_TYPE_GENERICTHING.equals(this.thingTypeUID)) {
this.channelIdsWithConfig.put(CHANNEL_GENERIC_SWITCH, new EnOceanChannelTransformationConfig());
- this.supportedChannels.put(CHANNEL_GENERIC_SWITCH,
+
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_SWITCH,
CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_SWITCH));
this.channelIdsWithConfig.put(CHANNEL_GENERIC_ROLLERSHUTTER, new EnOceanChannelTransformationConfig());
- this.supportedChannels.put(CHANNEL_GENERIC_ROLLERSHUTTER,
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_ROLLERSHUTTER,
CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_ROLLERSHUTTER));
this.channelIdsWithConfig.put(CHANNEL_GENERIC_DIMMER, new EnOceanChannelTransformationConfig());
- this.supportedChannels.put(CHANNEL_GENERIC_DIMMER,
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_DIMMER,
CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_DIMMER));
this.channelIdsWithConfig.put(CHANNEL_GENERIC_NUMBER, new EnOceanChannelTransformationConfig());
- this.supportedChannels.put(CHANNEL_GENERIC_NUMBER,
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_NUMBER,
CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_NUMBER));
this.channelIdsWithConfig.put(CHANNEL_GENERIC_STRING, new EnOceanChannelTransformationConfig());
- this.supportedChannels.put(CHANNEL_GENERIC_STRING,
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_STRING,
CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_STRING));
this.channelIdsWithConfig.put(CHANNEL_GENERIC_COLOR, new EnOceanChannelTransformationConfig());
- this.supportedChannels.put(CHANNEL_GENERIC_COLOR, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_COLOR));
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_COLOR,
+ CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_COLOR));
this.channelIdsWithConfig.put(CHANNEL_GENERIC_TEACHINCMD, new EnOceanChannelTransformationConfig());
- this.supportedChannels.put(CHANNEL_GENERIC_TEACHINCMD,
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_GENERIC_TEACHINCMD,
CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_GENERIC_TEACHINCMD));
}
this.channelIdsWithConfig.put(CHANNEL_RSSI, new Configuration());
- this.supportedChannels.put(CHANNEL_RSSI, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_RSSI));
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_RSSI,
+ CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_RSSI));
this.channelIdsWithConfig.put(CHANNEL_REPEATCOUNT, new Configuration());
- this.supportedChannels.put(CHANNEL_REPEATCOUNT, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_REPEATCOUNT));
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_REPEATCOUNT,
+ CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_REPEATCOUNT));
this.channelIdsWithConfig.put(CHANNEL_LASTRECEIVED, new Configuration());
- this.supportedChannels.put(CHANNEL_LASTRECEIVED, CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_LASTRECEIVED));
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_LASTRECEIVED,
+ CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_LASTRECEIVED));
if (requestsResponse) {
this.channelIdsWithConfig.put(CHANNEL_STATUS_REQUEST_EVENT, new Configuration());
- this.supportedChannels.put(CHANNEL_STATUS_REQUEST_EVENT,
+ this.supportedChannels = addChannelDescription(this.supportedChannels, CHANNEL_STATUS_REQUEST_EVENT,
CHANNELID2CHANNELDESCRIPTION.get(CHANNEL_STATUS_REQUEST_EVENT));
}
}
+ private static Hashtable<String, EnOceanChannelDescription> addChannelDescription(
+ Hashtable<String, EnOceanChannelDescription> channels, @Nullable String id,
+ @Nullable EnOceanChannelDescription channelDescription) {
+ if (id != null && channelDescription != null) {
+ channels.put(id, channelDescription);
+ }
+ return channels;
+ }
+
public Class<? extends EEP> getEEPClass() {
return eepClass;
}
return requestsResponse;
}
- public Map<String, EnOceanChannelDescription> GetSupportedChannels() {
+ public Map<String, EnOceanChannelDescription> getSupportedChannels() {
return Collections.unmodifiableMap(supportedChannels);
}
|| supportedChannels.values().stream().anyMatch(c -> c.channelTypeUID.getId().equals(channelTypeId));
}
- public ThingTypeUID getThingTypeUID() {
+ public @Nullable ThingTypeUID getThingTypeUID() {
return thingTypeUID;
}
- @NonNull
public String getId() {
if (command == -1) {
return String.format("%02X_%02X_%02X", rorg.getValue(), func, type);
}
}
- @NonNull
public Configuration getChannelConfig(String channelId) {
Configuration c = null;
-
- if (channelIdsWithConfig != null) {
+ if (!channelIdsWithConfig.isEmpty()) {
c = channelIdsWithConfig.get(channelId);
+ if (c != null) {
+ return c;
+ }
}
-
- if (c != null) {
- return c;
- }
-
return new Configuration();
}
public static EEPType getType(Class<? extends EEP> eepClass) {
for (EEPType eep : values()) {
- if (eep.eepClass != null && eep.eepClass.equals(eepClass)) {
+ if (eep.eepClass.equals(eepClass)) {
return eep;
}
}
throw new IllegalArgumentException(String.format("EEP with class %s could not be found", eepClass.getName()));
}
- public static EEPType getType(RORG rorg, int func, int type, int manufId) {
+ public static @Nullable EEPType getType(RORG rorg, int func, int type, int manufId) {
EEPType fallback = null;
for (EEPType eep : values()) {
*/
package org.openhab.binding.enocean.internal.eep.F6_01;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class F6_01_01 extends _RPSMessage {
public F6_01_01() {
}
@Override
- protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+ protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
Configuration config) {
-
return getBit(bytes[0], 4) ? CommonTriggerEvents.PRESSED : CommonTriggerEvents.RELEASED;
}
import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchConfigBase.SwitchMode;
import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class F6_02 extends _RPSMessage {
- final byte AI = 0;
- final byte A0 = 1;
- final byte BI = 2;
- final byte B0 = 3;
- final byte PRESSED = 16;
- final byte PRESSED_SEC = 1;
+ protected static final byte AI = 0;
+ protected static final byte A0 = 1;
+ protected static final byte BI = 2;
+ protected static final byte B0 = 3;
+ protected static final byte PRESSED = 16;
+ protected static final byte PRESSED_SEC = 1;
- final String DIR1 = "DIR1";
- final String DIR2 = "DIR2";
- final String NODIR = "-";
+ protected static final String DIR1 = "DIR1";
+ protected static final String DIR2 = "DIR2";
+ protected static final String NODIR = "-";
int secondByte = -1;
int secondStatus = -1;
return dirA + "|" + dirB;
}
- protected String getChannelEvent(byte dir1, byte dir2) {
+ protected @Nullable String getChannelEvent(byte dir1, byte dir2) {
if ((bytes[0] & PRESSED_SEC) != 0) {
// Do not emit an event if channelA is pressed together with channelB as it is undetermined which one gets
// fired first
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchConfigBase.Channel;
import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchListenerConfig;
import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class F6_02_01 extends F6_02 {
public F6_02_01() {
}
@Override
- protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+ protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
Configuration config) {
-
if (t21 && nu) {
if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
return getRockerSwitchAction(config);
if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
return CommonTriggerEvents.RELEASED;
} else {
- if (lastEvent != null && lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) {
+ if (lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) {
return CommonTriggerEvents.DIR1_RELEASED;
- } else if (lastEvent != null && lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) {
+ } else if (lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) {
return CommonTriggerEvents.DIR2_RELEASED;
}
}
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (command instanceof StringType) {
String s = ((StringType) command).toString();
if (s.equals(CommonTriggerEvents.DIR1_RELEASED) || s.equals(CommonTriggerEvents.DIR2_RELEASED)) {
- setStatus(_RPSMessage.T21Flag);
+ setStatus(_RPSMessage.T21_FLAG);
setData((byte) 0x00);
return;
}
byte dir2 = channelTypeId.equalsIgnoreCase(CHANNEL_VIRTUALROCKERSWITCHB) ? BI : AI;
if (s.equals(CommonTriggerEvents.DIR1_PRESSED)) {
- setStatus((byte) (_RPSMessage.T21Flag | _RPSMessage.NUFlag));
+ setStatus((byte) (_RPSMessage.T21_FLAG | _RPSMessage.NU_FLAG));
setData((byte) ((dir1 << 5) | PRESSED));
} else if (s.equals(CommonTriggerEvents.DIR2_PRESSED)) {
- setStatus((byte) (_RPSMessage.T21Flag | _RPSMessage.NUFlag));
+ setStatus((byte) (_RPSMessage.T21_FLAG | _RPSMessage.NU_FLAG));
setData((byte) ((dir2 << 5) | PRESSED));
}
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
// this method is used by the classic device listener channels to convert a rocker switch message into an
// appropriate item update
State currentState = getCurrentStateFunc.apply(channelId);
- if (t21 && nu) {
+ if (t21 && nu && currentState != null) {
EnOceanChannelRockerSwitchListenerConfig c = config.as(EnOceanChannelRockerSwitchListenerConfig.class);
byte dir1 = c.getChannel() == Channel.ChannelA ? A0 : B0;
byte dir2 = c.getChannel() == Channel.ChannelA ? AI : BI;
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchConfigBase.Channel;
import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchListenerConfig;
import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class F6_02_02 extends F6_02 {
public F6_02_02() {
}
@Override
- protected String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+ protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
Configuration config) {
-
if (t21 && nu) {
if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
return getRockerSwitchAction(config);
if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
return CommonTriggerEvents.RELEASED;
} else {
- if (lastEvent != null && lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) {
+ if (lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) {
return CommonTriggerEvents.DIR1_RELEASED;
- } else if (lastEvent != null && lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) {
+ } else if (lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) {
return CommonTriggerEvents.DIR2_RELEASED;
}
}
@Override
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
if (command instanceof StringType) {
String s = ((StringType) command).toString();
if (s.equals(CommonTriggerEvents.DIR1_RELEASED) || s.equals(CommonTriggerEvents.DIR2_RELEASED)) {
- setStatus(_RPSMessage.T21Flag);
+ setStatus(_RPSMessage.T21_FLAG);
setData((byte) 0x00);
return;
}
byte dir2 = channelTypeId.equalsIgnoreCase(CHANNEL_VIRTUALROCKERSWITCHB) ? B0 : A0;
if (s.equals(CommonTriggerEvents.DIR1_PRESSED)) {
- setStatus((byte) (_RPSMessage.T21Flag | _RPSMessage.NUFlag));
+ setStatus((byte) (_RPSMessage.T21_FLAG | _RPSMessage.NU_FLAG));
setData((byte) ((dir1 << 5) | PRESSED));
} else if (s.equals(CommonTriggerEvents.DIR2_PRESSED)) {
- setStatus((byte) (_RPSMessage.T21Flag | _RPSMessage.NUFlag));
+ setStatus((byte) (_RPSMessage.T21_FLAG | _RPSMessage.NU_FLAG));
setData((byte) ((dir2 << 5) | PRESSED));
}
}
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
// this method is used by the classic device listener channels to convert a rocker switch message into an
// appropriate item update
State currentState = getCurrentStateFunc.apply(channelId);
- if (t21 && nu) {
+ if (t21 && nu && currentState != null) {
EnOceanChannelRockerSwitchListenerConfig c = config.as(EnOceanChannelRockerSwitchListenerConfig.class);
byte dir1 = c.getChannel() == Channel.ChannelA ? AI : BI;
byte dir2 = c.getChannel() == Channel.ChannelA ? A0 : B0;
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
import org.openhab.core.config.core.Configuration;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class F6_05_02 extends _RPSMessage {
protected static final byte ALARM_OFF = 0x00;
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
switch (channelId) {
case CHANNEL_SMOKEDETECTION:
return bytes[0] == ALARM_OFF ? OnOffType.OFF : (bytes[0] == ALARM_ON ? OnOffType.ON : UnDefType.UNDEF);
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig;
import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class F6_10_00 extends _RPSMessage {
- public final byte Closed = (byte) 0xF0; // 1111xxxx
- public final byte Open1 = (byte) 0xE0; // 1110xxxx
- public final byte Open2 = (byte) 0xC0; // 1100xxxx
- public final byte Tilted = (byte) 0xD0; // 1101xxxx
+ public static final byte CLOSED = (byte) 0xF0; // 1111xxxx
+ public static final byte OPEN_1 = (byte) 0xE0; // 1110xxxx
+ public static final byte OPEN_2 = (byte) 0xC0; // 1100xxxx
+ public static final byte TILTED = (byte) 0xD0; // 1101xxxx
public F6_10_00() {
super();
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
byte data = (byte) (bytes[0] & 0xF0);
// todo localization
switch (channelId) {
case CHANNEL_WINDOWHANDLESTATE:
- if (data == Closed) {
+ if (data == CLOSED) {
return new StringType("CLOSED");
- } else if (data == Tilted) {
+ } else if (data == TILTED) {
return new StringType("TILTED");
- } else if (data == Open1 || data == Open2) {
+ } else if (data == OPEN_1 || data == OPEN_2) {
return new StringType("OPEN");
}
case CHANNEL_CONTACT:
EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
- if (data == Closed) {
+ if (data == CLOSED) {
return c.inverted ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
- } else if (data == Tilted) {
+ } else if (data == TILTED) {
return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
- } else if (data == Open1 || data == Open2) {
+ } else if (data == OPEN_1 || data == OPEN_2) {
return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
}
}
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig;
import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Holger Englert - Initial contribution
*/
+@NonNullByDefault
public class F6_10_00_EltakoFPE extends _RPSMessage {
- final byte OPEN = 0x00;
- final byte CLOSED = 0x10;
+ protected static final byte OPEN = 0x00;
+ protected static final byte CLOSED = 0x10;
public F6_10_00_EltakoFPE() {
super();
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
if (channelId.equals(CHANNEL_CONTACT)) {
EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
if (c.inverted) {
import java.util.function.Function;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanChannelContactConfig;
import org.openhab.binding.enocean.internal.eep.Base._RPSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class F6_10_01 extends _RPSMessage {
- public final byte Closed = 0x0F; // xxxx1111
- public final byte Open1 = 0x0E; // xxxx1110
- public final byte Open2 = 0x0C; // xxxx1100
- public final byte Tilted = 0x0D; // xxxx1101
+ public static final byte CLOSED = 0x0F; // xxxx1111
+ public static final byte OPEN_1 = 0x0E; // xxxx1110
+ public static final byte OPEN_2 = 0x0C; // xxxx1100
+ public static final byte TILTED = 0x0D; // xxxx1101
public F6_10_01() {
super();
@Override
protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
-
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
byte data = (byte) (bytes[0] & 0x0F);
// todo localization
switch (channelId) {
case CHANNEL_WINDOWHANDLESTATE:
- if (data == Closed) {
+ if (data == CLOSED) {
return new StringType("CLOSED");
- } else if (data == Tilted) {
+ } else if (data == TILTED) {
return new StringType("TILTED");
- } else if (data == Open1 || data == Open2) {
+ } else if (data == OPEN_1 || data == OPEN_2) {
return new StringType("OPEN");
}
case CHANNEL_CONTACT:
EnOceanChannelContactConfig c = config.as(EnOceanChannelContactConfig.class);
- if (data == Closed) {
+ if (data == CLOSED) {
return c.inverted ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
- } else if (data == Tilted) {
+ } else if (data == TILTED) {
return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
- } else if (data == Open1 || data == Open2) {
+ } else if (data == OPEN_1 || data == OPEN_2) {
return c.inverted ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
}
}
+++ /dev/null
-/**
- * Copyright (c) 2010-2023 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.enocean.internal.eep.Generic;
-
-import org.openhab.binding.enocean.internal.messages.ERP1Message;
-
-/**
- *
- * @author Daniel Weber - Initial contribution
- */
-public class Generic4BS extends GenericEEP {
-
- public Generic4BS() {
- super();
- }
-
- public Generic4BS(ERP1Message packet) {
- super(packet);
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2010-2023 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.enocean.internal.eep.Generic;
-
-import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
-import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.function.Function;
-
-import org.openhab.binding.enocean.internal.config.EnOceanChannelTransformationConfig;
-import org.openhab.binding.enocean.internal.eep.EEP;
-import org.openhab.binding.enocean.internal.messages.ERP1Message;
-import org.openhab.core.config.core.Configuration;
-import org.openhab.core.config.discovery.DiscoveryResultBuilder;
-import org.openhab.core.library.types.DateTimeType;
-import org.openhab.core.library.types.DecimalType;
-import org.openhab.core.library.types.HSBType;
-import org.openhab.core.library.types.OnOffType;
-import org.openhab.core.library.types.OpenClosedType;
-import org.openhab.core.library.types.PercentType;
-import org.openhab.core.library.types.PlayPauseType;
-import org.openhab.core.library.types.PointType;
-import org.openhab.core.library.types.RewindFastforwardType;
-import org.openhab.core.library.types.StringListType;
-import org.openhab.core.library.types.StringType;
-import org.openhab.core.library.types.UpDownType;
-import org.openhab.core.transform.actions.Transformation;
-import org.openhab.core.types.Command;
-import org.openhab.core.types.State;
-import org.openhab.core.types.UnDefType;
-import org.openhab.core.util.HexUtils;
-
-/**
- *
- * @author Daniel Weber - Initial contribution
- */
-public class GenericEEP extends EEP {
-
- final List<Class<? extends State>> supportedStates = Collections
- .unmodifiableList(new LinkedList<Class<? extends State>>() {
-
- private static final long serialVersionUID = 1L;
-
- {
- add(DateTimeType.class);
- add(DecimalType.class);
- add(HSBType.class);
- add(OnOffType.class);
- add(OpenClosedType.class);
- add(PercentType.class);
- add(PlayPauseType.class);
- add(PointType.class);
- add(RewindFastforwardType.class);
- add(StringListType.class);
- add(StringType.class);
- add(UpDownType.class);
- }
- });
-
- public GenericEEP() {
- super();
- }
-
- public GenericEEP(ERP1Message packet) {
- super(packet);
- }
-
- @Override
- protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
- Function<String, State> getCurrentStateFunc, Configuration config) {
- if (config != null) {
- EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class);
-
- String input = channelId + "|" + command.toString();
- String output = Transformation.transform(transformationInfo.transformationType,
- transformationInfo.transformationFunction, input);
-
- if (output != null && !output.isEmpty() && !input.equals(output)) {
- try {
- setData(HexUtils.hexToBytes(output));
- } catch (Exception e) {
- logger.debug("Command {} could not transformed", command.toString());
- }
- }
- }
- }
-
- @Override
- protected State convertToStateImpl(String channelId, String channelTypeId,
- Function<String, State> getCurrentStateFunc, Configuration config) {
- if (config != null) {
- EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class);
-
- String payload = HexUtils.bytesToHex(bytes);
- String input = channelId + "|" + payload;
- String output = Transformation.transform(transformationInfo.transformationType,
- transformationInfo.transformationFunction, input);
-
- if (output != null && !output.isEmpty() && !input.equals(output)) {
- String[] parts = output.split("\\|");
-
- if (parts.length == 2) {
- Class<? extends State> state = supportedStates.stream().filter(s -> s.getName().contains(parts[0]))
- .findFirst().orElse(null);
-
- if (state != null) {
- if (state.isEnum()) {
- for (State s : state.getEnumConstants()) {
- if (s.toString().equalsIgnoreCase(parts[1])) {
- return s;
- }
- }
- logger.debug("Could not find value '{}' for state '{}'", parts[1], parts[0]);
- } else {
- try {
- return state.getConstructor(String.class).newInstance(parts[1]);
- } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
- | InvocationTargetException | NoSuchMethodException | SecurityException e) {
- logger.debug("Could not create state '{}' with value '{}'", parts[0], parts[1]);
- }
- }
- } else {
- logger.debug("State '{}' not found", parts[0]);
- }
- } else {
- logger.debug("Transformation result malformed: {}", output);
- }
- }
- }
-
- return UnDefType.UNDEF;
- }
-
- @Override
- protected int getDataLength() {
- if (packet != null) {
- return packet.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH;
- } else {
- return bytes.length;
- }
- }
-
- @Override
- protected boolean validateData(byte[] bytes) {
- return true;
- }
-
- @Override
- public void addConfigPropertiesTo(DiscoveryResultBuilder discoveredThingResultBuilder) {
- discoveredThingResultBuilder.withProperty(PARAMETER_SENDINGEEPID, getEEPType().getId())
- .withProperty(PARAMETER_RECEIVINGEEPID, getEEPType().getId());
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2010-2023 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.enocean.internal.eep.Generic;
-
-import org.openhab.binding.enocean.internal.messages.ERP1Message;
-
-/**
- *
- * @author Daniel Weber - Initial contribution
- */
-public class GenericRPS extends GenericEEP {
-
- public GenericRPS() {
- super();
- }
-
- public GenericRPS(ERP1Message packet) {
- super(packet);
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2010-2023 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.enocean.internal.eep.Generic;
-
-import org.openhab.binding.enocean.internal.messages.ERP1Message;
-
-/**
- *
- * @author Daniel Weber - Initial contribution
- */
-public class GenericVLD extends GenericEEP {
-
- public GenericVLD() {
- super();
- }
-
- public GenericVLD(ERP1Message packet) {
- super(packet);
- }
-}
--- /dev/null
+/**
+ * Copyright (c) 2010-2023 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.enocean.internal.eep.generic;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.enocean.internal.messages.ERP1Message;
+
+/**
+ *
+ * @author Daniel Weber - Initial contribution
+ */
+@NonNullByDefault
+public class Generic4BS extends GenericEEP {
+
+ public Generic4BS() {
+ super();
+ }
+
+ public Generic4BS(ERP1Message packet) {
+ super(packet);
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2010-2023 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.enocean.internal.eep.generic;
+
+import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
+import static org.openhab.binding.enocean.internal.messages.ESP3Packet.*;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.function.Function;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.enocean.internal.config.EnOceanChannelTransformationConfig;
+import org.openhab.binding.enocean.internal.eep.EEP;
+import org.openhab.binding.enocean.internal.messages.ERP1Message;
+import org.openhab.core.config.core.Configuration;
+import org.openhab.core.config.discovery.DiscoveryResultBuilder;
+import org.openhab.core.library.types.DateTimeType;
+import org.openhab.core.library.types.DecimalType;
+import org.openhab.core.library.types.HSBType;
+import org.openhab.core.library.types.OnOffType;
+import org.openhab.core.library.types.OpenClosedType;
+import org.openhab.core.library.types.PercentType;
+import org.openhab.core.library.types.PlayPauseType;
+import org.openhab.core.library.types.PointType;
+import org.openhab.core.library.types.RewindFastforwardType;
+import org.openhab.core.library.types.StringListType;
+import org.openhab.core.library.types.StringType;
+import org.openhab.core.library.types.UpDownType;
+import org.openhab.core.transform.actions.Transformation;
+import org.openhab.core.types.Command;
+import org.openhab.core.types.State;
+import org.openhab.core.types.UnDefType;
+import org.openhab.core.util.HexUtils;
+
+/**
+ *
+ * @author Daniel Weber - Initial contribution
+ */
+@NonNullByDefault
+public class GenericEEP extends EEP {
+
+ final List<Class<? extends State>> supportedStates = Collections
+ .unmodifiableList(new LinkedList<Class<? extends State>>() {
+ private static final long serialVersionUID = 1L;
+
+ {
+ add(DateTimeType.class);
+ add(DecimalType.class);
+ add(HSBType.class);
+ add(OnOffType.class);
+ add(OpenClosedType.class);
+ add(PercentType.class);
+ add(PlayPauseType.class);
+ add(PointType.class);
+ add(RewindFastforwardType.class);
+ add(StringListType.class);
+ add(StringType.class);
+ add(UpDownType.class);
+ }
+ });
+
+ public GenericEEP() {
+ super();
+ }
+
+ public GenericEEP(ERP1Message packet) {
+ super(packet);
+ }
+
+ @Override
+ protected void convertFromCommandImpl(String channelId, String channelTypeId, Command command,
+ Function<String, State> getCurrentStateFunc, @Nullable Configuration config) {
+ if (config == null) {
+ logger.error("Cannot handle command {}, when transformation configuration is null", command.toString());
+ return;
+ }
+ EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class);
+
+ String input = channelId + "|" + command.toString();
+ String output = Transformation.transform(transformationInfo.transformationType,
+ transformationInfo.transformationFunction, input);
+
+ if (output != null && !output.isEmpty() && !input.equals(output)) {
+ try {
+ setData(HexUtils.hexToBytes(output));
+ } catch (IllegalArgumentException e) {
+ logger.debug("Command {} could not transformed", command.toString());
+ throw e;
+ }
+ }
+ }
+
+ @Override
+ protected State convertToStateImpl(String channelId, String channelTypeId,
+ Function<String, @Nullable State> getCurrentStateFunc, Configuration config) {
+ EnOceanChannelTransformationConfig transformationInfo = config.as(EnOceanChannelTransformationConfig.class);
+
+ String payload = HexUtils.bytesToHex(bytes);
+ String input = channelId + "|" + payload;
+ String output = Transformation.transform(transformationInfo.transformationType,
+ transformationInfo.transformationFunction, input);
+
+ if (output != null && !output.isEmpty() && !input.equals(output)) {
+ String[] parts = output.split("\\|");
+
+ if (parts.length == 2) {
+ @Nullable
+ Class<? extends State> state = supportedStates.stream().filter(s -> s.getName().contains(parts[0]))
+ .findFirst().orElse(null);
+
+ if (state != null) {
+ if (state.isEnum()) {
+ State[] states;
+ if ((states = state.getEnumConstants()) != null) {
+ for (State s : states) {
+ if (s.toString().equalsIgnoreCase(parts[1])) {
+ return s;
+ }
+ }
+ }
+ logger.debug("Could not find value '{}' for state '{}'", parts[1], parts[0]);
+ } else {
+ try {
+ return state.getConstructor(String.class).newInstance(parts[1]);
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | NoSuchMethodException | SecurityException e) {
+ logger.debug("Could not create state '{}' with value '{}'", parts[0], parts[1]);
+ }
+ }
+ } else {
+ logger.debug("State '{}' not found", parts[0]);
+ }
+ } else {
+ logger.debug("Transformation result malformed: {}", output);
+ }
+ }
+
+ return UnDefType.UNDEF;
+ }
+
+ @Override
+ protected int getDataLength() {
+ ERP1Message localPacket = packet;
+ if (localPacket != null) {
+ return localPacket.getPayload().length - ESP3_SENDERID_LENGTH - ESP3_RORG_LENGTH - ESP3_STATUS_LENGTH;
+ } else {
+ return bytes.length;
+ }
+ }
+
+ @Override
+ protected boolean validateData(byte[] bytes) {
+ return true;
+ }
+
+ @Override
+ public void addConfigPropertiesTo(DiscoveryResultBuilder discoveredThingResultBuilder) {
+ discoveredThingResultBuilder.withProperty(PARAMETER_SENDINGEEPID, getEEPType().getId())
+ .withProperty(PARAMETER_RECEIVINGEEPID, getEEPType().getId());
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2010-2023 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.enocean.internal.eep.generic;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.enocean.internal.messages.ERP1Message;
+
+/**
+ *
+ * @author Daniel Weber - Initial contribution
+ */
+@NonNullByDefault
+public class GenericRPS extends GenericEEP {
+
+ public GenericRPS() {
+ super();
+ }
+
+ public GenericRPS(ERP1Message packet) {
+ super(packet);
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2010-2023 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.enocean.internal.eep.generic;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.enocean.internal.messages.ERP1Message;
+
+/**
+ *
+ * @author Daniel Weber - Initial contribution
+ */
+@NonNullByDefault
+public class GenericVLD extends GenericEEP {
+
+ public GenericVLD() {
+ super();
+ }
+
+ public GenericVLD(ERP1Message packet) {
+ super(packet);
+ }
+}
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanActuatorConfig;
import org.openhab.binding.enocean.internal.eep.EEP;
import org.openhab.binding.enocean.internal.eep.EEPFactory;
* This class defines base functionality for sending eep messages. This class extends EnOceanBaseSensorHandler
* class as most actuator things send status or response messages, too.
*/
+@NonNullByDefault
public class EnOceanBaseActuatorHandler extends EnOceanBaseSensorHandler {
// List of thing types which support sending of eep messages
THING_TYPE_MEASUREMENTSWITCH, THING_TYPE_GENERICTHING, THING_TYPE_ROLLERSHUTTER, THING_TYPE_THERMOSTAT,
THING_TYPE_HEATRECOVERYVENTILATION);
- protected byte[] senderId; // base id of bridge + senderIdOffset, used for sending msg
- protected byte[] destinationId; // in case of broadcast FFFFFFFF otherwise the enocean id of the device
+ protected byte[] senderId = new byte[0]; // base id of bridge + senderIdOffset, used for sending msg
+ protected byte[] destinationId = new byte[0]; // in case of broadcast FFFFFFFF otherwise the enocean id of the
+ // device
- protected EEPType sendingEEPType = null;
+ protected @Nullable EEPType sendingEEPType = null;
- private ScheduledFuture<?> refreshJob; // used for polling current status of thing
+ private @Nullable ScheduledFuture<?> refreshJob; // used for polling current status of thing
public EnOceanBaseActuatorHandler(Thing thing, ItemChannelLinkRegistry itemChannelLinkRegistry) {
super(thing, itemChannelLinkRegistry);
* @param senderIdOffset to be validated
* @return true if senderIdOffset is between ]0;128[ and is not used yet
*/
- private boolean validateSenderIdOffset(Integer senderIdOffset) {
+ private boolean validateSenderIdOffset(@Nullable Integer senderIdOffset) {
if (senderIdOffset == null) {
return true;
}
}
@Override
+ @Nullable
Collection<EEPType> getEEPTypes() {
Collection<EEPType> r = super.getEEPTypes();
+
if (sendingEEPType == null) {
return r;
}
-
+ if (r == null) {
+ r = Collections.emptyList();
+ }
return Collections.unmodifiableCollection(Stream
.concat(r.stream(), Collections.singletonList(sendingEEPType).stream()).collect(Collectors.toList()));
}
@Override
boolean validateConfig() {
EnOceanActuatorConfig config = getConfiguration();
- if (config == null) {
- configurationErrorDescription = "Configuration is not valid";
- return false;
- }
- if (config.sendingEEPId == null || config.sendingEEPId.isEmpty()) {
+ if (config.sendingEEPId.isEmpty()) {
configurationErrorDescription = "Sending EEP must be provided";
return false;
}
+ EEPType localEEPType = null;
try {
- sendingEEPType = EEPType.getType(getConfiguration().sendingEEPId);
+ localEEPType = EEPType.getType(getConfiguration().sendingEEPId);
+ sendingEEPType = localEEPType;
} catch (IllegalArgumentException e) {
configurationErrorDescription = "Sending EEP is not supported";
return false;
if (super.validateConfig()) {
try {
- if (sendingEEPType.getSupportsRefresh()) {
+ if (localEEPType.getSupportsRefresh()) {
if (getConfiguration().pollingInterval > 0) {
refreshJob = scheduler.scheduleWithFixedDelay(() -> {
try {
// Generic things are treated as actuator things, however to support also generic sensors one can omit
// senderIdOffset
// TODO: seperate generic actuators from generic sensors?
- if ((getConfiguration().senderIdOffset == null
- && THING_TYPE_GENERICTHING.equals(this.getThing().getThingTypeUID()))) {
+ Integer senderOffset = getConfiguration().senderIdOffset;
+
+ if ((senderOffset == null && THING_TYPE_GENERICTHING.equals(this.getThing().getThingTypeUID()))) {
return true;
}
// if senderIdOffset is not set, the next free senderIdOffset is determined
- if (getConfiguration().senderIdOffset == null) {
+ if (senderOffset == null) {
Configuration updateConfig = editConfiguration();
- getConfiguration().senderIdOffset = bridgeHandler.getNextSenderId(thing);
- if (getConfiguration().senderIdOffset == null) {
+ senderOffset = bridgeHandler.getNextSenderId(thing);
+ getConfiguration().senderIdOffset = senderOffset;
+ if (senderOffset == null) {
configurationErrorDescription = "Could not get a free sender Id from Bridge";
return false;
}
- updateConfig.put(PARAMETER_SENDERIDOFFSET, getConfiguration().senderIdOffset);
+ updateConfig.put(PARAMETER_SENDERIDOFFSET, senderOffset);
updateConfiguration(updateConfig);
}
byte[] baseId = bridgeHandler.getBaseId();
- baseId[3] = (byte) ((baseId[3] + getConfiguration().senderIdOffset) & 0xFF);
+ baseId[3] = (byte) ((baseId[3] + senderOffset) & 0xFF);
this.senderId = baseId;
this.updateProperty(PROPERTY_SENDINGENOCEAN_ID, HexUtils.bytesToHex(this.senderId));
- bridgeHandler.addSender(getConfiguration().senderIdOffset, thing);
+ bridgeHandler.addSender(senderOffset, thing);
return true;
}
sendMessage(VIRTUALCHANNEL_SEND_COMMAND, VIRTUALCHANNEL_SEND_COMMAND, OnOffType.ON, null);
}
- protected void sendMessage(String channelId, String channelTypeId, Command command, Configuration channelConfig) {
- EEP eep = EEPFactory.createEEP(sendingEEPType);
+ protected void sendMessage(String channelId, String channelTypeId, Command command,
+ @Nullable Configuration channelConfig) {
+ EEPType sendType = sendingEEPType;
+ if (sendType == null) {
+ logger.warn("cannot send a message with an empty EEPType");
+ return;
+ }
+ EEP eep = EEPFactory.createEEP(sendType);
if (eep.convertFromCommand(channelId, channelTypeId, command, id -> getCurrentState(id), channelConfig)
.hasData()) {
BasePacket msg = eep.setSenderId(senderId).setDestinationId(destinationId)
.setSuppressRepeating(getConfiguration().suppressRepeating).getERP1Message();
-
- getBridgeHandler().sendMessage(msg, null);
+ if (msg == null) {
+ logger.warn("cannot send an empty message");
+ return;
+ }
+ EnOceanBridgeHandler handler = getBridgeHandler();
+ if (handler != null) {
+ handler.sendMessage(msg, null);
+ }
}
}
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
// We must have a valid sendingEEPType and sender id to send commands
- if (sendingEEPType == null || senderId == null) {
+ EEPType localsendingType = sendingEEPType;
+ if (localsendingType == null) {
return;
}
// check if we do support refreshs
if (command == RefreshType.REFRESH) {
- if (!sendingEEPType.getSupportsRefresh()) {
+ if (!localsendingType.getSupportsRefresh()) {
return;
}
@Override
public void handleRemoval() {
-
EnOceanBridgeHandler bridgeHandler = getBridgeHandler();
if (bridgeHandler != null) {
- if (getConfiguration().senderIdOffset != null && getConfiguration().senderIdOffset > 0) {
- bridgeHandler.removeSender(getConfiguration().senderIdOffset);
+ Integer senderOffset = getConfiguration().senderIdOffset;
+ if (senderOffset != null && senderOffset > 0) {
+ bridgeHandler.removeSender(senderOffset);
}
if (bridgeHandler.isSmackClient(this.thing)) {
@Override
public void dispose() {
- if (refreshJob != null && !refreshJob.isCancelled()) {
- refreshJob.cancel(true);
+ ScheduledFuture<?> localRefreshJob = refreshJob;
+ if (localRefreshJob != null && !localRefreshJob.isCancelled()) {
+ localRefreshJob.cancel(true);
refreshJob = null;
}
}
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanBaseConfig;
import org.openhab.binding.enocean.internal.eep.EEP;
import org.openhab.binding.enocean.internal.eep.EEPFactory;
* @author Daniel Weber - Initial contribution
* This class defines base functionality for receiving eep messages.
*/
+@NonNullByDefault
public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements PacketListener {
// List of all thing types which support receiving of eep messages
protected final Hashtable<RORG, EEPType> receivingEEPTypes = new Hashtable<>();
- protected ScheduledFuture<?> responseFuture = null;
+ protected @Nullable ScheduledFuture<?> responseFuture = null;
public EnOceanBaseSensorHandler(Thing thing, ItemChannelLinkRegistry itemChannelLinkRegistry) {
super(thing, itemChannelLinkRegistry);
}
@Override
+ @Nullable
Collection<EEPType> getEEPTypes() {
return Collections.unmodifiableCollection(receivingEEPTypes.values());
}
try {
config.receivingEEPId.forEach(receivingEEP -> {
EEPType receivingEEPType = EEPType.getType(receivingEEP);
- if (receivingEEPTypes.putIfAbsent(receivingEEPType.getRORG(), receivingEEPType) != null) {
+ EEPType existingKey = receivingEEPTypes.putIfAbsent(receivingEEPType.getRORG(), receivingEEPType);
+ if (existingKey != null) {
throw new IllegalArgumentException("Receiving more than one EEP of the same RORG is not supported");
}
});
receivingEEPTypes.put(EEPType.SigBatteryStatus.getRORG(), EEPType.SigBatteryStatus);
}
} catch (IllegalArgumentException e) {
- configurationErrorDescription = e.getMessage();
+ String eMessage = e.getMessage();
+ configurationErrorDescription = eMessage != null ? eMessage
+ : "IllegalArgumentException without a message was thrown";
return false;
}
}
if (!config.enoceanId.equals(EMPTYENOCEANID)) {
- getBridgeHandler().addPacketListener(this);
+ EnOceanBridgeHandler handler = getBridgeHandler();
+ if (handler != null) {
+ handler.addPacketListener(this);
+ }
}
return true;
@Override
public void handleRemoval() {
- if (getBridgeHandler() != null) {
- getBridgeHandler().removePacketListener(this);
+ EnOceanBridgeHandler handler = getBridgeHandler();
+ if (handler != null) {
+ handler.removePacketListener(this);
}
super.handleRemoval();
}
@Override
public void packetReceived(BasePacket packet) {
ERP1Message msg = (ERP1Message) packet;
- EEPType receivingEEPType = receivingEEPTypes.get(msg.getRORG());
- if (receivingEEPType == null) {
+
+ EEPType localReceivingType = receivingEEPTypes.get(msg.getRORG());
+ if (localReceivingType == null) {
return;
}
- EEP eep = EEPFactory.buildEEP(receivingEEPType, (ERP1Message) packet);
+ EEP eep = EEPFactory.buildEEP(localReceivingType, (ERP1Message) packet);
logger.debug("ESP Packet payload {} for {} received", HexUtils.bytesToHex(packet.getPayload()),
HexUtils.bytesToHex(msg.getSenderId()));
byte[] senderId = msg.getSenderId();
// try to interpret received message for all linked or trigger channels
- getThing().getChannels().stream().filter(channelFilter(receivingEEPType, senderId))
+ getThing().getChannels().stream().filter(channelFilter(localReceivingType, senderId))
.sorted(Comparator.comparing(Channel::getKind)) // handle state channels first
.forEachOrdered(channel -> {
this::getCurrentState);
// if message can be interpreted (result != UnDefType.UNDEF) => update item state
- if (result != null && result != UnDefType.UNDEF) {
+ if (result != UnDefType.UNDEF) {
updateState(channelId, result);
}
break;
case TRIGGER:
String lastEvent = lastEvents.get(channelId);
- String event = eep.convertToEvent(channelId, channelTypeId, lastEvent, channelConfig);
- if (event != null) {
- triggerChannel(channel.getUID(), event);
- lastEvents.put(channelId, event);
+ if (lastEvent != null) {
+ String event = eep.convertToEvent(channelId, channelTypeId, lastEvent,
+ channelConfig);
+ if (event != null) {
+ triggerChannel(channel.getUID(), event);
+ lastEvents.put(channelId, event);
+ }
}
break;
}
});
- if (receivingEEPType.getRequstesResponse()) {
+ if (localReceivingType.getRequstesResponse()) {
// fire trigger for receive
triggerChannel(prepareAnswer, "requestAnswer");
// Send response after 100ms
- if (responseFuture == null || responseFuture.isDone()) {
- responseFuture = scheduler.schedule(this::sendRequestResponse, 100, TimeUnit.MILLISECONDS);
+ ScheduledFuture<?> localResponseFuture = responseFuture;
+ if (localResponseFuture == null || localResponseFuture.isDone()) {
+ localResponseFuture = scheduler.schedule(this::sendRequestResponse, 100, TimeUnit.MILLISECONDS);
}
}
}
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanChannelDescription;
import org.openhab.binding.enocean.internal.config.EnOceanBaseConfig;
import org.openhab.binding.enocean.internal.eep.EEPType;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class EnOceanBaseThingHandler extends ConfigStatusThingHandler {
- private EnOceanBridgeHandler gateway = null;
+ private @Nullable EnOceanBridgeHandler gateway = null;
protected Logger logger = LoggerFactory.getLogger(EnOceanBaseThingHandler.class);
- protected String configurationErrorDescription;
+ protected String configurationErrorDescription = "";
// There is no data structure which holds the last triggered event, so we have to implement it by ourself
// This is especially needed for press and release events
protected Hashtable<String, String> lastEvents = new Hashtable<>();
- protected EnOceanBaseConfig config = null;
+ protected EnOceanBaseConfig config = new EnOceanBaseConfig();
private ItemChannelLinkRegistry itemChannelLinkRegistry;
- protected @NonNull ChannelUID prepareAnswer;
+ protected ChannelUID prepareAnswer;
public EnOceanBaseThingHandler(Thing thing, ItemChannelLinkRegistry itemChannelLinkRegistry) {
super(thing);
public void initialize() {
logger.debug("Initializing enocean base thing handler.");
this.gateway = null; // reset gateway in case we change the bridge
- this.config = null;
Bridge bridge = getBridge();
if (bridge == null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "A bridge is required");
private void initializeThing(ThingStatus bridgeStatus) {
logger.debug("initializeThing thing {} bridge status {}", getThing().getUID(), bridgeStatus);
- if (this.itemChannelLinkRegistry == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
- "ItemChannelLinkRegistry could not be found");
- } else {
- if (getBridgeHandler() != null) {
- if (bridgeStatus == ThingStatus.ONLINE) {
- initializeConfig();
- if (validateConfig()) {
- updateStatus(ThingStatus.ONLINE);
- } else {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
- configurationErrorDescription);
- }
+ if (getBridgeHandler() != null) {
+ if (bridgeStatus == ThingStatus.ONLINE) {
+ initializeConfig();
+ if (validateConfig()) {
+ updateStatus(ThingStatus.ONLINE);
} else {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ configurationErrorDescription);
}
} else {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "A bridge is required");
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
}
+ } else {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "A bridge is required");
}
}
- protected boolean validateEnoceanId(String id) {
+ protected boolean validateEnoceanId(@Nullable String id) {
if (id == null || id.isEmpty()) {
return false;
} else {
abstract boolean validateConfig();
- abstract Collection<EEPType> getEEPTypes();
+ abstract @Nullable Collection<EEPType> getEEPTypes();
protected void updateChannels() {
- @NonNull
- List<@NonNull Channel> channelList = new LinkedList<>(this.getThing().getChannels());
+ List<Channel> channelList = new LinkedList<>(this.getThing().getChannels());
Collection<EEPType> eeps = getEEPTypes();
if (eeps == null) {
return;
channelList.removeIf(channel -> !eeps.stream().anyMatch(eep -> eep.isChannelSupported(channel))));
// Next create supported channels of each selected eep
- eeps.stream().flatMap(eep -> eep.GetSupportedChannels().keySet().stream().map(id -> new SimpleEntry<>(id, eep)))
+ eeps.stream().flatMap(eep -> eep.getSupportedChannels().keySet().stream().map(id -> new SimpleEntry<>(id, eep)))
.forEach(entry -> {
String channelId = entry.getKey();
- EnOceanChannelDescription cd = entry.getValue().GetSupportedChannels().get(channelId);
+ EnOceanChannelDescription cd = entry.getValue().getSupportedChannels().get(channelId);
if (cd == null) {
return;
}
}
- protected State getCurrentState(Channel channel) {
+ protected State getCurrentState(@Nullable Channel channel) {
if (channel != null) {
Set<Item> items = itemChannelLinkRegistry.getLinkedItems(channel.getUID());
for (Item item : items) {
return getCurrentState(getThing().getChannel(channelId));
}
- protected synchronized EnOceanBridgeHandler getBridgeHandler() {
+ protected synchronized @Nullable EnOceanBridgeHandler getBridgeHandler() {
if (this.gateway == null) {
Bridge bridge = getBridge();
if (bridge == null) {
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanConfigStatusMessage;
import org.openhab.binding.enocean.internal.config.EnOceanBaseConfig;
import org.openhab.binding.enocean.internal.config.EnOceanBridgeConfig;
import org.openhab.binding.enocean.internal.messages.ESP3PacketFactory;
import org.openhab.binding.enocean.internal.messages.Response;
import org.openhab.binding.enocean.internal.messages.Response.ResponseType;
-import org.openhab.binding.enocean.internal.messages.Responses.BaseResponse;
-import org.openhab.binding.enocean.internal.messages.Responses.RDBaseIdResponse;
-import org.openhab.binding.enocean.internal.messages.Responses.RDLearnedClientsResponse;
-import org.openhab.binding.enocean.internal.messages.Responses.RDLearnedClientsResponse.LearnedClient;
-import org.openhab.binding.enocean.internal.messages.Responses.RDRepeaterResponse;
-import org.openhab.binding.enocean.internal.messages.Responses.RDVersionResponse;
+import org.openhab.binding.enocean.internal.messages.responses.BaseResponse;
+import org.openhab.binding.enocean.internal.messages.responses.RDBaseIdResponse;
+import org.openhab.binding.enocean.internal.messages.responses.RDLearnedClientsResponse;
+import org.openhab.binding.enocean.internal.messages.responses.RDLearnedClientsResponse.LearnedClient;
+import org.openhab.binding.enocean.internal.messages.responses.RDRepeaterResponse;
+import org.openhab.binding.enocean.internal.messages.responses.RDVersionResponse;
import org.openhab.binding.enocean.internal.transceiver.EnOceanESP2Transceiver;
import org.openhab.binding.enocean.internal.transceiver.EnOceanESP3Transceiver;
import org.openhab.binding.enocean.internal.transceiver.EnOceanTransceiver;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements TransceiverErrorListener {
private Logger logger = LoggerFactory.getLogger(EnOceanBridgeHandler.class);
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BRIDGE);
- private EnOceanTransceiver transceiver; // holds connection to serial/tcp port and sends/receives messages
- private ScheduledFuture<?> connectorTask; // is used for reconnection if something goes wrong
+ private @Nullable EnOceanTransceiver transceiver; // holds connection to serial/tcp port and sends/receives messages
+ private @Nullable ScheduledFuture<?> connectorTask; // is used for reconnection if something goes wrong
- private byte[] baseId = null;
+ private byte[] baseId = new byte[0];
private Thing[] sendingThings = new Thing[128];
private SerialPortManager serialPortManager;
@Override
public void initialize() {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "trying to connect to gateway...");
- if (this.serialPortManager == null) {
- updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
- "SerialPortManager could not be found");
- } else {
- if (connectorTask == null || connectorTask.isDone()) {
- connectorTask = scheduler.scheduleWithFixedDelay(new Runnable() {
- @Override
- public void run() {
- if (thing.getStatus() != ThingStatus.ONLINE) {
- initTransceiver();
- }
+
+ ScheduledFuture<?> localConnectorTask = connectorTask;
+ if (localConnectorTask == null || localConnectorTask.isDone()) {
+ localConnectorTask = scheduler.scheduleWithFixedDelay(new Runnable() {
+ @Override
+ public void run() {
+ if (thing.getStatus() != ThingStatus.ONLINE) {
+ initTransceiver();
}
- }, 0, 60, TimeUnit.SECONDS);
- }
+ }
+ }, 0, 60, TimeUnit.SECONDS);
}
}
private synchronized void initTransceiver() {
try {
EnOceanBridgeConfig c = getThing().getConfiguration().as(EnOceanBridgeConfig.class);
- if (transceiver != null) {
- transceiver.ShutDown();
+ EnOceanTransceiver localTransceiver = transceiver;
+ if (localTransceiver != null) {
+ localTransceiver.shutDown();
}
switch (c.getESPVersion()) {
break;
}
+ localTransceiver = transceiver;
+ if (localTransceiver == null) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+ "Failed to initialize EnOceanTransceiver");
+ return;
+ }
+
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "opening serial port...");
- transceiver.Initialize();
+ localTransceiver.initilize();
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "starting rx thread...");
- transceiver.StartReceiving(scheduler);
+ localTransceiver.startReceiving(scheduler);
logger.info("EnOceanSerialTransceiver RX thread up and running");
if (c.rs485) {
- if (c.rs485BaseId != null && !c.rs485BaseId.isEmpty()) {
+ if (!c.rs485BaseId.isEmpty()) {
baseId = HexUtils.hexToBytes(c.rs485BaseId);
if (baseId.length != 4) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"trying to get bridge base id...");
logger.debug("request base id");
- transceiver.sendBasePacket(ESP3PacketFactory.CO_RD_IDBASE,
+ localTransceiver.sendBasePacket(ESP3PacketFactory.CO_RD_IDBASE,
new ResponseListenerIgnoringTimeouts<RDBaseIdResponse>() {
+
@Override
public void responseReceived(RDBaseIdResponse response) {
logger.debug("received response for base id");
if (response.isValid() && response.isOK()) {
baseId = response.getBaseId().clone();
updateProperty(PROPERTY_BASE_ID, HexUtils.bytesToHex(response.getBaseId()));
- updateProperty(PROPERTY_REMAINING_WRITE_CYCLES_Base_ID,
+ updateProperty(PROPERTY_REMAINING_WRITE_CYCLES_BASE_ID,
Integer.toString(response.getRemainingWriteCycles()));
- transceiver.setFilteredDeviceId(baseId);
-
+ EnOceanTransceiver localTransceiver = transceiver;
+ if (localTransceiver != null) {
+ localTransceiver.setFilteredDeviceId(baseId);
+ }
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
if (c.getESPVersion() == ESPVersion.ESP3) {
logger.debug("set postmaster mailboxes");
- transceiver.sendBasePacket(ESP3PacketFactory.SA_WR_POSTMASTER((byte) (c.enableSmack ? 20 : 0)),
+ localTransceiver.sendBasePacket(ESP3PacketFactory.SA_WR_POSTMASTER((byte) (c.enableSmack ? 20 : 0)),
new ResponseListenerIgnoringTimeouts<BaseResponse>() {
@Override
public void responseReceived(BaseResponse response) {
-
logger.debug("received response for postmaster mailboxes");
if (response.isOK()) {
updateProperty("Postmaster mailboxes:",
}
logger.debug("request version info");
- transceiver.sendBasePacket(ESP3PacketFactory.CO_RD_VERSION,
+ localTransceiver.sendBasePacket(ESP3PacketFactory.CO_RD_VERSION,
new ResponseListenerIgnoringTimeouts<RDVersionResponse>() {
+
@Override
public void responseReceived(RDVersionResponse response) {
if (response.isValid() && response.isOK()) {
@Override
public synchronized void dispose() {
- if (transceiver != null) {
- transceiver.ShutDown();
+ EnOceanTransceiver localTransceiver = transceiver;
+ if (localTransceiver != null) {
+ localTransceiver.shutDown();
transceiver = null;
}
- if (connectorTask != null && !connectorTask.isDone()) {
- connectorTask.cancel(true);
+ ScheduledFuture<?> localConnectorTask = connectorTask;
+ if (localConnectorTask != null && !localConnectorTask.isDone()) {
+ localConnectorTask.cancel(true);
connectorTask = null;
}
// The serial port must be provided
String path = getThing().getConfiguration().as(EnOceanBridgeConfig.class).path;
- if (path == null || path.isEmpty()) {
- configStatusMessages.add(ConfigStatusMessage.Builder.error(PATH)
+ if (path.isEmpty()) {
+ ConfigStatusMessage statusMessage = ConfigStatusMessage.Builder.error(PATH)
.withMessageKeySuffix(EnOceanConfigStatusMessage.PORT_MISSING.getMessageKey()).withArguments(PATH)
- .build());
+ .build();
+ if (statusMessage != null) {
+ configStatusMessages.add(statusMessage);
+ }
}
return configStatusMessages;
return smackClients.contains(sender.getConfiguration().as(EnOceanBaseConfig.class).enoceanId);
}
- public Integer getNextSenderId(Thing sender) {
+ public @Nullable Integer getNextSenderId(Thing sender) {
return getNextSenderId(sender.getConfiguration().as(EnOceanBaseConfig.class).enoceanId);
}
- public Integer getNextSenderId(String enoceanId) {
+ public @Nullable Integer getNextSenderId(String enoceanId) {
EnOceanBridgeConfig config = getConfigAs(EnOceanBridgeConfig.class);
-
- if (config.nextSenderId != null && sendingThings[config.nextSenderId] == null) {
+ Integer senderId = config.nextSenderId;
+ if (senderId == null) {
+ return null;
+ }
+ if (sendingThings[senderId] == null) {
Configuration c = this.editConfiguration();
c.put(PARAMETER_NEXT_SENDERID, null);
updateConfiguration(c);
- return config.nextSenderId;
+ return senderId;
}
for (int i = 1; i < sendingThings.length; i++) {
sendingThings[id] = null;
}
- public <T extends Response> void sendMessage(BasePacket message, ResponseListener<T> responseListener) {
+ public <T extends @Nullable Response> void sendMessage(BasePacket message,
+ @Nullable ResponseListener<T> responseListener) {
try {
- transceiver.sendBasePacket(message, responseListener);
+ EnOceanTransceiver localTransceiver = transceiver;
+ if (localTransceiver == null) {
+ throw new IOException("EnOceanTransceiver has state null");
+ }
+ localTransceiver.sendBasePacket(message, responseListener);
} catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
}
public void addPacketListener(PacketListener listener, long senderIdToListenTo) {
- if (transceiver != null) {
- transceiver.addPacketListener(listener, senderIdToListenTo);
+ EnOceanTransceiver localTransceiver = transceiver;
+ if (localTransceiver != null) {
+ localTransceiver.addPacketListener(listener, senderIdToListenTo);
}
}
}
public void removePacketListener(PacketListener listener, long senderIdToListenTo) {
- if (transceiver != null) {
- transceiver.removePacketListener(listener, senderIdToListenTo);
+ EnOceanTransceiver localTransceiver = transceiver;
+ if (localTransceiver != null) {
+ localTransceiver.removePacketListener(listener, senderIdToListenTo);
}
}
public void startDiscovery(TeachInListener teachInListener) {
- transceiver.startDiscovery(teachInListener);
+ EnOceanTransceiver localTransceiver = transceiver;
+ if (localTransceiver != null) {
+ localTransceiver.startDiscovery(teachInListener);
+ }
if (smackAvailable) {
// activate smack teach in
logger.debug("activate smack teach in");
try {
- transceiver.sendBasePacket(ESP3PacketFactory.SA_WR_LEARNMODE(true),
+ if (localTransceiver == null) {
+ throw new IOException("EnOceanTransceiver has state null");
+ }
+ localTransceiver.sendBasePacket(ESP3PacketFactory.SA_WR_LEARNMODE(true),
new ResponseListenerIgnoringTimeouts<BaseResponse>() {
-
@Override
public void responseReceived(BaseResponse response) {
-
if (response.isOK()) {
logger.debug("Smack teach in activated");
}
}
public void stopDiscovery() {
- transceiver.stopDiscovery();
+ EnOceanTransceiver localTransceiver = transceiver;
+ if (localTransceiver != null) {
+ localTransceiver.stopDiscovery();
+ }
try {
- transceiver.sendBasePacket(ESP3PacketFactory.SA_WR_LEARNMODE(false), null);
+ if (localTransceiver == null) {
+ throw new IOException("EnOceanTransceiver has state null");
+ }
+ localTransceiver.sendBasePacket(ESP3PacketFactory.SA_WR_LEARNMODE(false), null);
refreshProperties();
} catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
private void refreshProperties() {
if (getThing().getStatus() == ThingStatus.ONLINE && smackAvailable) {
-
logger.debug("request learned smack clients");
try {
- transceiver.sendBasePacket(ESP3PacketFactory.SA_RD_LEARNEDCLIENTS,
- new ResponseListenerIgnoringTimeouts<RDLearnedClientsResponse>() {
-
- @Override
- public void responseReceived(RDLearnedClientsResponse response) {
-
- logger.debug("received response for learned smack clients");
- if (response.isValid() && response.isOK()) {
- LearnedClient[] clients = response.getLearnedClients();
- updateProperty("Learned smart ack clients", Integer.toString(clients.length));
- updateProperty("Smart ack clients",
- Arrays.stream(clients)
- .map(x -> String.format("%s (MB Idx: %d)",
- HexUtils.bytesToHex(x.clientId), x.mailboxIndex))
- .collect(Collectors.joining(", ")));
- smackClients = Arrays.stream(clients).map(x -> HexUtils.bytesToHex(x.clientId))
- .collect(Collectors.toSet());
+ EnOceanTransceiver localTransceiver = transceiver;
+ if (localTransceiver != null) {
+ localTransceiver.sendBasePacket(ESP3PacketFactory.SA_RD_LEARNEDCLIENTS,
+ new ResponseListenerIgnoringTimeouts<RDLearnedClientsResponse>() {
+ @Override
+ public void responseReceived(RDLearnedClientsResponse response) {
+ logger.debug("received response for learned smack clients");
+ if (response.isValid() && response.isOK()) {
+ LearnedClient[] clients = response.getLearnedClients();
+ updateProperty("Learned smart ack clients", Integer.toString(clients.length));
+ updateProperty("Smart ack clients",
+ Arrays.stream(clients)
+ .map(x -> String.format("%s (MB Idx: %d)",
+ HexUtils.bytesToHex(x.clientId), x.mailboxIndex))
+ .collect(Collectors.joining(", ")));
+ smackClients = Arrays.stream(clients).map(x -> HexUtils.bytesToHex(x.clientId))
+ .collect(Collectors.toSet());
+ }
}
- }
- });
+ });
+ }
} catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Smack packet could not be send: " + e.getMessage());
-
}
}
}
@Override
- public void ErrorOccured(Throwable exception) {
- transceiver.ShutDown();
- transceiver = null;
+ public void errorOccured(Throwable exception) {
+ EnOceanTransceiver localTransceiver = transceiver;
+ if (localTransceiver != null) {
+ localTransceiver.shutDown();
+ transceiver = null;
+ }
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, exception.getMessage());
}
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.config.EnOceanActuatorConfig;
import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchConfigBase.SwitchMode;
import org.openhab.binding.enocean.internal.config.EnOceanChannelRockerSwitchListenerConfig;
* This class defines base functionality for sending eep messages. This class extends EnOceanBaseSensorHandler
* class as most actuator things send status or response messages, too.
*/
+@NonNullByDefault
public class EnOceanClassicDeviceHandler extends EnOceanBaseActuatorHandler {
// List of thing types which support sending of eep messages
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_CLASSICDEVICE);
private StringType lastTriggerEvent = StringType.valueOf(CommonTriggerEvents.DIR1_PRESSED);
+ @Nullable
ScheduledFuture<?> releaseFuture = null;
public EnOceanClassicDeviceHandler(Thing thing, ItemChannelLinkRegistry itemChannelLinkRegistry) {
}
@Override
- public void channelLinked(@NonNull ChannelUID channelUID) {
+ public void channelLinked(ChannelUID channelUID) {
super.channelLinked(channelUID);
// if linked channel is a listening channel => put listener
// it seems that there does not exist a channel update callback
// => remove all listeners and add them again
- getBridgeHandler().removePacketListener(this);
+ EnOceanBridgeHandler handler = getBridgeHandler();
+ if (handler != null) {
+ handler.removePacketListener(this);
+ }
this.getThing().getChannels().forEach(c -> {
if (isLinked(c.getUID()) && !addListener(c)) {
}
@Override
- public void channelUnlinked(@NonNull ChannelUID channelUID) {
+ public void channelUnlinked(ChannelUID channelUID) {
super.channelUnlinked(channelUID);
// if unlinked channel is listening channel => remove listener
removeListener(channel);
}
- protected boolean addListener(Channel channel) {
+ protected boolean addListener(@Nullable Channel channel) {
if (channel == null) {
return true;
}
EnOceanChannelRockerSwitchListenerConfig config = channel.getConfiguration()
.as(EnOceanChannelRockerSwitchListenerConfig.class);
try {
- getBridgeHandler().addPacketListener(this, Long.parseLong(config.enoceanId, 16));
+ @Nullable
+ EnOceanBridgeHandler handler = getBridgeHandler();
+ if (handler != null) {
+ handler.addPacketListener(this, Long.parseLong(config.enoceanId, 16));
+ }
return true;
} catch (NumberFormatException e) {
}
return true;
}
- protected void removeListener(Channel channel) {
+ protected void removeListener(@Nullable Channel channel) {
if (channel == null) {
return;
}
EnOceanChannelRockerSwitchListenerConfig config = channel.getConfiguration()
.as(EnOceanChannelRockerSwitchListenerConfig.class);
try {
- getBridgeHandler().removePacketListener(this, Long.parseLong(config.enoceanId, 16));
+ EnOceanBridgeHandler handler = getBridgeHandler();
+ if (handler != null) {
+ handler.removePacketListener(this, Long.parseLong(config.enoceanId, 16));
+ }
} catch (NumberFormatException e) {
}
}
: StringType.valueOf(CommonTriggerEvents.DIR2_RELEASED);
}
- private StringType convertToPressedCommand(Command command, SwitchMode switchMode) {
+ private @Nullable StringType convertToPressedCommand(Command command, SwitchMode switchMode) {
if (command instanceof StringType) {
return (StringType) command;
} else if (command instanceof OnOffType) {
}
@Override
- public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
+ public void handleCommand(ChannelUID channelUID, Command command) {
// We must have a valid sendingEEPType and sender id to send commands
- if (sendingEEPType == null || senderId == null || command == RefreshType.REFRESH) {
+ if (sendingEEPType == null || senderId.length == 0 || command == RefreshType.REFRESH) {
return;
}
if (result != null) {
lastTriggerEvent = result;
-
- EEP eep = EEPFactory.createEEP(sendingEEPType);
- if (eep.setSenderId(senderId).setDestinationId(destinationId).convertFromCommand(channelId, channelTypeId,
- result, id -> this.getCurrentState(id), channel.getConfiguration()).hasData()) {
- BasePacket press = eep.setSuppressRepeating(getConfiguration().suppressRepeating).getERP1Message();
-
- getBridgeHandler().sendMessage(press, null);
-
- if (channelConfig.duration > 0) {
- releaseFuture = scheduler.schedule(() -> {
- if (eep.convertFromCommand(channelId, channelTypeId, convertToReleasedCommand(lastTriggerEvent),
- id -> this.getCurrentState(id), channel.getConfiguration()).hasData()) {
- BasePacket release = eep.getERP1Message();
- getBridgeHandler().sendMessage(release, null);
+ EEPType localSendType = sendingEEPType;
+ if (localSendType != null) {
+ EEP eep = EEPFactory.createEEP(localSendType);
+ if (eep.setSenderId(senderId).setDestinationId(destinationId).convertFromCommand(channelId,
+ channelTypeId, result, id -> this.getCurrentState(id), channel.getConfiguration()).hasData()) {
+ BasePacket press = eep.setSuppressRepeating(getConfiguration().suppressRepeating).getERP1Message();
+ if (press != null) {
+ EnOceanBridgeHandler handler = getBridgeHandler();
+ if (handler != null) {
+ handler.sendMessage(press, null);
}
- }, channelConfig.duration, TimeUnit.MILLISECONDS);
+ }
+
+ if (channelConfig.duration > 0) {
+ releaseFuture = scheduler.schedule(() -> {
+ if (eep.convertFromCommand(channelId, channelTypeId,
+ convertToReleasedCommand(lastTriggerEvent), id -> this.getCurrentState(id),
+ channel.getConfiguration()).hasData()) {
+ BasePacket release = eep.getERP1Message();
+ if (release != null) {
+ EnOceanBridgeHandler handler = getBridgeHandler();
+ if (handler != null) {
+ handler.sendMessage(release, null);
+ }
+ }
+ }
+ }, channelConfig.duration, TimeUnit.MILLISECONDS);
+ }
}
}
}
@Override
public void handleRemoval() {
- if (releaseFuture != null && !releaseFuture.isDone()) {
- releaseFuture.cancel(true);
+ ScheduledFuture<?> future = releaseFuture;
+ if (future != null && !future.isDone()) {
+ future.cancel(true);
+ future = null;
}
releaseFuture = null;
import java.security.InvalidParameterException;
import java.util.Arrays;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class BasePacket {
public enum ESPPacketType {
protected ESPPacketType packetType;
protected byte[] data;
- protected byte[] optionalData;
+ protected byte[] optionalData = new byte[0];
public BasePacket(int dataLength, int optionalDataLength, ESPPacketType packetType, byte[] payload) {
this(dataLength, optionalDataLength, packetType.value, payload);
*/
package org.openhab.binding.enocean.internal.messages;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
class CCMessage extends BasePacket {
public enum CCMessageType {
import java.security.InvalidParameterException;
import java.util.Arrays;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.eep.Base.UTEResponse;
import org.openhab.binding.enocean.internal.eep.Base._1BSMessage;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class ERP1Message extends BasePacket {
// these are just ESP3 RORGs, ESP2 ORGs are converted by ESP2PacketConverter
case _1BS:
if (dataLength >= 6) {
senderId = Arrays.copyOfRange(payload, 2, 6);
- teachIn = ((_1BSMessage.TeachInBit & payload[1]) == 0);
+ teachIn = ((_1BSMessage.TEACHIN_BIT & payload[1]) == 0);
}
break;
case _4BS:
if (dataLength >= 9) {
senderId = Arrays.copyOfRange(payload, 5, 9);
- teachIn = (_4BSMessage.TeachInBit & payload[4]) == 0;
+ teachIn = (_4BSMessage.TEACHIN_BIT & payload[4]) == 0;
}
break;
case VLD:
break;
case UTE:
if (dataLength >= 6) {
- teachIn = (payload[1] & UTEResponse.TeachIn_MASK) == 0
- || (payload[1] & UTEResponse.TeachIn_MASK) == UTEResponse.TeachIn_NotSpecified;
+ teachIn = (payload[1] & UTEResponse.TEACHIN_MASK) == 0
+ || (payload[1] & UTEResponse.TEACHIN_MASK) == UTEResponse.TEACHIN_NPTSPECIFIED;
senderId = Arrays.copyOfRange(payload, dataLength - 5, dataLength - 1);
}
break;
import java.security.InvalidParameterException;
import java.util.Arrays;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.EnOceanException;
import org.openhab.binding.enocean.internal.messages.BasePacket.ESPPacketType;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class ESP2Packet {
public static final byte ENOCEAN_ESP2_FIRSTSYNC_BYTE = (byte) 0xA5;
import java.nio.charset.Charset;
import java.util.Arrays;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.messages.BasePacket.ESPPacketType;
import org.openhab.binding.enocean.internal.messages.ERP1Message.RORG;
import org.openhab.binding.enocean.internal.messages.ESP2Packet.ESP2PacketType;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class ESP2PacketConverter {
protected static Logger logger = LoggerFactory.getLogger(ESP2PacketConverter.class);
private static final int ESP3PACKET_BASE_LENGTH = ESP3Packet.ESP3_RORG_LENGTH + ESP3Packet.ESP3_SENDERID_LENGTH
+ ESP3Packet.ESP3_STATUS_LENGTH;
- private static BasePacket handleRadioTelegram(int dataLength, byte packetType, byte[] payload) {
+ private static @Nullable BasePacket handleRadioTelegram(int dataLength, byte packetType, byte[] payload) {
switch (ESP2Packet.ORG.getORG(payload[1])) {
case _RPS:
- return ESP3PacketFactory.BuildPacket(ESP3PACKET_BASE_LENGTH + RORG.RPS.getDataLength(), 0,
+ return ESP3PacketFactory.buildPacket(ESP3PACKET_BASE_LENGTH + RORG.RPS.getDataLength(), 0,
ESPPacketType.RADIO_ERP1.getValue(), new byte[] { RORG.RPS.getValue(), payload[2], payload[6],
payload[7], payload[8], payload[9], payload[10] });
case _1BS:
- return ESP3PacketFactory.BuildPacket(ESP3PACKET_BASE_LENGTH + RORG._1BS.getDataLength(), 0,
+ return ESP3PacketFactory.buildPacket(ESP3PACKET_BASE_LENGTH + RORG._1BS.getDataLength(), 0,
ESPPacketType.RADIO_ERP1.getValue(), new byte[] { RORG._1BS.getValue(), payload[2], payload[6],
payload[7], payload[8], payload[9], payload[10] });
case _4BS:
- return ESP3PacketFactory.BuildPacket(ESP3PACKET_BASE_LENGTH + RORG._4BS.getDataLength(), 0,
+ return ESP3PacketFactory.buildPacket(ESP3PACKET_BASE_LENGTH + RORG._4BS.getDataLength(), 0,
ESPPacketType.RADIO_ERP1.getValue(), new byte[] { RORG._4BS.getValue(), payload[2], payload[3],
payload[4], payload[5], payload[6], payload[7], payload[8], payload[9], payload[10] });
default:
}
}
- private static BasePacket handleMessageTelegram(int dataLength, byte packetType, byte[] payload) {
+ private static @Nullable BasePacket handleMessageTelegram(int dataLength, byte packetType, byte[] payload) {
switch (ESP2Packet.ESP2Response.getResponse(payload[1])) {
case OK:
- return ESP3PacketFactory.BuildPacket(1, 0, ESPPacketType.RESPONSE.getValue(),
+ return ESP3PacketFactory.buildPacket(1, 0, ESPPacketType.RESPONSE.getValue(),
new byte[] { ResponseType.RET_OK.getValue() });
case ERR:
- return ESP3PacketFactory.BuildPacket(1, 0, ESPPacketType.RESPONSE.getValue(),
+ return ESP3PacketFactory.buildPacket(1, 0, ESPPacketType.RESPONSE.getValue(),
new byte[] { ResponseType.RET_ERROR.getValue() });
case INF_SW_VERSION: {
byte[] data = new byte[33];
byte[] description = "TCM 210".getBytes(Charset.forName("ASCII"));
System.arraycopy(description, 0, data, 17, description.length);
- return ESP3PacketFactory.BuildPacket(data.length, 0, ESPPacketType.RESPONSE.getValue(), data);
+ return ESP3PacketFactory.buildPacket(data.length, 0, ESPPacketType.RESPONSE.getValue(), data);
}
case UNKOWN: // try to interpret it as a radio telegram
return handleRadioTelegram(dataLength, packetType, payload);
}
}
- public static BasePacket BuildPacket(int dataLength, byte packetType, byte[] payload) {
+ public static @Nullable BasePacket buildPacket(int dataLength, byte packetType, byte[] payload) {
ESP2PacketType type = ESP2PacketType.getPacketType(packetType);
switch (type) {
*/
package org.openhab.binding.enocean.internal.messages;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.EnOceanException;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class ESP3Packet {
- private static byte[] crc8_table = new byte[] { (byte) 0x00, (byte) 0x07, (byte) 0x0e, (byte) 0x09, (byte) 0x1c,
+ private static byte[] crc8Table = new byte[] { (byte) 0x00, (byte) 0x07, (byte) 0x0e, (byte) 0x09, (byte) 0x1c,
(byte) 0x1b, (byte) 0x12, (byte) 0x15, (byte) 0x38, (byte) 0x3f, (byte) 0x36, (byte) 0x31, (byte) 0x24,
(byte) 0x23, (byte) 0x2a, (byte) 0x2d, (byte) 0x70, (byte) 0x77, (byte) 0x7e, (byte) 0x79, (byte) 0x6c,
(byte) 0x6b, (byte) 0x62, (byte) 0x65, (byte) 0x48, (byte) 0x4f, (byte) 0x46, (byte) 0x41, (byte) 0x54,
byte output = 0;
for (int i = offset; i < offset + length; i++) {
int index = (output ^ data[i]) & 0xff;
- output = crc8_table[index];
+ output = crc8Table[index];
}
return (byte) (output & 0xff);
}
byte[] payload = basePacket.getPayload();
byte[] optionalPayload = basePacket.getOptionalPayload();
- int optionalLength = optionalPayload != null ? optionalPayload.length : 0;
-
byte[] result = new byte[ESP3_SYNC_BYTE_LENGTH + ESP3_HEADER_LENGTH + ESP3_CRC3_HEADER_LENGTH
- + payload.length + optionalLength + ESP3_CRC8_DATA_LENGTH];
+ + payload.length + optionalPayload.length + ESP3_CRC8_DATA_LENGTH];
result[0] = ESP3_SYNC_BYTE;
result[1] = (byte) ((payload.length >> 8) & 0xff);
result[2] = (byte) (payload.length & 0xff);
- result[3] = (byte) (optionalLength & 0xff);
+ result[3] = (byte) (optionalPayload.length & 0xff);
result[4] = basePacket.getPacketType().getValue();
result[5] = calcCRC8(result, ESP3_SYNC_BYTE_LENGTH, ESP3_HEADER_LENGTH);
- for (int i = 0; i < payload.length; i++) {
- result[6 + i] = payload[i];
- }
- if (optionalPayload != null) {
- for (int i = 0; i < optionalPayload.length; i++) {
- result[6 + payload.length + i] = (byte) (optionalPayload[i] & 0xff);
- }
+
+ System.arraycopy(payload, 0, result, 6, payload.length);
+
+ for (int i = 0; i < optionalPayload.length; i++) {
+ result[6 + payload.length + i] = (byte) (optionalPayload[i] & 0xff);
}
- result[6 + payload.length + optionalLength] = calcCRC8(result, 6, payload.length + optionalLength);
+
+ result[6 + payload.length + optionalPayload.length] = calcCRC8(result, 6,
+ payload.length + optionalPayload.length);
return result;
} catch (Exception e) {
byte output = 0;
for (int i = 0; i < length; i++) {
int index = (output ^ data[i]) & 0xff;
- output = crc8_table[index];
+ output = crc8Table[index];
}
return output == crc8;
}
*/
package org.openhab.binding.enocean.internal.messages;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanBindingConstants;
import org.openhab.binding.enocean.internal.Helper;
import org.openhab.binding.enocean.internal.messages.BasePacket.ESPPacketType;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class ESP3PacketFactory {
public static final BasePacket CO_RD_VERSION = new CCMessage(CCMessageType.CO_RD_VERSION);
new byte[] { SAMessageType.SA_WR_CLIENTLEARNRQ.getValue(), manu1, manu2, rorg, func, type });
}
- public static BasePacket BuildPacket(int dataLength, int optionalDataLength, byte packetType, byte[] payload) {
+ public static @Nullable BasePacket buildPacket(int dataLength, int optionalDataLength, byte packetType,
+ byte[] payload) {
ESPPacketType type = ESPPacketType.getPacketType(packetType);
switch (type) {
import java.util.stream.Stream;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EventMessage extends BasePacket {
public enum EventMessageType {
import java.security.InvalidParameterException;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class Response extends BasePacket {
public enum ResponseType {
}
protected ResponseType responseType;
- protected boolean _isValid = false;
+ protected boolean isValid = false;
public Response(int dataLength, int optionalDataLength, byte[] payload) {
super(dataLength, optionalDataLength, ESPPacketType.RESPONSE, payload);
}
public boolean isValid() {
- return _isValid;
+ return isValid;
}
}
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.enocean.internal.messages.Responses;
+package org.openhab.binding.enocean.internal.messages.responses;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.Helper;
import org.openhab.binding.enocean.internal.messages.Response;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class BaseResponse extends Response {
public BaseResponse(Response response) {
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.enocean.internal.messages.Responses;
+package org.openhab.binding.enocean.internal.messages.responses;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.Helper;
import org.openhab.binding.enocean.internal.messages.Response;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class RDBaseIdResponse extends Response {
- private byte[] baseId = null;
+ private byte[] baseId = new byte[0];
private int remainingWriteCycles = 0;
public RDBaseIdResponse(Response response) {
RDBaseIdResponse(int dataLength, int optionalDataLength, byte[] payload) {
super(dataLength, optionalDataLength, payload);
- if (this.data == null || this.data.length != 5 || this.optionalData == null || this.optionalData.length != 1) {
+ if (this.data.length != 5 || this.optionalData.length != 1) {
return;
}
baseId = getPayload(1, 4);
remainingWriteCycles = optionalData[0] & 0xFF;
- _isValid = true;
+ isValid = true;
}
public final byte[] getBaseId() {
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.enocean.internal.messages.Responses;
+package org.openhab.binding.enocean.internal.messages.responses;
import java.util.Arrays;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.Helper;
import org.openhab.binding.enocean.internal.messages.Response;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class RDLearnedClientsResponse extends Response {
public class LearnedClient {
- public byte[] clientId;
- public byte[] controllerId;
+ public byte[] clientId = new byte[0];
+ public byte[] controllerId = new byte[0];
public int mailboxIndex;
}
- LearnedClient[] learnedClients;
+ LearnedClient[] learnedClients = new LearnedClient[0];
public RDLearnedClientsResponse(Response response) {
this(response.getPayload().length, response.getOptionalPayload().length,
RDLearnedClientsResponse(int dataLength, int optionalDataLength, byte[] payload) {
super(dataLength, optionalDataLength, payload);
- if (payload == null || ((payload.length - 1) % 9) != 0) {
+ if (payload.length == 0 || (payload.length - 1) % 9 != 0) {
return;
} else {
- _isValid = true;
+ isValid = true;
}
learnedClients = new LearnedClient[(payload.length - 1) / 9];
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.enocean.internal.messages.Responses;
+package org.openhab.binding.enocean.internal.messages.responses;
import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.Response;
import org.openhab.core.library.types.StringType;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class RDRepeaterResponse extends Response {
- protected String repeaterLevel;
+ protected String repeaterLevel = "";
public RDRepeaterResponse(Response response) {
this(response.getPayload().length, 0, response.getPayload());
RDRepeaterResponse(int dataLength, int optionalDataLength, byte[] payload) {
super(dataLength, optionalDataLength, payload);
- if (payload == null || payload.length < 3) {
+ if (payload.length < 3) {
return;
}
return;
}
- _isValid = true;
+ isValid = true;
}
}
- @NonNull
public StringType getRepeaterLevel() {
return StringType.valueOf(repeaterLevel);
}
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.enocean.internal.messages.Responses;
+package org.openhab.binding.enocean.internal.messages.responses;
import java.util.Arrays;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.Response;
import org.openhab.core.util.HexUtils;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class RDVersionResponse extends Response {
protected String appVersion = "";
sb.append((char) (payload[i] & 0xff));
}
description = sb.toString();
- _isValid = true;
+ isValid = true;
} catch (Exception e) {
responseType = ResponseType.RET_ERROR;
}
}
- @NonNull
public String getAPPVersion() {
return appVersion;
}
- @NonNull
public String getAPIVersion() {
return apiVersion;
}
- @NonNull
public String getChipID() {
return chipId;
}
- @NonNull
public String getDescription() {
return description;
}
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.openhab.binding.enocean.internal.messages.Responses;
+package org.openhab.binding.enocean.internal.messages.responses;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.Response;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class SMACKTeachInResponse extends Response {
// set response time to 250ms
*/
package org.openhab.binding.enocean.internal.messages;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class SAMessage extends BasePacket {
public enum SAMessageType {
@Override
public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(ChannelType channelType, @Nullable String itemType) {
-
if (CHANNELTYPE_ROCKERSWITCH_ACTION_UID.equals(channelType.getUID())) {
if (CoreItemFactory.PLAYER.equalsIgnoreCase(itemType)) {
return ROCKERSWITCHACTION_TOGGLE_PLAYER;
protected @Nullable State previousState;
- final String ANYDIR = "*";
+ protected static final String ANY_DIR = "*";
public RockerSwitchActionBaseProfile(ProfileCallback callback, ProfileContext context) {
this.callback = callback;
EnOceanProfileRockerSwitchActionConfig config = context.getConfiguration()
.as(EnOceanProfileRockerSwitchActionConfig.class);
- if (!(config.channelAFilter.equals(ANYDIR) || config.channelAFilter.equals(directions[0]))) {
+ if (!(config.channelAFilter.equals(ANY_DIR) || config.channelAFilter.equals(directions[0]))) {
return false;
- } else if (!(config.channelBFilter.equals(ANYDIR) || config.channelBFilter.equals(directions[1]))) {
+ } else if (!(config.channelBFilter.equals(ANY_DIR) || config.channelBFilter.equals(directions[1]))) {
return false;
}
package org.openhab.binding.enocean.internal.transceiver;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Arrays;
+import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanException;
import org.openhab.binding.enocean.internal.messages.BasePacket;
import org.openhab.binding.enocean.internal.messages.ERP1Message;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanESP2Transceiver extends EnOceanTransceiver {
public EnOceanESP2Transceiver(String path, TransceiverErrorListener errorListener,
- ScheduledExecutorService scheduler, SerialPortManager serialPortManager) {
+ ScheduledExecutorService scheduler, @Nullable SerialPortManager serialPortManager) {
super(path, errorListener, scheduler, serialPortManager);
}
protected void processMessage(byte firstByte) {
byte[] readingBuffer = new byte[ENOCEAN_MAX_DATA];
int bytesRead = -1;
- byte _byte;
+ byte byteBuffer;
try {
readingBuffer[0] = firstByte;
-
- bytesRead = this.inputStream.read(readingBuffer, 1, inputStream.available());
+ InputStream localInputStream = inputStream;
+ if (localInputStream == null) {
+ throw new IOException("could not read from inputstream, it was null");
+ }
+ bytesRead = localInputStream.read(readingBuffer, 1, localInputStream.available());
if (bytesRead == -1) {
throw new IOException("could not read from inputstream");
}
- if (readingTask == null || readingTask.isCancelled()) {
+ Future<?> localReadingTask = readingTask;
+ if (localReadingTask == null || localReadingTask.isCancelled()) {
return;
}
bytesRead++;
for (int p = 0; p < bytesRead; p++) {
- _byte = readingBuffer[p];
+ byteBuffer = readingBuffer[p];
switch (state) {
case WaitingForFirstSyncByte:
- if (_byte == ESP2Packet.ENOCEAN_ESP2_FIRSTSYNC_BYTE) {
+ if (byteBuffer == ESP2Packet.ENOCEAN_ESP2_FIRSTSYNC_BYTE) {
state = ReadingState.WaitingForSecondSyncByte;
logger.trace("Received First Sync Byte");
}
break;
case WaitingForSecondSyncByte:
- if (_byte == ESP2Packet.ENOCEAN_ESP2_SECONDSYNC_BYTE) {
+ if (byteBuffer == ESP2Packet.ENOCEAN_ESP2_SECONDSYNC_BYTE) {
state = ReadingState.ReadingHeader;
logger.trace("Received Second Sync Byte");
}
state = ReadingState.ReadingData;
currentPosition = 0;
- dataBuffer[currentPosition++] = _byte;
+ dataBuffer[currentPosition++] = byteBuffer;
dataLength = ((dataBuffer[0] & 0xFF) & 0b11111);
packetType = (byte) ((dataBuffer[0] & 0xFF) >> 5);
break;
case ReadingData:
if (currentPosition == dataLength) {
- if (ESP2Packet.validateCheckSum(dataBuffer, dataLength, _byte)) {
- BasePacket packet = ESP2PacketConverter.BuildPacket(dataLength, packetType, dataBuffer);
+ if (ESP2Packet.validateCheckSum(dataBuffer, dataLength, byteBuffer)) {
+ BasePacket packet = ESP2PacketConverter.buildPacket(dataLength, packetType, dataBuffer);
if (packet != null) {
switch (packet.getPacketType()) {
case RADIO_ERP1: {
}
} else {
if (dataBuffer[1] != (byte) 0xFC) {
- logger.debug("Unknown/unsupported ESP2Packet: {}",
- HexUtils.bytesToHex(Arrays.copyOf(dataBuffer, dataLength)));
+ byte[] array = Arrays.copyOf(dataBuffer, dataLength);
+ String packetString = array != null ? HexUtils.bytesToHex(array) : "";
+ logger.debug("Unknown/unsupported ESP2Packet: {}", packetString);
}
}
} else {
logger.debug("ESP2Packet malformed: {}", HexUtils.bytesToHex(dataBuffer));
}
- state = _byte == ESP2Packet.ENOCEAN_ESP2_FIRSTSYNC_BYTE
+ state = byteBuffer == ESP2Packet.ENOCEAN_ESP2_FIRSTSYNC_BYTE
? ReadingState.WaitingForSecondSyncByte
: ReadingState.WaitingForFirstSyncByte;
currentPosition = 0;
dataLength = packetType = -1;
} else {
- dataBuffer[currentPosition++] = _byte;
+ dataBuffer[currentPosition++] = byteBuffer;
}
break;
}
}
- } catch (
-
- IOException ioexception) {
- errorListener.ErrorOccured(ioexception);
+ } catch (IOException ioexception) {
+ logger.trace("Unable to process message", ioexception);
+ TransceiverErrorListener localListener = errorListener;
+ if (localListener != null) {
+ localListener.errorOccured(ioexception);
+ }
return;
}
}
package org.openhab.binding.enocean.internal.transceiver;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Arrays;
+import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanException;
import org.openhab.binding.enocean.internal.messages.BasePacket;
import org.openhab.binding.enocean.internal.messages.ESP3Packet;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public class EnOceanESP3Transceiver extends EnOceanTransceiver {
public EnOceanESP3Transceiver(String path, TransceiverErrorListener errorListener,
- ScheduledExecutorService scheduler, SerialPortManager serialPortManager) {
+ ScheduledExecutorService scheduler, @Nullable SerialPortManager serialPortManager) {
super(path, errorListener, scheduler, serialPortManager);
}
protected void processMessage(byte firstByte) {
byte[] readingBuffer = new byte[ENOCEAN_MAX_DATA];
int bytesRead = -1;
- byte _byte;
+ byte byteBuffer;
try {
readingBuffer[0] = firstByte;
-
- bytesRead = this.inputStream.read(readingBuffer, 1, inputStream.available());
+ InputStream localInPutStream = this.inputStream;
+ if (localInPutStream == null) {
+ throw new IOException("could not read from inputstream");
+ }
+ bytesRead = localInPutStream.read(readingBuffer, 1, localInPutStream.available());
if (bytesRead == -1) {
throw new IOException("could not read from inputstream");
}
- if (readingTask == null || readingTask.isCancelled()) {
+ Future<?> localReadingTask = readingTask;
+ if (localReadingTask == null || localReadingTask.isCancelled()) {
return;
}
bytesRead++;
for (int p = 0; p < bytesRead; p++) {
- _byte = readingBuffer[p];
+ byteBuffer = readingBuffer[p];
switch (state) {
case WaitingForSyncByte:
- if (_byte == ESP3Packet.ESP3_SYNC_BYTE) {
+ if (byteBuffer == ESP3Packet.ESP3_SYNC_BYTE) {
state = ReadingState.ReadingHeader;
logger.trace("Received Sync Byte");
}
break;
case ReadingHeader:
if (currentPosition == ESP3Packet.ESP3_HEADER_LENGTH) {
- if (ESP3Packet.checkCRC8(dataBuffer, ESP3Packet.ESP3_HEADER_LENGTH, _byte)
+ if (ESP3Packet.checkCRC8(dataBuffer, ESP3Packet.ESP3_HEADER_LENGTH, byteBuffer)
&& ((dataBuffer[0] & 0xFF) << 8) + (dataBuffer[1] & 0xFF)
+ (dataBuffer[2] & 0xFF) > 0) {
state = ReadingState.ReadingData;
ESP3Packet.ESP3_HEADER_LENGTH - copyFrom);
state = ReadingState.ReadingHeader;
currentPosition = ESP3Packet.ESP3_HEADER_LENGTH - copyFrom;
- dataBuffer[currentPosition++] = _byte;
+ dataBuffer[currentPosition++] = byteBuffer;
} else {
currentPosition = 0;
- state = _byte == ESP3Packet.ESP3_SYNC_BYTE ? ReadingState.ReadingHeader
+ state = byteBuffer == ESP3Packet.ESP3_SYNC_BYTE ? ReadingState.ReadingHeader
: ReadingState.WaitingForSyncByte;
}
logger.trace("CrC8 header check not successful");
}
} else {
- dataBuffer[currentPosition++] = _byte;
+ dataBuffer[currentPosition++] = byteBuffer;
}
break;
case ReadingData:
if (currentPosition == dataLength + optionalLength) {
- if (ESP3Packet.checkCRC8(dataBuffer, dataLength + optionalLength, _byte)) {
+ if (ESP3Packet.checkCRC8(dataBuffer, dataLength + optionalLength, byteBuffer)) {
state = ReadingState.WaitingForSyncByte;
- BasePacket packet = ESP3PacketFactory.BuildPacket(dataLength, optionalLength,
+ BasePacket packet = ESP3PacketFactory.buildPacket(dataLength, optionalLength,
packetType, dataBuffer);
if (packet != null) {
.bytesToHex(Arrays.copyOf(dataBuffer, dataLength + optionalLength)));
}
} else {
- state = _byte == ESP3Packet.ESP3_SYNC_BYTE ? ReadingState.ReadingHeader
+ state = byteBuffer == ESP3Packet.ESP3_SYNC_BYTE ? ReadingState.ReadingHeader
: ReadingState.WaitingForSyncByte;
logger.trace("ESP3Packet malformed: {}",
HexUtils.bytesToHex(Arrays.copyOf(dataBuffer, dataLength + optionalLength)));
currentPosition = 0;
dataLength = optionalLength = packetType = -1;
} else {
- dataBuffer[currentPosition++] = _byte;
+ dataBuffer[currentPosition++] = byteBuffer;
}
break;
}
}
} catch (IOException ioexception) {
- errorListener.ErrorOccured(ioexception);
+ logger.trace("Unable to process message", ioexception);
+ TransceiverErrorListener localListener = errorListener;
+ if (localListener != null) {
+ localListener.errorOccured(ioexception);
+ }
return;
}
}
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanBindingConstants;
import org.openhab.binding.enocean.internal.EnOceanException;
import org.openhab.binding.enocean.internal.Helper;
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public abstract class EnOceanTransceiver implements SerialPortEventListener {
public static final int ENOCEAN_MAX_DATA = 65790;
// Thread management
- protected Future<?> readingTask = null;
- private Future<?> timeOut = null;
+ protected @Nullable Future<?> readingTask = null;
+ private @Nullable Future<?> timeOut = null;
protected Logger logger = LoggerFactory.getLogger(EnOceanTransceiver.class);
- private SerialPortManager serialPortManager;
+ private @Nullable SerialPortManager serialPortManager;
private static final int ENOCEAN_DEFAULT_BAUD = 57600;
protected String path;
- SerialPort serialPort;
+ private @Nullable SerialPort serialPort;
class Request {
- BasePacket RequestPacket;
-
- Response ResponsePacket;
- ResponseListener<? extends Response> ResponseListener;
+ @Nullable
+ BasePacket requestPacket;
+ @Nullable
+ Response responsePacket;
+ @Nullable
+ ResponseListener<? extends @Nullable Response> responseListener;
}
private class RequestQueue {
if (!queue.isEmpty()) {
currentRequest = queue.peek();
try {
- if (currentRequest != null && currentRequest.RequestPacket != null) {
- synchronized (currentRequest) {
- logger.debug("Sending data, type {}, payload {}{}",
- currentRequest.RequestPacket.getPacketType().name(),
- HexUtils.bytesToHex(currentRequest.RequestPacket.getPayload()),
- HexUtils.bytesToHex(currentRequest.RequestPacket.getOptionalPayload()));
-
- byte[] b = serializePacket(currentRequest.RequestPacket);
- logger.trace("Sending raw data: {}", HexUtils.bytesToHex(b));
- outputStream.write(b);
- outputStream.flush();
-
- if (timeOut != null) {
- timeOut.cancel(true);
- }
-
- // slowdown sending of message to avoid hickups at receivers
- // Todo tweak sending intervall (250 ist just a first try)
- timeOut = scheduler.schedule(() -> {
- try {
- sendNext();
- } catch (IOException e) {
- errorListener.ErrorOccured(e);
- return;
+ Request localCurrentRequest = currentRequest;
+ if (localCurrentRequest != null && localCurrentRequest.requestPacket != null) {
+ synchronized (localCurrentRequest) {
+ BasePacket rqPacket = localCurrentRequest.requestPacket;
+ if (currentRequest != null && rqPacket != null) {
+ logger.debug("Sending data, type {}, payload {}{}", rqPacket.getPacketType().name(),
+ HexUtils.bytesToHex(rqPacket.getPayload()),
+ HexUtils.bytesToHex(rqPacket.getOptionalPayload()));
+ byte[] b = serializePacket(rqPacket);
+ logger.trace("Sending raw data: {}", HexUtils.bytesToHex(b));
+ OutputStream localOutPutStream = outputStream;
+ if (localOutPutStream != null) {
+ localOutPutStream.write(b);
+ localOutPutStream.flush();
+ }
+ Future<?> localTimeOut = timeOut;
+ if (localTimeOut != null) {
+ localTimeOut.cancel(true);
}
- }, 250, TimeUnit.MILLISECONDS);
+
+ // slowdown sending of message to avoid hickups at receivers
+ // Todo tweak sending intervall (250 ist just a first try)
+ timeOut = scheduler.schedule(() -> {
+ try {
+ sendNext();
+ } catch (IOException e) {
+ logger.trace("Unable to process message", e);
+ TransceiverErrorListener localListener = errorListener;
+ if (localListener != null) {
+ localListener.errorOccured(e);
+ }
+ return;
+ }
+ }, 250, TimeUnit.MILLISECONDS);
+ }
}
} else {
sendNext();
}
RequestQueue requestQueue;
+ @Nullable
Request currentRequest = null;
protected Map<Long, HashSet<PacketListener>> listeners;
protected HashSet<EventListener> eventListeners;
- protected TeachInListener teachInListener;
+ protected @Nullable TeachInListener teachInListener;
- protected InputStream inputStream;
- protected OutputStream outputStream;
+ protected @Nullable InputStream inputStream;
+ protected @Nullable OutputStream outputStream;
- private byte[] filteredDeviceId;
+ private byte[] filteredDeviceId = new byte[0];
+ @Nullable
TransceiverErrorListener errorListener;
public EnOceanTransceiver(String path, TransceiverErrorListener errorListener, ScheduledExecutorService scheduler,
- SerialPortManager serialPortManager) {
+ @Nullable SerialPortManager serialPortManager) {
requestQueue = new RequestQueue(scheduler);
listeners = new HashMap<>();
this.path = path;
}
- public void Initialize()
+ public void initilize()
throws UnsupportedCommOperationException, PortInUseException, IOException, TooManyListenersException {
- SerialPortIdentifier id = serialPortManager.getIdentifier(path);
+ SerialPortManager localSerialPortManager = serialPortManager;
+ if (localSerialPortManager == null) {
+ throw new IOException("Could access the SerialPortManager, it was null");
+ }
+ SerialPortIdentifier id = localSerialPortManager.getIdentifier(path);
if (id == null) {
throw new IOException("Could not find a gateway on given path '" + path + "', "
- + serialPortManager.getIdentifiers().count() + " ports available.");
+ + localSerialPortManager.getIdentifiers().count() + " ports available.");
}
- serialPort = id.open(EnOceanBindingConstants.BINDING_ID, 1000);
- serialPort.setSerialPortParams(ENOCEAN_DEFAULT_BAUD, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
+ try {
+ serialPort = id.open(EnOceanBindingConstants.BINDING_ID, 1000);
+ } catch (PortInUseException e) {
+ logger.warn("EnOceanSerialTransceiver not initialized, port allready in use", e);
+ return;
+ }
+ SerialPort localSerialPort = serialPort;
+ if (localSerialPort == null) {
+ logger.debug("EnOceanSerialTransceiver not initialized, serialPort was null");
+ return;
+ }
+ localSerialPort.setSerialPortParams(ENOCEAN_DEFAULT_BAUD, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
try {
- serialPort.enableReceiveThreshold(1);
- serialPort.enableReceiveTimeout(100); // In ms. Small values mean faster shutdown but more cpu usage.
+ localSerialPort.enableReceiveThreshold(1);
+ localSerialPort.enableReceiveTimeout(100); // In ms. Small values mean faster shutdown but more cpu usage.
} catch (UnsupportedCommOperationException e) {
// rfc connections do not allow a ReceiveThreshold
+ logger.debug("EnOceanSerialTransceiver encountered an UnsupportedCommOperationException while initilizing",
+ e);
}
- inputStream = serialPort.getInputStream();
- outputStream = serialPort.getOutputStream();
-
+ inputStream = localSerialPort.getInputStream();
+ outputStream = localSerialPort.getOutputStream();
logger.info("EnOceanSerialTransceiver initialized");
}
- public void StartReceiving(ScheduledExecutorService scheduler) {
- if (readingTask == null || readingTask.isCancelled()) {
- readingTask = scheduler.submit(new Runnable() {
+ public void startReceiving(ScheduledExecutorService scheduler) {
+ @Nullable
+ Future<?> localReadingTask = readingTask;
+ if (localReadingTask == null || localReadingTask.isCancelled()) {
+ localReadingTask = scheduler.submit(new Runnable() {
@Override
public void run() {
receivePackets();
logger.info("EnOceanSerialTransceiver RX thread started");
}
- public void ShutDown() {
+ public void shutDown() {
logger.debug("shutting down transceiver");
logger.debug("Interrupt rx Thread");
- if (timeOut != null) {
- timeOut.cancel(true);
+ Future<?> localTimeOut = timeOut;
+ if (localTimeOut != null) {
+ localTimeOut.cancel(true);
}
- if (readingTask != null) {
- readingTask.cancel(true);
- try {
- inputStream.close();
- } catch (Exception e) {
+ Future<?> localReadingTask = readingTask;
+ if (localReadingTask != null) {
+ localReadingTask.cancel(true);
+
+ InputStream localInputStream = inputStream;
+ if (localInputStream != null) {
+ try {
+ localInputStream.close();
+ } catch (IOException e) {
+ logger.debug("IOException occured while closing the stream", e);
+ }
}
}
teachInListener = null;
errorListener = null;
- if (outputStream != null) {
- logger.debug("Closing serial output stream");
+ OutputStream localOutputStream = outputStream;
+ if (localOutputStream != null) {
try {
- outputStream.close();
+ localOutputStream.close();
} catch (IOException e) {
- logger.debug("Error while closing the output stream: {}", e.getMessage());
+ logger.debug("IOException occured while closing the output stream", e);
}
}
- if (inputStream != null) {
- logger.debug("Closeing serial input stream");
+
+ InputStream localInputStream = inputStream;
+ if (localInputStream != null) {
try {
- inputStream.close();
+ localInputStream.close();
} catch (IOException e) {
- logger.debug("Error while closing the input stream: {}", e.getMessage());
+ logger.debug("IOException occured while closing the input stream", e);
}
}
- if (serialPort != null) {
- logger.debug("Closing serial port");
- serialPort.close();
+ SerialPort localSerialPort = serialPort;
+ if (localSerialPort != null) {
+ logger.debug("Closing the serial port");
+ localSerialPort.close();
}
serialPort = null;
private void receivePackets() {
byte[] buffer = new byte[1];
- while (readingTask != null && !readingTask.isCancelled()) {
+ Future<?> localReadingTask = readingTask;
+ while (localReadingTask != null && !localReadingTask.isCancelled()) {
int bytesRead = read(buffer, 1);
if (bytesRead > 0) {
processMessage(buffer[0]);
protected abstract void processMessage(byte firstByte);
protected int read(byte[] buffer, int length) {
- try {
- return this.inputStream.read(buffer, 0, length);
- } catch (IOException e) {
- return 0;
+ InputStream localInputStream = inputStream;
+ if (localInputStream != null) {
+ try {
+ localInputStream.read(buffer, 0, length);
+ } catch (IOException e) {
+ logger.debug("IOException occured while reading the input stream", e);
+ return 0;
+ }
}
+ return 0;
}
protected void informListeners(BasePacket packet) {
msg.getRORG().name(), HexUtils.bytesToHex(msg.getSenderId()), HexUtils.bytesToHex(d));
if (msg.getRORG() != RORG.Unknown) {
- if (senderId != null) {
- if (filteredDeviceId != null && senderId[0] == filteredDeviceId[0]
+ if (senderId.length > 0) {
+ if (senderId.length > 2 && filteredDeviceId.length > 2 && senderId[0] == filteredDeviceId[0]
&& senderId[1] == filteredDeviceId[1] && senderId[2] == filteredDeviceId[2]) {
// filter away own messages which are received through a repeater
return;
if (teachInListener != null && (msg.getIsTeachIn() || msg.getRORG() == RORG.RPS)) {
logger.info("Received teach in message from {}", HexUtils.bytesToHex(msg.getSenderId()));
- teachInListener.packetReceived(msg);
+
+ TeachInListener localListener = teachInListener;
+ if (localListener != null) {
+ localListener.packetReceived(msg);
+ }
return;
} else if (teachInListener == null && msg.getIsTeachIn()) {
logger.info("Discard message because this is a teach-in telegram from {}!",
if (teachInListener != null) {
logger.info("Received smart teach in from {}", HexUtils.bytesToHex(senderId));
- teachInListener.eventReceived(event);
+ TeachInListener localListener = teachInListener;
+ if (localListener != null) {
+ localListener.eventReceived(event);
+ }
return;
} else {
logger.info("Discard message because this is a smart teach-in telegram from {}!",
}
protected void handleResponse(Response response) throws IOException {
- if (currentRequest != null) {
- if (currentRequest.ResponseListener != null) {
- currentRequest.ResponsePacket = response;
+ Request localCurrentRequest = currentRequest;
+ if (localCurrentRequest != null) {
+ ResponseListener<? extends @Nullable Response> listener = localCurrentRequest.responseListener;
+ if (listener != null) {
+ localCurrentRequest.responsePacket = response;
try {
- currentRequest.ResponseListener.handleResponse(response);
+ listener.handleResponse(response);
} catch (Exception e) {
logger.debug("Exception during response handling");
} finally {
}
}
- public void sendBasePacket(BasePacket packet, ResponseListener<? extends Response> responseCallback)
- throws IOException {
+ public void sendBasePacket(@Nullable BasePacket packet,
+ @Nullable ResponseListener<? extends @Nullable Response> responseCallback) throws IOException {
if (packet == null) {
return;
}
logger.debug("Enqueue new send request with ESP3 type {} {} callback", packet.getPacketType().name(),
responseCallback == null ? "without" : "with");
Request r = new Request();
- r.RequestPacket = packet;
- r.ResponseListener = responseCallback;
+ r.requestPacket = packet;
+ r.responseListener = responseCallback;
requestQueue.enqueRequest(r);
}
}
public void setFilteredDeviceId(byte[] filteredDeviceId) {
- if (filteredDeviceId != null) {
- System.arraycopy(filteredDeviceId, 0, filteredDeviceId, 0, filteredDeviceId.length);
- }
+ System.arraycopy(filteredDeviceId, 0, filteredDeviceId, 0, filteredDeviceId.length);
}
@Override
*/
package org.openhab.binding.enocean.internal.transceiver;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.EventMessage;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public interface EventListener {
public void eventReceived(EventMessage event);
}
*/
package org.openhab.binding.enocean.internal.transceiver;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.enocean.internal.messages.BasePacket;
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public interface PacketListener {
public void packetReceived(BasePacket packet);
import java.lang.reflect.ParameterizedType;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.EnOceanException;
import org.openhab.binding.enocean.internal.messages.Response;
*
* @author Daniel Weber - Initial contribution
*/
-public abstract class ResponseListener<T extends Response> {
+@NonNullByDefault
+public abstract class ResponseListener<T extends @Nullable Response> {
protected Class<T> persistentClass;
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({ "unchecked", "null" })
public ResponseListener() {
this.persistentClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
.getActualTypeArguments()[0];
import java.lang.reflect.ParameterizedType;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.enocean.internal.messages.Response;
/**
*
* @author Daniel Weber - Initial contribution
*/
-public abstract class ResponseListenerIgnoringTimeouts<T extends Response> extends ResponseListener<T> {
+@NonNullByDefault
+public abstract class ResponseListenerIgnoringTimeouts<T extends @Nullable Response> extends ResponseListener<T> {
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({ "unchecked", "null" })
public ResponseListenerIgnoringTimeouts() {
this.persistentClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
.getActualTypeArguments()[0];
*/
package org.openhab.binding.enocean.internal.transceiver;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public interface TeachInListener extends PacketListener, EventListener {
}
*/
package org.openhab.binding.enocean.internal.transceiver;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Daniel Weber - Initial contribution
*/
+@NonNullByDefault
public interface TransceiverErrorListener {
- public void ErrorOccured(Throwable exception);
+ public void errorOccured(Throwable exception);
}