]> git.basschouten.com Git - openhab-addons.git/blob
675b9eae060ec4e5936d1bf2a17ddb340f8b6dfc
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.onewire.internal.owserver;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link OwserverTemperatureScale} provides the owserver protocol temperature scale flags
19  *
20  * @author Jan N. Klug - Initial contribution
21  */
22
23 @NonNullByDefault
24 public enum OwserverTemperatureScale {
25     CENTIGRADE(0x00000000),
26     FAHRENHEIT(0x00010000),
27     KELVIN(0x00020000),
28     RANKINE(0x00030000);
29
30     private static final int CLEAR_MASK = 0x00030000;
31     private final int flag;
32
33     OwserverTemperatureScale(int flag) {
34         this.flag = flag;
35     }
36
37     /**
38      * get numeric value of this flag
39      *
40      * @return
41      */
42     public int getValue() {
43         return flag;
44     }
45
46     /**
47      * set this flag in a set of given flags
48      *
49      * @param flags aggregated flags
50      * @return parameter with this flag set
51      */
52     public int setFlag(int flags) {
53         int tempFlags = flags;
54         tempFlags &= ~CLEAR_MASK;
55         tempFlags |= this.getValue();
56         return tempFlags;
57     }
58
59     /**
60      * get the temperature scale flag from a given set of flags
61      *
62      * @param flags set of flags
63      * @return temperature scale flag
64      * @throws IllegalArgumentException
65      */
66     public static OwserverTemperatureScale getFlag(int flags) {
67         int tempFlags = flags;
68         tempFlags &= CLEAR_MASK;
69         for (OwserverTemperatureScale value : values()) {
70             if (value.getValue() == tempFlags) {
71                 return value;
72             }
73         }
74         return CENTIGRADE;
75     }
76 }