]> git.basschouten.com Git - openhab-addons.git/blob
6e42d974ad93d42b5ffac37a7bb2fa438e493463
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lcn.internal.converter;
14
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;
20
21 /**
22  * Base class for all converters.
23  *
24  * @author Fabian Wolter - Initial Contribution
25  */
26 @NonNullByDefault
27 public class Converter {
28     /**
29      * Converts a state update from the Thing into a human readable representational State.
30      *
31      * @param state from the Thing
32      * @return human readable representational State
33      */
34     public State onStateUpdateFromHandler(State state) {
35         return state;
36     }
37
38     /**
39      * Converts a human readable value into LCN native value.
40      *
41      * @param humanReadable value to convert
42      * @return the native LCN value
43      */
44     public DecimalType onCommandFromItem(double humanReadable) {
45         return new DecimalType(humanReadable);
46     }
47
48     /**
49      * Converts a human readable value into LCN native value.
50      *
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
54      */
55     public DecimalType onCommandFromItem(QuantityType<?> quantityType) throws LcnException {
56         return onCommandFromItem(quantityType.doubleValue());
57     }
58 }