2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lcn.internal.subhandler;
15 import java.util.Arrays;
16 import java.util.Collection;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.lcn.internal.LcnBindingConstants;
22 import org.openhab.binding.lcn.internal.LcnModuleHandler;
23 import org.openhab.binding.lcn.internal.common.LcnChannelGroup;
24 import org.openhab.binding.lcn.internal.common.LcnDefs;
25 import org.openhab.binding.lcn.internal.connection.ModInfo;
28 * Handles State changes of transponders and remote controls of an LCN module.
30 * @author Fabian Wolter - Initial contribution
33 public class LcnModuleCodeSubHandler extends AbstractLcnModuleSubHandler {
34 private static final Pattern TRANSPONDER_PATTERN = Pattern
35 .compile(LcnBindingConstants.ADDRESS_REGEX + "\\.ZT(?<byte0>\\d{3})(?<byte1>\\d{3})(?<byte2>\\d{3})");
36 private static final Pattern FINGERPRINT_PATTERN_HEX = Pattern.compile(LcnBindingConstants.ADDRESS_REGEX
37 + "\\.ZF(?<byte0>[0-9A-Fa-f]{2})(?<byte1>[0-9A-Fa-f]{2})(?<byte2>[0-9A-Fa-f]{2})$");
38 private static final Pattern FINGERPRINT_PATTERN_DEC = Pattern
39 .compile(LcnBindingConstants.ADDRESS_REGEX + "\\.ZF(?<byte0>\\d{3})(?<byte1>\\d{3})(?<byte2>\\d{3})");
40 private static final Pattern REMOTE_CONTROL_PATTERN = Pattern.compile(LcnBindingConstants.ADDRESS_REGEX
41 + "\\.ZI(?<byte0>\\d{3})(?<byte1>\\d{3})(?<byte2>\\d{3})(?<key>\\d{3})(?<action>\\d{3})");
43 public LcnModuleCodeSubHandler(LcnModuleHandler handler, ModInfo info) {
48 public void handleRefresh(LcnChannelGroup channelGroup, int number) {
53 public void handleStatusMessage(Matcher matcher) {
57 if (matcher.pattern() == FINGERPRINT_PATTERN_HEX) {
61 code = String.format("%02X%02X%02X", Integer.parseInt(matcher.group("byte0"), base),
62 Integer.parseInt(matcher.group("byte1"), base), Integer.parseInt(matcher.group("byte2"), base));
64 if (matcher.pattern() == TRANSPONDER_PATTERN) {
65 handler.triggerChannel(LcnChannelGroup.CODE, "transponder", code);
66 } else if (matcher.pattern() == FINGERPRINT_PATTERN_HEX || matcher.pattern() == FINGERPRINT_PATTERN_DEC) {
67 handler.triggerChannel(LcnChannelGroup.CODE, "fingerprint", code);
68 } else if (matcher.pattern() == REMOTE_CONTROL_PATTERN) {
69 int keyNumber = Integer.parseInt(matcher.group("key"));
75 } else if (keyNumber > 20) {
78 } else if (keyNumber > 10) {
81 } else if (keyNumber > 0) {
87 int action = Integer.parseInt(matcher.group("action"));
90 handler.triggerChannel(LcnChannelGroup.CODE, "remotecontrolbatterylow", code);
94 LcnDefs.SendKeyCommand actionType;
97 actionType = LcnDefs.SendKeyCommand.HIT;
100 actionType = LcnDefs.SendKeyCommand.MAKE;
103 actionType = LcnDefs.SendKeyCommand.BREAK;
109 handler.triggerChannel(LcnChannelGroup.CODE, "remotecontrolkey",
110 keyLayer + keyNumber + ":" + actionType.name());
112 handler.triggerChannel(LcnChannelGroup.CODE, "remotecontrolcode",
113 code + ":" + keyLayer + keyNumber + ":" + actionType.name());
118 public Collection<Pattern> getPckStatusMessagePatterns() {
119 return Arrays.asList(TRANSPONDER_PATTERN, FINGERPRINT_PATTERN_HEX, FINGERPRINT_PATTERN_DEC,
120 REMOTE_CONTROL_PATTERN);