]> git.basschouten.com Git - openhab-addons.git/commitdiff
[OmniLink] Minor restructuring of binding code (#10280)
authorEthan Dye <mrtops03@gmail.com>
Tue, 16 Mar 2021 19:51:25 +0000 (13:51 -0600)
committerGitHub <noreply@github.com>
Tue, 16 Mar 2021 19:51:25 +0000 (20:51 +0100)
* Minor restructuring of binding code

Signed-off-by: Ethan Dye <mrtops03@gmail.com>
* Ensure that SystemType is present before switch

Signed-off-by: Ethan Dye <mrtops03@gmail.com>
* Log on invalid System Type

Signed-off-by: Ethan Dye <mrtops03@gmail.com>
18 files changed:
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/SystemType.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/TemperatureFormat.java [new file with mode: 0644]
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/discovery/ObjectPropertyRequest.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/discovery/OmnilinkDiscoveryService.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/exceptions/BridgeOfflineException.java [new file with mode: 0644]
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractAreaHandler.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AbstractOmnilinkHandler.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AudioSourceHandler.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/AudioZoneHandler.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/BridgeOfflineException.java [deleted file]
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/HumiditySensorHandler.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/LockHandler.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/OmnilinkBridgeHandler.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/TempSensorHandler.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/TemperatureFormat.java [deleted file]
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/ThermostatHandler.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/UnitHandler.java
bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/ZoneHandler.java

index 5ac9cf644dfd1663d32d870331d386e3284977d1..a17159463b54ba7562ecd6c0c8fe12b81f7fa757 100644 (file)
@@ -13,6 +13,7 @@
 package org.openhab.binding.omnilink.internal;
 
 import java.util.Arrays;
+import java.util.Optional;
 import java.util.Set;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -34,8 +35,7 @@ public enum SystemType {
         this.modelNumbers = Set.of(modelNumbers);
     }
 
-    public static SystemType getType(int modelNumber) {
-        return Arrays.stream(values()).filter(s -> s.modelNumbers.contains(modelNumber)).findFirst()
-                .orElseThrow(IllegalArgumentException::new);
+    public static Optional<SystemType> getType(int modelNumber) {
+        return Arrays.stream(values()).filter(s -> s.modelNumbers.contains(modelNumber)).findFirst();
     }
 }
diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/TemperatureFormat.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/TemperatureFormat.java
new file mode 100644 (file)
index 0000000..58f02af
--- /dev/null
@@ -0,0 +1,92 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.omnilink.internal;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+import com.digitaldan.jomnilinkII.MessageUtils;
+
+/**
+ * The {@link TemperatureFormat} defines some methods that are used to
+ * convert OmniLink temperature values into Fahrenheit or Celsius.
+ *
+ * @author Craig Hamilton - Initial contribution
+ * @author Ethan Dye - openHAB3 rewrite
+ */
+@NonNullByDefault
+public enum TemperatureFormat {
+    // Don't convert zero - it appears that is what omni returns when there is no value.
+    CELSIUS(2) {
+        @Override
+        public float omniToFormat(int omniNumber) {
+            return MessageUtils.omniToC(omniNumber);
+        }
+
+        @Override
+        public int formatToOmni(float celsius) {
+            return MessageUtils.CToOmni(celsius);
+        }
+    },
+    FAHRENHEIT(1) {
+        @Override
+        public float omniToFormat(int omniNumber) {
+            return MessageUtils.omniToF(omniNumber);
+        }
+
+        @Override
+        public int formatToOmni(float fahrenheit) {
+            return MessageUtils.FtoOmni(fahrenheit);
+        }
+    };
+
+    private final int formatNumber;
+
+    private TemperatureFormat(int formatNumber) {
+        this.formatNumber = formatNumber;
+    }
+
+    /**
+     * Convert a number represented by the omni to the format.
+     *
+     * @param omniNumber Number to convert
+     * @return Number converted to appropriate format.
+     */
+    public abstract float omniToFormat(int omniNumber);
+
+    /**
+     * Convert a number from this format into an omni number.
+     *
+     * @param format Number in the current format.
+     * @return Omni formatted number.
+     */
+    public abstract int formatToOmni(float format);
+
+    /**
+     * Get the number which identifies this format as defined by the omniprotocol.
+     *
+     * @return Number which identifies this temperature format.
+     */
+    public int getFormatNumber() {
+        return formatNumber;
+    }
+
+    public static TemperatureFormat valueOf(int tempFormat) {
+        if (tempFormat == CELSIUS.formatNumber) {
+            return CELSIUS;
+        } else if (tempFormat == FAHRENHEIT.formatNumber) {
+            return FAHRENHEIT;
+        } else {
+            throw new IllegalArgumentException("Invalid temperature format!");
+        }
+    }
+}
index 7cf1dd8a2a65f52ef54f6bc24e307c717531bf4a..f44c8e12b6ebae5c716c6ee81ab20c109f8a0198 100644 (file)
@@ -17,7 +17,7 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.openhab.binding.omnilink.internal.handler.BridgeOfflineException;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.binding.omnilink.internal.handler.OmnilinkBridgeHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index 86ceadf7c6986170372e76c6339ae2a6cfed3bd6..e796ad66112c4b76e759ca22eaa06642fd555b13 100644 (file)
@@ -21,11 +21,12 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.omnilink.internal.SystemType;
-import org.openhab.binding.omnilink.internal.handler.BridgeOfflineException;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.binding.omnilink.internal.handler.OmnilinkBridgeHandler;
 import org.openhab.core.config.discovery.AbstractDiscoveryService;
 import org.openhab.core.config.discovery.DiscoveryResult;
@@ -62,7 +63,7 @@ public class OmnilinkDiscoveryService extends AbstractDiscoveryService
     private final Logger logger = LoggerFactory.getLogger(OmnilinkDiscoveryService.class);
     private static final int DISCOVER_TIMEOUT_SECONDS = 30;
     private @Nullable OmnilinkBridgeHandler bridgeHandler;
-    private @Nullable SystemType systemType;
+    private Optional<SystemType> systemType = Optional.empty();
     private @Nullable List<AreaProperties> areas;
 
     /**
@@ -389,7 +390,6 @@ public class OmnilinkDiscoveryService extends AbstractDiscoveryService
                 int thingNumber = areaProperties.getNumber();
                 String thingName = areaProperties.getName();
                 String thingID = Integer.toString(thingNumber);
-                ThingUID thingUID = null;
 
                 /*
                  * It seems that for simple OmniLink Controller configurations there
@@ -405,27 +405,24 @@ public class OmnilinkDiscoveryService extends AbstractDiscoveryService
 
                 Map<String, Object> properties = Map.of(THING_PROPERTIES_NAME, thingName);
 
-                final SystemType systemType = this.systemType;
-                if (systemType != null) {
-                    switch (systemType) {
+                final String name = thingName;
+                systemType.ifPresentOrElse(t -> {
+                    ThingUID thingUID = null;
+                    switch (t) {
                         case LUMINA:
                             thingUID = new ThingUID(THING_TYPE_LUMINA_AREA, bridgeUID, thingID);
                             break;
-                        case OMNI:
-                            thingUID = new ThingUID(THING_TYPE_OMNI_AREA, bridgeUID, thingID);
-                            break;
                         default:
-                            throw new IllegalStateException("Unknown System Type");
+                            thingUID = new ThingUID(THING_TYPE_OMNI_AREA, bridgeUID, thingID);
                     }
-                }
-
-                if (thingUID != null) {
                     DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties)
                             .withProperty(THING_PROPERTIES_NUMBER, thingID)
-                            .withRepresentationProperty(THING_PROPERTIES_NUMBER).withBridge(bridgeUID)
-                            .withLabel(thingName).build();
+                            .withRepresentationProperty(THING_PROPERTIES_NUMBER).withBridge(bridgeUID).withLabel(name)
+                            .build();
                     thingDiscovered(discoveryResult);
-                }
+                }, () -> {
+                    logger.warn("Unknown System Type");
+                });
 
                 areas.add(areaProperties);
             }
diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/exceptions/BridgeOfflineException.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/exceptions/BridgeOfflineException.java
new file mode 100644 (file)
index 0000000..7b35721
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.omnilink.internal.exceptions;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * The {@link BridgeOfflineException} defines an exception for when the OmniLink
+ * Bridge is offline or unavailable.
+ *
+ * @author Craig Hamilton - Initial contribution
+ */
+@NonNullByDefault
+@SuppressWarnings("serial")
+public class BridgeOfflineException extends Exception {
+    public BridgeOfflineException(Exception e) {
+        super(e);
+    }
+}
index f848860a3169b948f7de0136dc4286400214472a..1201d30b9b16c6e06d324bc511b62b2e66562beb 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Optional;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.openhab.binding.omnilink.internal.AreaAlarm;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.StringType;
index f17f716a1cd32d5032485e0fac39abe528fbf686..587b253dc6b3859edd04f2424a4baf21bc3bb704 100644 (file)
@@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.thing.Bridge;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.binding.BaseThingHandler;
index 9846edf7d12dafe5271534118af0fa3ce01a96c5..e5501cc60be1005cf290922b50fcbb7534d44922 100644 (file)
@@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.StringType;
 import org.openhab.core.thing.ChannelUID;
index f80e28da5a988ac48eb45dd4b3dcb3f7219d49c5..6a51b68f34f27e12651ed7cc6525c17bfc735a79 100644 (file)
@@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.omnilink.internal.AudioPlayer;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.NextPreviousType;
 import org.openhab.core.library.types.OnOffType;
diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/BridgeOfflineException.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/BridgeOfflineException.java
deleted file mode 100644 (file)
index 891d4c4..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.omnilink.internal.handler;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * The {@link BridgeOfflineException} defines an exception for when the OmniLink
- * Bridge is offline or unavailable.
- *
- * @author Craig Hamilton - Initial contribution
- */
-@NonNullByDefault
-public class BridgeOfflineException extends Exception {
-    private static final long serialVersionUID = -9081729691518514097L;
-
-    public BridgeOfflineException(Exception e) {
-        super(e);
-    }
-}
index 002c4dcc8f1fb8c88186da4607b7fb9eeca4a772..4e865439ead0b6e66f4053d706bf044e7b94ce4b 100644 (file)
@@ -22,8 +22,10 @@ import javax.measure.quantity.Dimensionless;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.omnilink.internal.TemperatureFormat;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.unit.Units;
 import org.openhab.core.thing.ChannelUID;
index b2e554c525e4b0c33aef1e37ab74b0fb48bc6d28..6c2bfa8f60b93efc1af02141954d6c46f5ea2a26 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.Thing;
index c02dadaa0d84e6dc445ae21cc521d9c17460c4ae..a0991bb9a56215fbe6441ffb9ce3f1bb52a452c1 100644 (file)
@@ -28,8 +28,10 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.omnilink.internal.AudioPlayer;
 import org.openhab.binding.omnilink.internal.SystemType;
+import org.openhab.binding.omnilink.internal.TemperatureFormat;
 import org.openhab.binding.omnilink.internal.config.OmnilinkBridgeConfig;
 import org.openhab.binding.omnilink.internal.discovery.OmnilinkDiscoveryService;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.library.types.DateTimeType;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.StringType;
@@ -93,7 +95,7 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
     private @Nullable ScheduledFuture<?> eventPollingJob;
     private final int autoReconnectPeriod = 60;
     private Optional<AudioPlayer> audioPlayer = Optional.empty();
-    private @Nullable SystemType systemType = null;
+    private Optional<SystemType> systemType = Optional.empty();
     private final Gson gson = new Gson();
     private int eventLogNumber = 0;
 
@@ -306,28 +308,23 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
                     theThing.map(Thing::getHandler)
                             .ifPresent(theHandler -> ((ZoneHandler) theHandler).handleStatus(zoneStatus));
                 } else if (status instanceof ExtendedAreaStatus) {
-                    final SystemType systemType = this.systemType;
                     ExtendedAreaStatus areaStatus = (ExtendedAreaStatus) status;
                     int areaNumber = areaStatus.getNumber();
 
-                    if (systemType != null) {
-                        logger.debug("Received status update for Area: {}, status: {}", areaNumber, areaStatus);
-                        Optional<Thing> theThing;
-                        switch (systemType) {
-                            case OMNI:
-                                theThing = getChildThing(THING_TYPE_OMNI_AREA, areaNumber);
-                                break;
+                    logger.debug("Received status update for Area: {}, status: {}", areaNumber, areaStatus);
+                    systemType.ifPresent(t -> {
+                        Optional<Thing> theThing = Optional.empty();
+                        switch (t) {
                             case LUMINA:
                                 theThing = getChildThing(THING_TYPE_LUMINA_AREA, areaNumber);
                                 break;
-                            default:
-                                theThing = Optional.empty();
+                            case OMNI:
+                                theThing = getChildThing(THING_TYPE_OMNI_AREA, areaNumber);
+                                break;
                         }
                         theThing.map(Thing::getHandler)
                                 .ifPresent(theHandler -> ((AbstractAreaHandler) theHandler).handleStatus(areaStatus));
-                    } else {
-                        logger.debug("Received null System Type!");
-                    }
+                    });
                 } else if (status instanceof ExtendedAccessControlReaderLockStatus) {
                     ExtendedAccessControlReaderLockStatus lockStatus = (ExtendedAccessControlReaderLockStatus) status;
                     int lockNumber = lockStatus.getNumber();
index 75152c27f1a1c47f391e510f519d7ff97044b59c..969527e91ac64b3c3824410e4989d3eb56b50d31 100644 (file)
@@ -22,8 +22,10 @@ import javax.measure.quantity.Temperature;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.omnilink.internal.TemperatureFormat;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.unit.ImperialUnits;
 import org.openhab.core.library.unit.SIUnits;
diff --git a/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/TemperatureFormat.java b/bundles/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/internal/handler/TemperatureFormat.java
deleted file mode 100644 (file)
index fdff35d..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.omnilink.internal.handler;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-import com.digitaldan.jomnilinkII.MessageUtils;
-
-/**
- * The {@link TemperatureFormat} defines some methods that are used to
- * convert OmniLink temperature values into Fahrenheit or Celsius.
- *
- * @author Craig Hamilton - Initial contribution
- * @author Ethan Dye - openHAB3 rewrite
- */
-@NonNullByDefault
-public enum TemperatureFormat {
-    // Don't convert zero - it appears that is what omni returns when there is no value.
-    CELSIUS(2) {
-        @Override
-        public float omniToFormat(int omniNumber) {
-            return MessageUtils.omniToC(omniNumber);
-        }
-
-        @Override
-        public int formatToOmni(float celsius) {
-            return MessageUtils.CToOmni(celsius);
-        }
-    },
-    FAHRENHEIT(1) {
-        @Override
-        public float omniToFormat(int omniNumber) {
-            return MessageUtils.omniToF(omniNumber);
-        }
-
-        @Override
-        public int formatToOmni(float fahrenheit) {
-            return MessageUtils.FtoOmni(fahrenheit);
-        }
-    };
-
-    private final int formatNumber;
-
-    private TemperatureFormat(int formatNumber) {
-        this.formatNumber = formatNumber;
-    }
-
-    /**
-     * Convert a number represented by the omni to the format.
-     *
-     * @param omniNumber Number to convert
-     * @return Number converted to appropriate format.
-     */
-    public abstract float omniToFormat(int omniNumber);
-
-    /**
-     * Convert a number from this format into an omni number.
-     *
-     * @param format Number in the current format.
-     * @return Omni formatted number.
-     */
-    public abstract int formatToOmni(float format);
-
-    /**
-     * Get the number which identifies this format as defined by the omniprotocol.
-     *
-     * @return Number which identifies this temperature format.
-     */
-    public int getFormatNumber() {
-        return formatNumber;
-    }
-
-    public static TemperatureFormat valueOf(int tempFormat) {
-        if (tempFormat == CELSIUS.formatNumber) {
-            return CELSIUS;
-        } else if (tempFormat == FAHRENHEIT.formatNumber) {
-            return FAHRENHEIT;
-        } else {
-            throw new IllegalArgumentException("Invalid temperature format!");
-        }
-    }
-}
index a66259caf663e91b0f365da310efb795c1f37568..df84bc9e0e1c14283ae1e998ce321814fba25793 100644 (file)
@@ -24,8 +24,10 @@ import javax.measure.quantity.Temperature;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.omnilink.internal.TemperatureFormat;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OpenClosedType;
 import org.openhab.core.library.types.QuantityType;
index 992905118c73e209814edccfb17ab08afff07f1e..379fc3c109d02a21c80342bf689585455ca176e9 100644 (file)
@@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.PercentType;
index 1637049b310ebb3eed89358683e3de15fa50ee0f..8d07e9228716d98947ca102af8ce862cad4b7485 100644 (file)
@@ -23,6 +23,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
 import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
+import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OpenClosedType;
 import org.openhab.core.library.types.StringType;