]> git.basschouten.com Git - openhab-addons.git/blob
4a0892c00f89eee71046b54b771f1f9ac00a1a7c
[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.knx.internal.channel;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 import tuwien.auto.calimero.GroupAddress;
19 import tuwien.auto.calimero.KNXFormatException;
20
21 /**
22  * Base class for telegram meta-data
23  *
24  * @author Simon Kaufmann - initial contribution and API.
25  *
26  */
27 @NonNullByDefault
28 public abstract class AbstractSpec {
29
30     private String dpt;
31
32     protected AbstractSpec(@Nullable ChannelConfiguration channelConfiguration, String defaultDPT) {
33         if (channelConfiguration != null) {
34             String configuredDPT = channelConfiguration.getDPT();
35             this.dpt = configuredDPT != null ? configuredDPT : defaultDPT;
36         } else {
37             this.dpt = defaultDPT;
38         }
39     }
40
41     /**
42      * Helper method to convert a {@link GroupAddressConfiguration} into a {@link GroupAddress}.
43      *
44      * @param ga the group address configuration
45      * @return a group address object
46      */
47     protected final GroupAddress toGroupAddress(GroupAddressConfiguration ga) {
48         try {
49             return new GroupAddress(ga.getGA());
50         } catch (KNXFormatException e) {
51             throw new IllegalArgumentException(e);
52         }
53     }
54
55     /**
56      * Return the data point type.
57      * <p>
58      * See {@link org.openhab.binding.knx.internal.client.InboundSpec#getDPT()} and
59      * {@link org.openhab.binding.knx.internal.client.OutboundSpec#getDPT()}.
60      *
61      * @return the data point type.
62      */
63     public final String getDPT() {
64         return dpt;
65     }
66 }