2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ism8.server;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * The {@link DataPointScaling} is the data points for scaling values
23 * @author Hans-Reiner Hoffmann - Initial contribution
26 public class DataPointScaling extends DataPointBase<@Nullable Double> {
27 private final Logger logger = LoggerFactory.getLogger(DataPointScaling.class);
28 private String outputFormat = "";
30 public DataPointScaling(int id, String knxDataType, String description) {
31 super(id, knxDataType, description);
33 this.outputFormat = "%.1f";
37 public String getValueText() {
38 return String.format(this.outputFormat, this.getValue());
42 public void processData(byte[] data) {
43 if (this.checkProcessData(data)) {
44 if (data[3] != 1 && data.length <= 4) {
45 logger.debug("DataPoint-ProcessData: Data size wrong for this type({}/1).", data[3]);
49 this.setValue((Byte.toUnsignedInt(data[4]) * 100.0) / 255.0);
54 protected byte[] convertWriteValue(Object value) {
55 this.setValue(Math.max(Math.min(Double.parseDouble(value.toString()), 100), 0));
56 Object rawVal = this.getValue();
57 double rawValResult = rawVal != null ? (Double) rawVal : 0.0;
58 byte val = (byte) (rawValResult / 100.0 * 255.0);
59 return new byte[] { val };