2 * Copyright (c) 2010-2022 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.lcn.internal.converter;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.lcn.internal.common.LcnException;
17 import org.openhab.core.library.types.DecimalType;
18 import org.openhab.core.library.types.QuantityType;
19 import org.openhab.core.types.State;
22 * Base class for all converters.
24 * @author Fabian Wolter - Initial Contribution
27 public class Converter {
29 * Converts a state update from the Thing into a human readable representational State.
31 * @param state from the Thing
32 * @return human readable representational State
33 * @throws LcnException
35 public State onStateUpdateFromHandler(State state) throws LcnException {
40 * Converts a human readable value into LCN native value.
42 * @param humanReadable value to convert
43 * @return the native LCN value
45 public DecimalType onCommandFromItem(double humanReadable) {
46 return new DecimalType(humanReadable);
50 * Converts a human readable value into LCN native value.
52 * @param humanReadable value to convert
53 * @return the native LCN value
54 * @throws LcnException when the value could not be converted to the base unit
56 public DecimalType onCommandFromItem(QuantityType<?> quantityType) throws LcnException {
57 return onCommandFromItem(quantityType.doubleValue());