2 * Copyright (c) 2010-2023 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.onewire.internal.owserver;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
18 * The {@link OwserverTemperatureScale} provides the owserver protocol temperature scale flags
20 * @author Jan N. Klug - Initial contribution
24 public enum OwserverTemperatureScale {
25 CENTIGRADE(0x00000000),
26 FAHRENHEIT(0x00010000),
30 private static final int CLEAR_MASK = 0x00030000;
31 private final int flag;
33 OwserverTemperatureScale(int flag) {
38 * get numeric value of this flag
42 public int getValue() {
47 * set this flag in a set of given flags
49 * @param flags aggregated flags
50 * @return parameter with this flag set
52 public int setFlag(int flags) {
53 int tempFlags = flags;
54 tempFlags &= ~CLEAR_MASK;
55 tempFlags |= this.getValue();
60 * get the temperature scale flag from a given set of flags
62 * @param flags set of flags
63 * @return temperature scale flag
64 * @throws IllegalArgumentException
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) {