]> git.basschouten.com Git - openhab-addons.git/blob
4844ef709e743c0ff2451b227dedd6e22487e3aa
[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.openhab.core.library.types.DecimalType;
17 import org.openhab.core.types.State;
18
19 /**
20  * The {@link TspFhbValueDataItem} represents a transparent slave parameter or fault history buffer value.
21  *
22  * @author Arjen Korevaar - Initial contribution
23  */
24 @NonNullByDefault
25 public class TspFhbValueDataItem extends DataItem {
26
27     public TspFhbValueDataItem(Msg msg, String subject) {
28         super(msg, ByteType.BOTH, subject, null);
29     }
30
31     @Override
32     public String getChannelId(Message message) {
33         // With TSP or FHB values, the index is HIGHBYTE, the value is LOWBYTE
34         int index = message.getUInt(ByteType.HIGHBYTE);
35         return getChannelId(index);
36     }
37
38     public String getChannelId(int index) {
39         return super.getSubject() + "_" + index;
40     }
41
42     public String getLabel(int index) {
43         return super.getSubject() + " " + index;
44     }
45
46     @Override
47     public State createState(Message message) {
48         // With TSP or FHB values, the index is HIGHBYTE, the value is LOWBYTE
49         // TSP values are treated as Number:Dimensionless
50         return new DecimalType(message.getUInt(ByteType.LOWBYTE));
51     }
52 }