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
34 public State onStateUpdateFromHandler(State state) {
39 * Converts a human readable value into LCN native value.
41 * @param humanReadable value to convert
42 * @return the native LCN value
44 public DecimalType onCommandFromItem(double humanReadable) {
45 return new DecimalType(humanReadable);
49 * Converts a human readable value into LCN native value.
51 * @param humanReadable value to convert
52 * @return the native LCN value
53 * @throws LcnException when the value could not be converted to the base unit
55 public DecimalType onCommandFromItem(QuantityType<?> quantityType) throws LcnException {
56 return onCommandFromItem(quantityType.doubleValue());