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.omnilink.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
17 import com.digitaldan.jomnilinkII.MessageUtils;
20 * The {@link TemperatureFormat} defines some methods that are used to
21 * convert OmniLink temperature values into Fahrenheit or Celsius.
23 * @author Craig Hamilton - Initial contribution
24 * @author Ethan Dye - openHAB3 rewrite
27 public enum TemperatureFormat {
28 // Don't convert zero - it appears that is what omni returns when there is no value.
31 public float omniToFormat(int omniNumber) {
32 return MessageUtils.omniToC(omniNumber);
36 public int formatToOmni(float celsius) {
37 return MessageUtils.CToOmni(celsius);
42 public float omniToFormat(int omniNumber) {
43 return MessageUtils.omniToF(omniNumber);
47 public int formatToOmni(float fahrenheit) {
48 return MessageUtils.FtoOmni(fahrenheit);
52 private final int formatNumber;
54 private TemperatureFormat(int formatNumber) {
55 this.formatNumber = formatNumber;
59 * Convert a number represented by the omni to the format.
61 * @param omniNumber Number to convert
62 * @return Number converted to appropriate format.
64 public abstract float omniToFormat(int omniNumber);
67 * Convert a number from this format into an omni number.
69 * @param format Number in the current format.
70 * @return Omni formatted number.
72 public abstract int formatToOmni(float format);
75 * Get the number which identifies this format as defined by the OmniLink protocol.
77 * @return Number which identifies this temperature format.
79 public int getFormatNumber() {
83 public static TemperatureFormat valueOf(int tempFormat) {
84 if (tempFormat == CELSIUS.formatNumber) {
86 } else if (tempFormat == FAHRENHEIT.formatNumber) {
89 throw new IllegalArgumentException("Invalid temperature format!");