]> git.basschouten.com Git - openhab-addons.git/blob
ff175cb4fee4a3692e746845ab3bf5836b55f6e9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.tacmi.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * This enum holds all the different measures and states available to be
21  * retrieved by the TACmi binding, including the scale factors needed to convert the received values to the real
22  * numbers.
23  *
24  * @author Timo Wendt - Initial contribution
25  * @author Wolfgang Klimt - improvements
26  * @author Christian Niessner - Ported to OpenHAB2
27  */
28 @NonNullByDefault
29 public enum TACmiMeasureType {
30     NONE(0, 1),
31     TEMPERATURE(1, 10),
32     UNKNOWN2(2, 1),
33     UNKNOWN3(3, 1),
34     SECONDS(4, 1),
35     UNKNOWN5(5, 1),
36     UNKNOWN6(6, 1),
37     UNKNOWN7(7, 1),
38     UNKNOWN8(8, 1),
39     UNKNOWN9(9, 1),
40     KILOWATT(10, 100),
41     KILOWATTHOURS(11, 10),
42     MEGAWATTHOURS(12, 1),
43     UNKNOWN13(13, 1),
44     UNKNOWN14(14, 1),
45     UNKNOWN15(15, 1),
46     UNKNOWN16(16, 1),
47     UNKNOWN17(17, 1),
48     UNKNOWN18(18, 1),
49     UNKNOWN19(19, 1),
50     UNKNOWN20(20, 1),
51     UNKNOWN21(21, 1),
52
53     UNSUPPORTED(-1, 1);
54
55     private final int typeval;
56     private final int offset;
57
58     private static final Logger logger = LoggerFactory.getLogger(TACmiMeasureType.class);
59
60     private TACmiMeasureType(int typeval, int offset) {
61         this.typeval = typeval;
62         this.offset = offset;
63     }
64
65     public int getTypeValue() {
66         return typeval;
67     }
68
69     public int getOffset() {
70         return offset;
71     }
72
73     /**
74      * Return measure type for a specific int value
75      */
76     public static TACmiMeasureType fromInt(int type) {
77         for (TACmiMeasureType mtype : TACmiMeasureType.values()) {
78             if (mtype.getTypeValue() == type) {
79                 return mtype;
80             }
81         }
82         logger.debug("Received unexpected measure type {}", type);
83         return TACmiMeasureType.UNSUPPORTED;
84     }
85 }