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.fronius.internal.api;
15 import javax.measure.Unit;
17 import org.openhab.core.library.types.QuantityType;
18 import org.openhab.core.types.util.UnitUtils;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import com.google.gson.annotations.SerializedName;
25 * The {@link InverterRealtimeResponse} is responsible for storing
28 * @author Thomas Rokohl - Initial contribution
29 * @author Jimmy Tanagra - Add conversion to QuantityType
31 public class ValueUnit {
33 @SerializedName("Value")
35 @SerializedName("Unit")
36 private String unit = "";
38 public double getValue() {
42 public void setValue(double value) {
46 public String getUnit() {
47 return this.unit == null ? "" : this.unit;
50 public void setUnit(String unit) {
54 public QuantityType<?> asQuantityType() {
55 Unit<?> unit = UnitUtils.parseUnit(getUnit());
57 final Logger logger = LoggerFactory.getLogger(ValueUnit.class);
58 logger.debug("The unit for ValueUnit ({})/({}) cannot be parsed", value, this.unit);
59 unit = QuantityType.ONE.getUnit();
61 return new QuantityType<>(value, unit);