]> git.basschouten.com Git - openhab-addons.git/blob
26885e3340520bf64a2505ed83aa8cac654a81f4
[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.Collections;
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.common.LcnException;
25 import org.openhab.binding.lcn.internal.common.Variable;
26 import org.openhab.binding.lcn.internal.connection.ModInfo;
27 import org.openhab.core.library.types.DecimalType;
28
29 /**
30  * Handles Commands and State changes of S0 counter inputs of an LCN module.
31  *
32  * @author Fabian Wolter - Initial contribution
33  */
34 @NonNullByDefault
35 public class LcnModuleS0CounterSubHandler extends AbstractLcnModuleVariableSubHandler {
36     private static final Pattern PATTERN = Pattern
37             .compile(LcnBindingConstants.ADDRESS_REGEX + "\\.C(?<id>\\d)(?<value>\\d+)");
38
39     public LcnModuleS0CounterSubHandler(LcnModuleHandler handler, ModInfo info) {
40         super(handler, info);
41     }
42
43     @Override
44     public void handleCommandDecimal(DecimalType command, LcnChannelGroup channelGroup, int number)
45             throws LcnException {
46         throw new LcnException("Setting S0 counters is not supported");
47     }
48
49     @Override
50     public void handleStatusMessage(Matcher matcher) throws LcnException {
51         fireUpdateAndReset(matcher, "", Variable.s0IdToVar(Integer.parseInt(matcher.group("id")) - 1));
52     }
53
54     @Override
55     public Collection<Pattern> getPckStatusMessagePatterns() {
56         return Collections.singleton(PATTERN);
57     }
58 }