]> git.basschouten.com Git - openhab-addons.git/blob
7b4c034fd1070c685fb5b31dc67e6cbccd7bf422
[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      * @throws LcnException
34      */
35     public State onStateUpdateFromHandler(State state) throws LcnException {
36         return state;
37     }
38
39     /**
40      * Converts a human readable value into LCN native value.
41      *
42      * @param humanReadable value to convert
43      * @return the native LCN value
44      */
45     public DecimalType onCommandFromItem(double humanReadable) {
46         return new DecimalType(humanReadable);
47     }
48
49     /**
50      * Converts a human readable value into LCN native value.
51      *
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
55      */
56     public DecimalType onCommandFromItem(QuantityType<?> quantityType) throws LcnException {
57         return onCommandFromItem(quantityType.doubleValue());
58     }
59 }