]> git.basschouten.com Git - openhab-addons.git/commitdiff
[enocean] Fix unusable bundle after a refactoring about null annotation (#15302)
authorGwendal Roulleau <dalgwen@users.noreply.github.com>
Wed, 26 Jul 2023 11:21:59 +0000 (13:21 +0200)
committerGitHub <noreply@github.com>
Wed, 26 Jul 2023 11:21:59 +0000 (13:21 +0200)
Fix bundle unusable after #14023 (closes #15181)
Fix a case issue with some directory
Fix trigger channel issue

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
23 files changed:
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_03/D2_03_0A.java
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_01.java
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_50.java
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEP.java
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_01/F6_01_01.java
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseSensorHandler.java
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/BaseResponse.java [deleted file]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDBaseIdResponse.java [deleted file]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDLearnedClientsResponse.java [deleted file]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDRepeaterResponse.java [deleted file]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDVersionResponse.java [deleted file]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/SMACKTeachInResponse.java [deleted file]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/BaseResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDBaseIdResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDLearnedClientsResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDRepeaterResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDVersionResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/SMACKTeachInResponse.java [new file with mode: 0644]
bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanTransceiver.java

index d79601dc3968a27fc580d46a3c2877b787e0c465..5924c7845a2afeb63f154be3b193e4a3f4d62201 100644 (file)
@@ -49,7 +49,7 @@ public class A5_20_04 extends A5_20 {
     }
 
     @Override
-    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
             Configuration config) {
         switch (channelId) {
             case CHANNEL_STATUS_REQUEST_EVENT:
index 824a5408f2909d42689ccb5ac595d4d820af1c61..91ea0aa399684430f2ad7aba35cd8634527d721c 100644 (file)
@@ -48,7 +48,7 @@ public class D2_03_0A extends _VLDMessage {
     }
 
     @Override
-    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
             Configuration config) {
         switch (channelId) {
             case CHANNEL_PUSHBUTTON:
index 8668c0ba6d80118356ba1a485b6a7ed0c062fd08..db4b35f5fafec1d4a52b8058af36985e96f5f141 100644 (file)
@@ -38,7 +38,7 @@ import org.openhab.core.types.UnDefType;
  * battery channels may be not supported by the physical device (depending on the actual model). If a channel is not
  * supported by a device it will transmit a 'not supported' message which is ignored by this implementation.
  * Consequently channels that are not supported by the physical device will never send updates to linked items.
- * 
+ *
  * @author Thomas Lauterbach - Initial contribution
  */
 @NonNullByDefault
@@ -164,7 +164,7 @@ public class D2_06_01 extends _VLDMessage {
     }
 
     protected State getTemperature() {
-        double unscaledTemp = (double) (bytes[5] & 0xFF);
+        double unscaledTemp = bytes[5] & 0xFF;
         if (unscaledTemp <= 250) {
             double scaledTemp = unscaledTemp * 0.32 - 20;
             return new QuantityType<>(scaledTemp, SIUnits.CELSIUS);
@@ -198,7 +198,7 @@ public class D2_06_01 extends _VLDMessage {
     }
 
     @Override
-    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
             Configuration config) {
         // Sensor values
         if (bytes[0] == MessageType.SENSORVALUES.getIntValue()) {
index 63ad5c71e00c207aed9023e87a5a4b961d9a4950..d8a58c7c29dbf84cfdca7e3982a37c27bc08aa5b 100644 (file)
@@ -115,7 +115,7 @@ public class D2_06_50 extends _VLDMessage {
     }
 
     @Override
-    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
             Configuration config) {
         // Alarm
         if (bytes[0] == 0x02) {
index 353f75670d54c4b0d47e3f30b1e9f4c91a81efba..e5f832099bd7f37b308581094a10195ba268f158 100644 (file)
@@ -114,7 +114,7 @@ public abstract class EEP {
         return convertToStateImpl(channelId, channelTypeId, getCurrentStateFunc, config);
     }
 
-    public @Nullable String convertToEvent(String channelId, String channelTypeId, String lastEvent,
+    public @Nullable String convertToEvent(String channelId, String channelTypeId, @Nullable String lastEvent,
             Configuration config) {
         if (!getEEPType().isChannelSupported(channelId, channelTypeId)) {
             throw new IllegalArgumentException(
@@ -223,7 +223,7 @@ public abstract class EEP {
         return UnDefType.UNDEF;
     }
 
-    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
             Configuration config) {
         return null;
     }
index 60329e831d93ece2a9404690696809a7a421d51c..14c6a9c90a49c0155a98ee90235e520d60ba6587 100644 (file)
@@ -35,7 +35,7 @@ public class F6_01_01 extends _RPSMessage {
     }
 
     @Override
-    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
             Configuration config) {
         return getBit(bytes[0], 4) ? CommonTriggerEvents.PRESSED : CommonTriggerEvents.RELEASED;
     }
index 36126907651040c4b5711e4fdcbe4dc6e0b4defa..80e7db34960488a56beac1650ce5cd2fa301668a 100644 (file)
@@ -45,7 +45,7 @@ public class F6_02_01 extends F6_02 {
     }
 
     @Override
-    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
             Configuration config) {
         if (t21 && nu) {
             if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
@@ -59,7 +59,7 @@ public class F6_02_01 extends F6_02 {
         } else if (t21 && !nu) {
             if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
                 return CommonTriggerEvents.RELEASED;
-            } else {
+            } else if (lastEvent != null) {
                 if (lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) {
                     return CommonTriggerEvents.DIR1_RELEASED;
                 } else if (lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) {
index 514c07eab7e7c560b58e2c52cbd0433f118e6bce..ed63201e81c2da842e753c947ed225102ff76dcb 100644 (file)
@@ -45,7 +45,7 @@ public class F6_02_02 extends F6_02 {
     }
 
     @Override
-    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, String lastEvent,
+    protected @Nullable String convertToEventImpl(String channelId, String channelTypeId, @Nullable String lastEvent,
             Configuration config) {
         if (t21 && nu) {
             if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
@@ -58,7 +58,7 @@ public class F6_02_02 extends F6_02 {
         } else if (t21 && !nu) {
             if (CHANNEL_ROCKERSWITCH_ACTION.equals(channelTypeId)) {
                 return CommonTriggerEvents.RELEASED;
-            } else {
+            } else if (lastEvent != null) {
                 if (lastEvent.equals(CommonTriggerEvents.DIR1_PRESSED)) {
                     return CommonTriggerEvents.DIR1_RELEASED;
                 } else if (lastEvent.equals(CommonTriggerEvents.DIR2_PRESSED)) {
index e26b3663f46e595d851b79802e2513a66d90d198..d242e0f2926feee78b712e89d8f1a4377a8267c6 100644 (file)
@@ -189,13 +189,10 @@ public class EnOceanBaseSensorHandler extends EnOceanBaseThingHandler implements
                                 break;
                             case TRIGGER:
                                 String lastEvent = lastEvents.get(channelId);
-                                if (lastEvent != null) {
-                                    String event = eep.convertToEvent(channelId, channelTypeId, lastEvent,
-                                            channelConfig);
-                                    if (event != null) {
-                                        triggerChannel(channel.getUID(), event);
-                                        lastEvents.put(channelId, event);
-                                    }
+                                String event = eep.convertToEvent(channelId, channelTypeId, lastEvent, channelConfig);
+                                if (event != null) {
+                                    triggerChannel(channel.getUID(), event);
+                                    lastEvents.put(channelId, event);
                                 }
                                 break;
                         }
index cadb17f98de388c6fcb4a911018c9d549d9cceae..0a4cb5f3f8367fde500ef1c743d8f8964424235c 100644 (file)
@@ -208,7 +208,7 @@ public class EnOceanBridgeHandler extends ConfigStatusBridgeHandler implements T
             }
 
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "opening serial port...");
-            localTransceiver.initilize();
+            localTransceiver.initialize();
 
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_PENDING, "starting rx thread...");
             localTransceiver.startReceiving(scheduler);
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/BaseResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/BaseResponse.java
deleted file mode 100644 (file)
index e1aa364..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * 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.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) {
-        super(response.getPayload().length + response.getOptionalPayload().length, 0,
-                Helper.concatAll(response.getPayload(), response.getOptionalPayload()));
-    }
-}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDBaseIdResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDBaseIdResponse.java
deleted file mode 100644 (file)
index c00672a..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * 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.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 = new byte[0];
-    private int remainingWriteCycles = 0;
-
-    public RDBaseIdResponse(Response response) {
-        this(response.getPayload().length, response.getOptionalPayload().length,
-                Helper.concatAll(response.getPayload(), response.getOptionalPayload()));
-    }
-
-    RDBaseIdResponse(int dataLength, int optionalDataLength, byte[] payload) {
-        super(dataLength, optionalDataLength, payload);
-
-        if (this.data.length != 5 || this.optionalData.length != 1) {
-            return;
-        }
-
-        baseId = getPayload(1, 4);
-        remainingWriteCycles = optionalData[0] & 0xFF;
-
-        isValid = true;
-    }
-
-    public final byte[] getBaseId() {
-        return baseId;
-    }
-
-    public int getRemainingWriteCycles() {
-        return remainingWriteCycles;
-    }
-}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDLearnedClientsResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDLearnedClientsResponse.java
deleted file mode 100644 (file)
index 6c11487..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.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 = new byte[0];
-        public byte[] controllerId = new byte[0];
-        public int mailboxIndex;
-    }
-
-    LearnedClient[] learnedClients = new LearnedClient[0];
-
-    public RDLearnedClientsResponse(Response response) {
-        this(response.getPayload().length, response.getOptionalPayload().length,
-                Helper.concatAll(response.getPayload(), response.getOptionalPayload()));
-    }
-
-    RDLearnedClientsResponse(int dataLength, int optionalDataLength, byte[] payload) {
-        super(dataLength, optionalDataLength, payload);
-
-        if (payload.length == 0 || (payload.length - 1) % 9 != 0) {
-            return;
-        } else {
-            isValid = true;
-        }
-
-        learnedClients = new LearnedClient[(payload.length - 1) / 9];
-        for (int i = 0; i < learnedClients.length; i++) {
-            LearnedClient client = new LearnedClient();
-            client.clientId = Arrays.copyOfRange(payload, 1 + i * 9, 1 + i * 9 + 4);
-            client.controllerId = Arrays.copyOfRange(payload, 5 + i * 9, 5 + i * 9 + 4);
-            client.mailboxIndex = payload[9 + i * 9] & 0xFF;
-            learnedClients[i] = client;
-        }
-    }
-
-    public LearnedClient[] getLearnedClients() {
-        return learnedClients;
-    }
-}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDRepeaterResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDRepeaterResponse.java
deleted file mode 100644 (file)
index d61ab7b..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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.messages.responses;
-
-import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
-
-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 = "";
-
-    public RDRepeaterResponse(Response response) {
-        this(response.getPayload().length, 0, response.getPayload());
-    }
-
-    RDRepeaterResponse(int dataLength, int optionalDataLength, byte[] payload) {
-        super(dataLength, optionalDataLength, payload);
-
-        if (payload.length < 3) {
-            return;
-        }
-
-        if (payload[1] == 0) {
-            repeaterLevel = REPEATERMODE_OFF;
-        } else if (payload[1] == 1 || payload[1] == 2) {
-            switch (payload[2]) {
-                case 1:
-                    repeaterLevel = REPEATERMODE_LEVEL_1;
-                    break;
-                case 2:
-                    repeaterLevel = REPEATERMODE_LEVEL_2;
-                    break;
-                case 0:
-                    repeaterLevel = REPEATERMODE_OFF;
-                    break;
-                default:
-                    return;
-            }
-
-            isValid = true;
-        }
-    }
-
-    public StringType getRepeaterLevel() {
-        return StringType.valueOf(repeaterLevel);
-    }
-}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDVersionResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDVersionResponse.java
deleted file mode 100644 (file)
index e041586..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * 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.messages.responses;
-
-import java.util.Arrays;
-
-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 = "";
-    protected String apiVersion = "";
-    protected String chipId = "";
-    protected String description = "";
-
-    public RDVersionResponse(Response response) {
-        this(response.getPayload().length, 0, response.getPayload());
-    }
-
-    RDVersionResponse(int dataLength, int optionalDataLength, byte[] payload) {
-        super(dataLength, optionalDataLength, payload);
-
-        if (payload.length < 33) {
-            return;
-        }
-
-        try {
-            appVersion = String.format("%d.%d.%d.%d", payload[1] & 0xff, payload[2] & 0xff, payload[3] & 0xff,
-                    payload[4] & 0xff);
-            apiVersion = String.format("%d.%d.%d.%d", payload[5] & 0xff, payload[6] & 0xff, payload[7] & 0xff,
-                    payload[8] & 0xff);
-
-            chipId = HexUtils.bytesToHex(Arrays.copyOfRange(payload, 9, 13));
-
-            StringBuffer sb = new StringBuffer();
-            for (int i = 17; i < payload.length; i++) {
-                sb.append((char) (payload[i] & 0xff));
-            }
-            description = sb.toString();
-            isValid = true;
-
-        } catch (Exception e) {
-            responseType = ResponseType.RET_ERROR;
-        }
-    }
-
-    public String getAPPVersion() {
-        return appVersion;
-    }
-
-    public String getAPIVersion() {
-        return apiVersion;
-    }
-
-    public String getChipID() {
-        return chipId;
-    }
-
-    public String getDescription() {
-        return description;
-    }
-}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/SMACKTeachInResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/SMACKTeachInResponse.java
deleted file mode 100644 (file)
index b09dc58..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * 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.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
-    static final byte RESPONSE_TIME_HVALUE = 0;
-    static final byte RESPONSE_TIME_LVALUE = (byte) 0xFA;
-
-    static final byte TEACH_IN = 0x00;
-    static final byte TEACH_OUT = 0x20;
-    static final byte REPEATED_TEACH_IN = 0x01;
-    static final byte NOPLACE_FOR_MAILBOX = 0x12;
-    static final byte BAD_RSSI = 0x14;
-
-    public SMACKTeachInResponse() {
-        super(4, 0, new byte[] { Response.ResponseType.RET_OK.getValue(), RESPONSE_TIME_HVALUE, RESPONSE_TIME_LVALUE,
-                TEACH_IN });
-    }
-
-    public void setTeachOutResponse() {
-        data[3] = TEACH_OUT;
-    }
-
-    public boolean isTeachOut() {
-        return data[3] == TEACH_OUT;
-    }
-
-    public void setRepeatedTeachInResponse() {
-        data[3] = REPEATED_TEACH_IN;
-    }
-
-    public void setNoPlaceForFurtherMailbox() {
-        data[3] = NOPLACE_FOR_MAILBOX;
-    }
-
-    public void setBadRSSI() {
-        data[3] = BAD_RSSI;
-    }
-
-    public void setTeachIn() {
-        data[3] = TEACH_IN;
-    }
-
-    public boolean isTeachIn() {
-        return data[3] == TEACH_IN;
-    }
-}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/BaseResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/BaseResponse.java
new file mode 100644 (file)
index 0000000..e1aa364
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+ * 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.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) {
+        super(response.getPayload().length + response.getOptionalPayload().length, 0,
+                Helper.concatAll(response.getPayload(), response.getOptionalPayload()));
+    }
+}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDBaseIdResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDBaseIdResponse.java
new file mode 100644 (file)
index 0000000..c00672a
--- /dev/null
@@ -0,0 +1,54 @@
+/**
+ * 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.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 = new byte[0];
+    private int remainingWriteCycles = 0;
+
+    public RDBaseIdResponse(Response response) {
+        this(response.getPayload().length, response.getOptionalPayload().length,
+                Helper.concatAll(response.getPayload(), response.getOptionalPayload()));
+    }
+
+    RDBaseIdResponse(int dataLength, int optionalDataLength, byte[] payload) {
+        super(dataLength, optionalDataLength, payload);
+
+        if (this.data.length != 5 || this.optionalData.length != 1) {
+            return;
+        }
+
+        baseId = getPayload(1, 4);
+        remainingWriteCycles = optionalData[0] & 0xFF;
+
+        isValid = true;
+    }
+
+    public final byte[] getBaseId() {
+        return baseId;
+    }
+
+    public int getRemainingWriteCycles() {
+        return remainingWriteCycles;
+    }
+}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDLearnedClientsResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDLearnedClientsResponse.java
new file mode 100644 (file)
index 0000000..6c11487
--- /dev/null
@@ -0,0 +1,63 @@
+/**
+ * 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.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 = new byte[0];
+        public byte[] controllerId = new byte[0];
+        public int mailboxIndex;
+    }
+
+    LearnedClient[] learnedClients = new LearnedClient[0];
+
+    public RDLearnedClientsResponse(Response response) {
+        this(response.getPayload().length, response.getOptionalPayload().length,
+                Helper.concatAll(response.getPayload(), response.getOptionalPayload()));
+    }
+
+    RDLearnedClientsResponse(int dataLength, int optionalDataLength, byte[] payload) {
+        super(dataLength, optionalDataLength, payload);
+
+        if (payload.length == 0 || (payload.length - 1) % 9 != 0) {
+            return;
+        } else {
+            isValid = true;
+        }
+
+        learnedClients = new LearnedClient[(payload.length - 1) / 9];
+        for (int i = 0; i < learnedClients.length; i++) {
+            LearnedClient client = new LearnedClient();
+            client.clientId = Arrays.copyOfRange(payload, 1 + i * 9, 1 + i * 9 + 4);
+            client.controllerId = Arrays.copyOfRange(payload, 5 + i * 9, 5 + i * 9 + 4);
+            client.mailboxIndex = payload[9 + i * 9] & 0xFF;
+            learnedClients[i] = client;
+        }
+    }
+
+    public LearnedClient[] getLearnedClients() {
+        return learnedClients;
+    }
+}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDRepeaterResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDRepeaterResponse.java
new file mode 100644 (file)
index 0000000..d61ab7b
--- /dev/null
@@ -0,0 +1,65 @@
+/**
+ * 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.messages.responses;
+
+import static org.openhab.binding.enocean.internal.EnOceanBindingConstants.*;
+
+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 = "";
+
+    public RDRepeaterResponse(Response response) {
+        this(response.getPayload().length, 0, response.getPayload());
+    }
+
+    RDRepeaterResponse(int dataLength, int optionalDataLength, byte[] payload) {
+        super(dataLength, optionalDataLength, payload);
+
+        if (payload.length < 3) {
+            return;
+        }
+
+        if (payload[1] == 0) {
+            repeaterLevel = REPEATERMODE_OFF;
+        } else if (payload[1] == 1 || payload[1] == 2) {
+            switch (payload[2]) {
+                case 1:
+                    repeaterLevel = REPEATERMODE_LEVEL_1;
+                    break;
+                case 2:
+                    repeaterLevel = REPEATERMODE_LEVEL_2;
+                    break;
+                case 0:
+                    repeaterLevel = REPEATERMODE_OFF;
+                    break;
+                default:
+                    return;
+            }
+
+            isValid = true;
+        }
+    }
+
+    public StringType getRepeaterLevel() {
+        return StringType.valueOf(repeaterLevel);
+    }
+}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDVersionResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDVersionResponse.java
new file mode 100644 (file)
index 0000000..e041586
--- /dev/null
@@ -0,0 +1,79 @@
+/**
+ * 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.messages.responses;
+
+import java.util.Arrays;
+
+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 = "";
+    protected String apiVersion = "";
+    protected String chipId = "";
+    protected String description = "";
+
+    public RDVersionResponse(Response response) {
+        this(response.getPayload().length, 0, response.getPayload());
+    }
+
+    RDVersionResponse(int dataLength, int optionalDataLength, byte[] payload) {
+        super(dataLength, optionalDataLength, payload);
+
+        if (payload.length < 33) {
+            return;
+        }
+
+        try {
+            appVersion = String.format("%d.%d.%d.%d", payload[1] & 0xff, payload[2] & 0xff, payload[3] & 0xff,
+                    payload[4] & 0xff);
+            apiVersion = String.format("%d.%d.%d.%d", payload[5] & 0xff, payload[6] & 0xff, payload[7] & 0xff,
+                    payload[8] & 0xff);
+
+            chipId = HexUtils.bytesToHex(Arrays.copyOfRange(payload, 9, 13));
+
+            StringBuffer sb = new StringBuffer();
+            for (int i = 17; i < payload.length; i++) {
+                sb.append((char) (payload[i] & 0xff));
+            }
+            description = sb.toString();
+            isValid = true;
+
+        } catch (Exception e) {
+            responseType = ResponseType.RET_ERROR;
+        }
+    }
+
+    public String getAPPVersion() {
+        return appVersion;
+    }
+
+    public String getAPIVersion() {
+        return apiVersion;
+    }
+
+    public String getChipID() {
+        return chipId;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+}
diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/SMACKTeachInResponse.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/SMACKTeachInResponse.java
new file mode 100644 (file)
index 0000000..b09dc58
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * 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.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
+    static final byte RESPONSE_TIME_HVALUE = 0;
+    static final byte RESPONSE_TIME_LVALUE = (byte) 0xFA;
+
+    static final byte TEACH_IN = 0x00;
+    static final byte TEACH_OUT = 0x20;
+    static final byte REPEATED_TEACH_IN = 0x01;
+    static final byte NOPLACE_FOR_MAILBOX = 0x12;
+    static final byte BAD_RSSI = 0x14;
+
+    public SMACKTeachInResponse() {
+        super(4, 0, new byte[] { Response.ResponseType.RET_OK.getValue(), RESPONSE_TIME_HVALUE, RESPONSE_TIME_LVALUE,
+                TEACH_IN });
+    }
+
+    public void setTeachOutResponse() {
+        data[3] = TEACH_OUT;
+    }
+
+    public boolean isTeachOut() {
+        return data[3] == TEACH_OUT;
+    }
+
+    public void setRepeatedTeachInResponse() {
+        data[3] = REPEATED_TEACH_IN;
+    }
+
+    public void setNoPlaceForFurtherMailbox() {
+        data[3] = NOPLACE_FOR_MAILBOX;
+    }
+
+    public void setBadRSSI() {
+        data[3] = BAD_RSSI;
+    }
+
+    public void setTeachIn() {
+        data[3] = TEACH_IN;
+    }
+
+    public boolean isTeachIn() {
+        return data[3] == TEACH_IN;
+    }
+}
index 298d1b1f06122baf295f4ac693f45fdd195f7641..145d8ae39db7d6aa9692790bd990e8b56f1cf039 100644 (file)
@@ -180,7 +180,7 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener {
         this.path = path;
     }
 
-    public void initilize()
+    public void initialize()
             throws UnsupportedCommOperationException, PortInUseException, IOException, TooManyListenersException {
         SerialPortManager localSerialPortManager = serialPortManager;
         if (localSerialPortManager == null) {
@@ -224,7 +224,7 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener {
         @Nullable
         Future<?> localReadingTask = readingTask;
         if (localReadingTask == null || localReadingTask.isCancelled()) {
-            localReadingTask = scheduler.submit(new Runnable() {
+            readingTask = scheduler.submit(new Runnable() {
                 @Override
                 public void run() {
                     receivePackets();
@@ -313,13 +313,24 @@ public abstract class EnOceanTransceiver implements SerialPortEventListener {
         InputStream localInputStream = inputStream;
         if (localInputStream != null) {
             try {
-                localInputStream.read(buffer, 0, length);
+                return localInputStream.read(buffer, 0, length);
             } catch (IOException e) {
                 logger.debug("IOException occured while reading the input stream", e);
                 return 0;
             }
+        } else {
+            logger.warn("Cannot read from null stream");
+            Future<?> localReadingTask = readingTask;
+            if (localReadingTask != null) {
+                localReadingTask.cancel(true);
+                readingTask = null;
+            }
+            TransceiverErrorListener localListener = errorListener;
+            if (localListener != null) {
+                localListener.errorOccured(new IOException("Cannot read from null stream"));
+            }
+            return 0;
         }
-        return 0;
     }
 
     protected void informListeners(BasePacket packet) {