From: Gwendal Roulleau Date: Wed, 26 Jul 2023 11:21:59 +0000 (+0200) Subject: [enocean] Fix unusable bundle after a refactoring about null annotation (#15302) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=2961593cfd3d0b96f26a8742ce8b7fa4177d1255;p=openhab-addons.git [enocean] Fix unusable bundle after a refactoring about null annotation (#15302) Fix bundle unusable after #14023 (closes #15181) Fix a case issue with some directory Fix trigger channel issue Signed-off-by: Gwendal Roulleau --- diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java index d79601dc39..5924c7845a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/A5_20/A5_20_04.java @@ -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: diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_03/D2_03_0A.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_03/D2_03_0A.java index 824a5408f2..91ea0aa399 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_03/D2_03_0A.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_03/D2_03_0A.java @@ -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: diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_01.java index 8668c0ba6d..db4b35f5fa 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_01.java @@ -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()) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_50.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_50.java index 63ad5c71e0..d8a58c7c29 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_50.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/D2_06/D2_06_50.java @@ -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) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEP.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEP.java index 353f75670d..e5f832099b 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEP.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/EEP.java @@ -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; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_01/F6_01_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_01/F6_01_01.java index 60329e831d..14c6a9c90a 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_01/F6_01_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_01/F6_01_01.java @@ -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; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java index 3612690765..80e7db3496 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_01.java @@ -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)) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java index 514c07eab7..ed63201e81 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/eep/F6_02/F6_02_02.java @@ -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)) { diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseSensorHandler.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseSensorHandler.java index e26b3663f4..d242e0f292 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseSensorHandler.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBaseSensorHandler.java @@ -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; } diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java index cadb17f98d..0a4cb5f3f8 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/handler/EnOceanBridgeHandler.java @@ -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 index e1aa3642c1..0000000000 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/BaseResponse.java +++ /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 index c00672a897..0000000000 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDBaseIdResponse.java +++ /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 index 6c114878e8..0000000000 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDLearnedClientsResponse.java +++ /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 index d61ab7bfee..0000000000 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDRepeaterResponse.java +++ /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 index e041586aaf..0000000000 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/RDVersionResponse.java +++ /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 index b09dc58289..0000000000 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/Responses/SMACKTeachInResponse.java +++ /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 index 0000000000..e1aa3642c1 --- /dev/null +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/BaseResponse.java @@ -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 index 0000000000..c00672a897 --- /dev/null +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDBaseIdResponse.java @@ -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 index 0000000000..6c114878e8 --- /dev/null +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDLearnedClientsResponse.java @@ -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 index 0000000000..d61ab7bfee --- /dev/null +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDRepeaterResponse.java @@ -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 index 0000000000..e041586aaf --- /dev/null +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/RDVersionResponse.java @@ -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 index 0000000000..b09dc58289 --- /dev/null +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/messages/responses/SMACKTeachInResponse.java @@ -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; + } +} diff --git a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanTransceiver.java b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanTransceiver.java index 298d1b1f06..145d8ae39d 100644 --- a/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanTransceiver.java +++ b/bundles/org.openhab.binding.enocean/src/main/java/org/openhab/binding/enocean/internal/transceiver/EnOceanTransceiver.java @@ -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) {