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.openthermgateway.internal;
15 import javax.measure.Unit;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.library.types.DecimalType;
20 import org.openhab.core.library.types.QuantityType;
21 import org.openhab.core.types.State;
24 * The {@link FloatDataItem} represents a 2-byte float value in a 2's complement format.
26 * @author Arjen Korevaar - Initial contribution
29 public class FloatDataItem extends DataItem {
31 private @Nullable Unit<?> unit;
33 public @Nullable Unit<?> getUnit() {
37 public FloatDataItem(Msg msg, String subject) {
38 this(msg, subject, null, null);
41 public FloatDataItem(Msg msg, String subject, Unit<?> unit) {
42 this(msg, subject, unit, null);
45 public FloatDataItem(Msg msg, String subject, CodeType codetype) {
46 this(msg, subject, null, codetype);
49 public FloatDataItem(Msg msg, String subject, @Nullable Unit<?> unit, @Nullable CodeType codetype) {
50 super(msg, ByteType.BOTH, subject, codetype);
56 public State createState(Message message) {
58 Unit<?> unit = this.getUnit();
59 float value = message.getFloat();
60 return (unit == null) ? new DecimalType(value) : new QuantityType<>(value, unit);