]> git.basschouten.com Git - openhab-addons.git/blob
66487e51807f5aba135e8861a4aebea83429e91b
[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.openthermgateway.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.types.State;
18
19 /**
20  * The {@link DataItem} represents the base dataitem.
21  *
22  * @author Arjen Korevaar - Initial contribution
23  */
24
25 @NonNullByDefault
26 public abstract class DataItem {
27     private Msg msg;
28     private ByteType byteType;
29     private String subject;
30     private @Nullable CodeType codeType;
31
32     public Msg getMsg() {
33         return msg;
34     }
35
36     public ByteType getByteType() {
37         return byteType;
38     }
39
40     public String getSubject() {
41         return subject;
42     }
43
44     public @Nullable CodeType getCodeType() {
45         return codeType;
46     }
47
48     public DataItem(Msg msg, ByteType byteType, String subject, @Nullable CodeType codeType) {
49         this.msg = msg;
50         this.byteType = byteType;
51         this.subject = subject;
52         this.codeType = codeType;
53     }
54
55     public boolean hasValidCodeType(Message message) {
56         // Used to bind a dataitem to a specific TBRA code
57         @Nullable
58         CodeType code = this.getCodeType();
59
60         return (code == null || code == message.getCodeType());
61     }
62
63     /**
64      * @param message unused in this default implementation
65      * @return the channel id
66      */
67     public String getChannelId(Message message) {
68         // Default implementation
69         return subject;
70     }
71
72     public abstract State createState(Message message);
73 }