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 UIntDataItem} represents an 8 or 16 bit unsigned integer.
26 * @author Arjen Korevaar - Initial contribution
29 public class UIntDataItem extends DataItem {
31 private @Nullable Unit<?> unit;
33 public @Nullable Unit<?> getUnit() {
37 public UIntDataItem(Msg msg, ByteType byteType, String subject) {
38 this(msg, byteType, subject, null);
41 public UIntDataItem(Msg msg, ByteType byteType, String subject, @Nullable Unit<?> unit) {
42 super(msg, byteType, subject, null);
48 public State createState(Message message) {
50 Unit<?> unit = getUnit();
51 int value = message.getUInt(super.getByteType());
52 return (unit == null) ? new DecimalType(value) : new QuantityType<>(value, unit);