[LCN] Fixes problems with fingerprint codes which were received in decimal (#15488)
* fixed problems with fingerprint codes which were received in decimal instead of hex Signed-off-by: Andre Jendrysseck <ajendry@gwdg.de> * correct format issues Signed-off-by: Andre Jendrysseck <ajendry@gwdg.de> * add test file for fingerprint codes Signed-off-by: Andre Jendrysseck <ajendry@gwdg.de> * Delete openhab-addons.code-workspace Signed-off-by: Andre Jendrysseck <ajendry@gwdg.de> --------- Signed-off-by: Andre Jendrysseck <ajendry@gwdg.de> Co-authored-by: Andre Jendrysseck <ajendry@gwdg.de>
This commit is contained in:
parent
5ab172ed1c
commit
5e8e097ad4
|
@ -33,8 +33,10 @@ import org.openhab.binding.lcn.internal.connection.ModInfo;
|
||||||
public class LcnModuleCodeSubHandler extends AbstractLcnModuleSubHandler {
|
public class LcnModuleCodeSubHandler extends AbstractLcnModuleSubHandler {
|
||||||
private static final Pattern TRANSPONDER_PATTERN = Pattern
|
private static final Pattern TRANSPONDER_PATTERN = Pattern
|
||||||
.compile(LcnBindingConstants.ADDRESS_REGEX + "\\.ZT(?<byte0>\\d{3})(?<byte1>\\d{3})(?<byte2>\\d{3})");
|
.compile(LcnBindingConstants.ADDRESS_REGEX + "\\.ZT(?<byte0>\\d{3})(?<byte1>\\d{3})(?<byte2>\\d{3})");
|
||||||
private static final Pattern FINGERPRINT_PATTERN = Pattern.compile(LcnBindingConstants.ADDRESS_REGEX
|
private static final Pattern FINGERPRINT_PATTERN_HEX = Pattern.compile(LcnBindingConstants.ADDRESS_REGEX
|
||||||
+ "\\.ZF(?<byte0>[0-9A-Fa-f]{2})(?<byte1>[0-9A-Fa-f]{2})(?<byte2>[0-9A-Fa-f]{2})");
|
+ "\\.ZF(?<byte0>[0-9A-Fa-f]{2})(?<byte1>[0-9A-Fa-f]{2})(?<byte2>[0-9A-Fa-f]{2})$");
|
||||||
|
private static final Pattern FINGERPRINT_PATTERN_DEC = Pattern
|
||||||
|
.compile(LcnBindingConstants.ADDRESS_REGEX + "\\.ZF(?<byte0>\\d{3})(?<byte1>\\d{3})(?<byte2>\\d{3})");
|
||||||
private static final Pattern REMOTE_CONTROL_PATTERN = Pattern.compile(LcnBindingConstants.ADDRESS_REGEX
|
private static final Pattern REMOTE_CONTROL_PATTERN = Pattern.compile(LcnBindingConstants.ADDRESS_REGEX
|
||||||
+ "\\.ZI(?<byte0>\\d{3})(?<byte1>\\d{3})(?<byte2>\\d{3})(?<key>\\d{3})(?<action>\\d{3})");
|
+ "\\.ZI(?<byte0>\\d{3})(?<byte1>\\d{3})(?<byte2>\\d{3})(?<key>\\d{3})(?<action>\\d{3})");
|
||||||
|
|
||||||
|
@ -51,7 +53,7 @@ public class LcnModuleCodeSubHandler extends AbstractLcnModuleSubHandler {
|
||||||
public void handleStatusMessage(Matcher matcher) {
|
public void handleStatusMessage(Matcher matcher) {
|
||||||
String code;
|
String code;
|
||||||
|
|
||||||
if (matcher.pattern() == FINGERPRINT_PATTERN) {
|
if (matcher.pattern() == FINGERPRINT_PATTERN_HEX) {
|
||||||
code = String.format("%02X%02X%02X", Integer.parseInt(matcher.group("byte0"), 16),
|
code = String.format("%02X%02X%02X", Integer.parseInt(matcher.group("byte0"), 16),
|
||||||
Integer.parseInt(matcher.group("byte1"), 16), Integer.parseInt(matcher.group("byte2"), 16));
|
Integer.parseInt(matcher.group("byte1"), 16), Integer.parseInt(matcher.group("byte2"), 16));
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,7 +63,7 @@ public class LcnModuleCodeSubHandler extends AbstractLcnModuleSubHandler {
|
||||||
|
|
||||||
if (matcher.pattern() == TRANSPONDER_PATTERN) {
|
if (matcher.pattern() == TRANSPONDER_PATTERN) {
|
||||||
handler.triggerChannel(LcnChannelGroup.CODE, "transponder", code);
|
handler.triggerChannel(LcnChannelGroup.CODE, "transponder", code);
|
||||||
} else if (matcher.pattern() == FINGERPRINT_PATTERN) {
|
} else if (matcher.pattern() == FINGERPRINT_PATTERN_HEX || matcher.pattern() == FINGERPRINT_PATTERN_DEC) {
|
||||||
handler.triggerChannel(LcnChannelGroup.CODE, "fingerprint", code);
|
handler.triggerChannel(LcnChannelGroup.CODE, "fingerprint", code);
|
||||||
} else if (matcher.pattern() == REMOTE_CONTROL_PATTERN) {
|
} else if (matcher.pattern() == REMOTE_CONTROL_PATTERN) {
|
||||||
int keyNumber = Integer.parseInt(matcher.group("key"));
|
int keyNumber = Integer.parseInt(matcher.group("key"));
|
||||||
|
@ -114,6 +116,7 @@ public class LcnModuleCodeSubHandler extends AbstractLcnModuleSubHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Pattern> getPckStatusMessagePatterns() {
|
public Collection<Pattern> getPckStatusMessagePatterns() {
|
||||||
return Arrays.asList(TRANSPONDER_PATTERN, FINGERPRINT_PATTERN, REMOTE_CONTROL_PATTERN);
|
return Arrays.asList(TRANSPONDER_PATTERN, FINGERPRINT_PATTERN_HEX, FINGERPRINT_PATTERN_DEC,
|
||||||
|
REMOTE_CONTROL_PATTERN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/**
|
||||||
|
* 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.lcn.internal.subhandler;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.openhab.binding.lcn.internal.common.LcnChannelGroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class.
|
||||||
|
*
|
||||||
|
* @author Andre Jendrysseck - Initial contribution
|
||||||
|
*/
|
||||||
|
@NonNullByDefault
|
||||||
|
public class LcnModuleCodeSubHandlerTest extends AbstractTestLcnModuleSubHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() {
|
||||||
|
super.setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHexFingerprint() {
|
||||||
|
tryParseAllHandlers("=M000005.ZFABCDEF");
|
||||||
|
verify(handler).triggerChannel(LcnChannelGroup.CODE, "fingerprint", "ABCDEF");
|
||||||
|
verify(handler).triggerChannel(any(), any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDecFingerprint() {
|
||||||
|
tryParseAllHandlers("=M000005.ZF255255255");
|
||||||
|
verify(handler).triggerChannel(LcnChannelGroup.CODE, "fingerprint", "FFFFFF");
|
||||||
|
verify(handler).triggerChannel(any(), any(), any());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue