diff --git a/addons/binding/org.openhab.binding.dsmr.test/META-INF/MANIFEST.MF b/addons/binding/org.openhab.binding.dsmr.test/META-INF/MANIFEST.MF
index 30f6f17cf7443..115ccb6a500a3 100644
--- a/addons/binding/org.openhab.binding.dsmr.test/META-INF/MANIFEST.MF
+++ b/addons/binding/org.openhab.binding.dsmr.test/META-INF/MANIFEST.MF
@@ -11,28 +11,15 @@ Fragment-Host: org.openhab.binding.dsmr
Import-Package:
org.apache.commons.io,
org.eclipse.jdt.annotation;resolution:=optional,
- org.eclipse.smarthome.core.common,
- org.eclipse.smarthome.core.common.registry,
- org.eclipse.smarthome.core.events,
org.eclipse.smarthome.core.thing,
- org.eclipse.smarthome.core.thing.binding,
- org.eclipse.smarthome.core.thing.binding.builder,
- org.eclipse.smarthome.core.thing.util,
org.eclipse.smarthome.io.transport.serial,
- org.eclipse.smarthome.test,
- org.eclipse.smarthome.test.java,
- org.eclipse.smarthome.test.storage,
org.hamcrest;core=split,
org.hamcrest.core,
org.junit,
org.mockito,
org.mockito.hamcrest,
org.mockito.invocation,
- org.mockito.stubbing,
- org.osgi.framework,
- org.osgi.service.component,
- org.osgi.service.device,
- org.slf4j
+ org.mockito.stubbing
Require-Bundle:
org.hamcrest,
org.junit
diff --git a/addons/binding/org.openhab.binding.dsmr.test/org.openhab.binding.dsmr.test.launch b/addons/binding/org.openhab.binding.dsmr.test/org.openhab.binding.dsmr.test.launch
index 6bac0ee1f82ba..a0180cf9ce4da 100644
--- a/addons/binding/org.openhab.binding.dsmr.test/org.openhab.binding.dsmr.test.launch
+++ b/addons/binding/org.openhab.binding.dsmr.test/org.openhab.binding.dsmr.test.launch
@@ -34,8 +34,8 @@
-
-
+
+
diff --git a/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/TelegramReaderUtil.java b/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/TelegramReaderUtil.java
index 5deb5232136c2..dea925a61c35f 100644
--- a/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/TelegramReaderUtil.java
+++ b/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/TelegramReaderUtil.java
@@ -12,7 +12,7 @@
*/
package org.openhab.binding.dsmr.internal;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
@@ -61,7 +61,9 @@ public static P1Telegram readTelegram(String telegramName, TelegramState expecte
byte[] telegram = readRawTelegram(telegramName);
P1TelegramParser parser = new P1TelegramParser(p1Telegram::set);
- parser.parseData(telegram, 0, telegram.length);
+ parser.setLenientMode(true);
+ parser.parse(telegram, telegram.length);
+ assertNotNull("Telegram state should have been set. (Missing newline at end of message?)", p1Telegram.get());
assertEquals("Expected TelegramState should be as expected", expectedTelegramState,
p1Telegram.get().getTelegramState());
return p1Telegram.get();
diff --git a/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/DSMRSerialAutoDeviceTest.java b/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/DSMRSerialAutoDeviceTest.java
index ee4ff8cf0292b..ef2b4018f6647 100644
--- a/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/DSMRSerialAutoDeviceTest.java
+++ b/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/DSMRSerialAutoDeviceTest.java
@@ -99,7 +99,7 @@ public void handleErrorEvent(@NonNull DSMRConnectorErrorEvent connectorErrorEven
try (InputStream inputStream = new ByteArrayInputStream(TelegramReaderUtil.readRawTelegram(TELEGRAM_NAME))) {
when(mockSerialPort.getInputStream()).thenReturn(inputStream);
DSMRSerialAutoDevice device = new DSMRSerialAutoDevice(serialPortManager, DUMMY_PORTNAME, listener,
- scheduler, 1);
+ new DSMRTelegramListener(), scheduler, 1);
device.start();
assertSame("Expect to be starting discovery state", DeviceState.DISCOVER_SETTINGS, device.getState());
serialPortEventListener
@@ -136,7 +136,7 @@ public void handleErrorEvent(@NonNull DSMRConnectorErrorEvent connectorErrorEven
throw new PortInUseException();
}).when(mockIdentifier).open(eq(DSMRBindingConstants.DSMR_PORT_NAME), anyInt());
DSMRSerialAutoDevice device = new DSMRSerialAutoDevice(serialPortManager, DUMMY_PORTNAME, listener,
- scheduler, 1);
+ new DSMRTelegramListener(), scheduler, 1);
device.start();
assertSame("Expected an error", DSMRConnectorErrorEvent.IN_USE, eventRef.get());
assertSame("Expect to be in error state", DeviceState.ERROR, device.getState());
@@ -146,7 +146,8 @@ public void handleErrorEvent(@NonNull DSMRConnectorErrorEvent connectorErrorEven
assertSame("Expect to be starting discovery state", DeviceState.DISCOVER_SETTINGS, device.getState());
// Trigger device to go into error stage with port doesn't exist.
mockIdentifier = null;
- device = new DSMRSerialAutoDevice(serialPortManager, DUMMY_PORTNAME, listener, scheduler, 1);
+ device = new DSMRSerialAutoDevice(serialPortManager, DUMMY_PORTNAME, listener, new DSMRTelegramListener(),
+ scheduler, 1);
device.start();
assertSame("Expected an error", DSMRConnectorErrorEvent.DONT_EXISTS, eventRef.get());
assertSame("Expect to be in error state", DeviceState.ERROR, device.getState());
diff --git a/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/SmartyDecrypterTest.java b/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/SmartyDecrypterTest.java
new file mode 100644
index 0000000000000..ba71133639c76
--- /dev/null
+++ b/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/SmartyDecrypterTest.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright (c) 2010-2018 by the respective copyright holders.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.openhab.binding.dsmr.internal.device;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.junit.Test;
+import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
+import org.openhab.binding.dsmr.internal.device.p1telegram.P1TelegramListener;
+import org.openhab.binding.dsmr.internal.device.p1telegram.P1TelegramParser;
+
+/**
+ * Test class for the {@link SmartyDecrypter}.
+ *
+ * @author Hilbrand Bouwkamp - Initial contribution
+ */
+@NonNullByDefault
+public class SmartyDecrypterTest {
+
+ private static final String KEY = "D491470F47126332B07D1923B3504188";
+ private static final int[] TELEGRAM = new int[] { 0xDB, 0x08, 0x53, 0x41, 0x47, 0x67, 0x70, 0x01, 0xBD, 0x54, 0x82,
+ 0x02, 0x7A, 0x30, 0x00, 0x05, 0xA8, 0xE3, 0x80, 0x6E, 0xE6, 0xE6, 0x39, 0x27, 0x4C, 0x7B, 0xC5, 0x70, 0x95,
+ 0xF8, 0x72, 0xB0, 0x8D, 0xDE, 0x62, 0x1F, 0xB7, 0x4E, 0xE8, 0x1E, 0x5E, 0xBE, 0x34, 0x2C, 0x93, 0xD8, 0xE7,
+ 0x37, 0x81, 0xFB, 0x2A, 0x1E, 0xB8, 0x71, 0x00, 0x74, 0xA5, 0x4F, 0xC5, 0x7A, 0xA7, 0xD1, 0xD9, 0x92, 0x36,
+ 0xC4, 0x2E, 0x2E, 0xC0, 0x1A, 0x03, 0x24, 0xEF, 0xC7, 0xF0, 0x2E, 0x3B, 0xA2, 0xFA, 0x43, 0x19, 0x6C, 0xA6,
+ 0x03, 0x83, 0x8A, 0xB8, 0x32, 0x2D, 0xFF, 0xA8, 0x3F, 0x7E, 0x83, 0x93, 0x2E, 0x60, 0x07, 0x40, 0x6B, 0x11,
+ 0x2B, 0x41, 0x74, 0x5F, 0x38, 0x80, 0x56, 0x46, 0xD5, 0x3F, 0xEA, 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 0xF2, 0x85, 0x0F, 0x17, };
+
+ /**
+ * Tests decrypting of a single complete Smarty telegram.
+ */
+ @Test
+ public void testSmartyDecrypter() {
+ AtomicReference telegramResult = new AtomicReference("");
+ P1TelegramListener telegramListener = telegram -> telegramResult.set(telegram.getRawTelegram());
+ SmartyDecrypter decoder = new SmartyDecrypter(new P1TelegramParser(telegramListener),
+ new DSMRTelegramListener(KEY), KEY);
+ decoder.setLenientMode(true);
+ byte[] data = new byte[TELEGRAM.length];
+
+ for (int i = 0; i < TELEGRAM.length; i++) {
+ data[i] = (byte) TELEGRAM[i];
+ }
+
+ decoder.parse(data, data.length);
+ String expected = new String(TelegramReaderUtil.readRawTelegram("smarty"), StandardCharsets.UTF_8);
+
+ assertThat("Should have correctly decrypted the telegram", telegramResult.get(), is(equalTo(expected)));
+ }
+}
diff --git a/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/p1telegram/P1TelegramParserTest.java b/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/p1telegram/P1TelegramParserTest.java
index 5f44b0f49a2ea..1b099f3569db1 100644
--- a/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/p1telegram/P1TelegramParserTest.java
+++ b/addons/binding/org.openhab.binding.dsmr.test/src/test/java/org/openhab/binding/dsmr/internal/device/p1telegram/P1TelegramParserTest.java
@@ -45,7 +45,7 @@ public static final List