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