]> git.basschouten.com Git - openhab-addons.git/blob
8e7ad6f8a61d8702b6fb738905bcda5e823927c2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lcn.internal.subhandler;
14
15 import java.util.Collection;
16 import java.util.Set;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
19
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.connection.ModInfo;
25
26 /**
27  * Handles serial number and firmware versions received from an LCN module.
28  *
29  * @author Fabian Wolter - Initial contribution
30  */
31 @NonNullByDefault
32 public class LcnModuleMetaFirmwareSubHandler extends AbstractLcnModuleSubHandler {
33     /** The pattern for the serial number and firmware PCK message */
34     public static final Pattern PATTERN = Pattern.compile(LcnBindingConstants.ADDRESS_REGEX
35             + "\\.SN(?<sn>[0-9|A-F]{10})(?<manu>[0-9|A-F]{2})FW(?<firmwareVersion>[0-9|A-F]{6})HW(?<hwType>\\d+)");
36
37     public LcnModuleMetaFirmwareSubHandler(LcnModuleHandler handler, ModInfo info) {
38         super(handler, info);
39     }
40
41     @Override
42     public void handleRefresh(LcnChannelGroup channelGroup, int number) {
43         // nothing
44     }
45
46     @Override
47     public void handleStatusMessage(Matcher matcher) {
48         info.setFirmwareVersion(Integer.parseInt(matcher.group("firmwareVersion"), 16));
49         handler.updateSerialNumberProperty(matcher.group("sn"));
50         handler.updateFirmwareVersionProperty(matcher.group("firmwareVersion"));
51     }
52
53     @Override
54     public Collection<Pattern> getPckStatusMessagePatterns() {
55         return Set.of(PATTERN);
56     }
57 }