]> git.basschouten.com Git - openhab-addons.git/blob
e03c92b0e05add74933b2d58c0099388578c590e
[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.dsmr.internal.device.cosem;
14
15 import java.text.ParseException;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.types.State;
19
20 /**
21  * This CosemValueDescriptor provides meta data for a CosemValue
22  *
23  * @author M. Volaart - Initial contribution
24  */
25 @NonNullByDefault
26 abstract class CosemValueDescriptor<S extends State> {
27
28     /**
29      * String describing the channel on which this value descriptor is available.
30      */
31     private final String channelId;
32
33     /**
34      * Creates a new {@link CosemValueDescriptor} with no unit and a default channel.
35      */
36     public CosemValueDescriptor() {
37         this("");
38     }
39
40     /**
41      * Creates a new {@link CosemValueDescriptor}.
42      *
43      * @param channelId the channel for this CosemValueDescriptor
44      */
45     public CosemValueDescriptor(String channelId) {
46         this.channelId = channelId;
47     }
48
49     /**
50      * Parses the string value to the {@link State} value
51      *
52      * @param CosemValue the Cosem value to parse
53      * @return S the {@link State} object instance of the Cosem value
54      * @throws ParseException if parsing failed
55      */
56     protected abstract S getStateValue(String cosemValue) throws ParseException;
57
58     /**
59      * Returns the channel id for this {@link CosemValueDescriptor}
60      *
61      * @return the channel identifier
62      */
63     public String getChannelId() {
64         return channelId;
65     }
66
67     /**
68      * Returns String representation of this {@link CosemValueDescriptor}
69      *
70      * @return String representation of this {@link CosemValueDescriptor}
71      */
72     @Override
73     public String toString() {
74         return "CosemValueDescriptor[channel=" + channelId + "]";
75     }
76 }