]> git.basschouten.com Git - openhab-addons.git/blob
df58c3098d753168ef435124e0fd875952f45b6f
[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.ism8.server;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * The {@link DataPointByteValue} is the data points for byte values
22  *
23  * @author Hans-Reiner Hoffmann - Initial contribution
24  */
25 @NonNullByDefault
26 public class DataPointByteValue extends DataPointBase<@Nullable Byte> {
27     private final Logger logger = LoggerFactory.getLogger(DataPointByteValue.class);
28
29     public DataPointByteValue(int id, String knxDataType, String description) {
30         super(id, knxDataType, description);
31     }
32
33     @Override
34     public String getValueText() {
35         Object val = this.getValue();
36         return val != null ? val.toString() : "0";
37     }
38
39     @Override
40     public void processData(byte[] data) {
41         if (this.checkProcessData(data)) {
42             if (data[3] != 1 && data.length <= 4) {
43                 logger.debug("DataPoint-ProcessData: Data size wrong for this type({}/1).", data[3]);
44                 return;
45             }
46             this.setValue(data[4]);
47         }
48     }
49
50     @Override
51     protected byte[] convertWriteValue(Object value) {
52         this.setValue(Byte.parseByte(value.toString()));
53         return new byte[] { this.getValue() };
54     }
55 }