]> git.basschouten.com Git - openhab-addons.git/commitdiff
[Tankerkoenig] Fixes #8876 (#8940)
authorJürgen Baginski <opus42@gmx.de>
Tue, 3 Nov 2020 06:48:05 +0000 (07:48 +0100)
committerGitHub <noreply@github.com>
Tue, 3 Nov 2020 06:48:05 +0000 (22:48 -0800)
* [Tankerkoenig] Update StationHandler

Incooperated check for 'null' iot to prevent NullPointerExceptions.
* [Tankerkoenig] Updated WebserviceHandler

Fixed false parsing of OpeningTimes.
* Applied a spotless check   Signed-off-by: Jürgen Baginski <opus42@gmx.de>

Signed-off-by: Jürgen Baginski <opus42@gmx.de>
bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/handler/StationHandler.java
bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/handler/WebserviceHandler.java

index 1f56b1df73ba131f01fae9fbf90e402cd7db93fb..93851362e53e467f5bc326a99e5a6bf525fc9f7c 100644 (file)
@@ -128,25 +128,43 @@ public class StationHandler extends BaseThingHandler {
      */
     public void updateData(LittleStation station) {
         logger.debug("Update Tankerkoenig data '{}'", getThing().getUID());
-        if (IS_NUMERIC_PATTERN.matcher(station.getDiesel()).matches()) {
-            DecimalType diesel = new DecimalType(station.getDiesel());
-            updateState(CHANNEL_DIESEL, diesel);
-        } else {
-            updateState(CHANNEL_DIESEL, UnDefType.UNDEF);
-        }
-        if (IS_NUMERIC_PATTERN.matcher(station.getE10()).matches()) {
-            DecimalType e10 = new DecimalType(station.getE10());
-            updateState(CHANNEL_E10, e10);
-        } else {
-            updateState(CHANNEL_E10, UnDefType.UNDEF);
-        }
-        if (IS_NUMERIC_PATTERN.matcher(station.getE5()).matches()) {
-            DecimalType e5 = new DecimalType(station.getE5());
-            updateState(CHANNEL_E5, e5);
+        if (station.isOpen() == true) {
+            logger.debug("Checked Station is open! '{}'", getThing().getUID());
+            updateState(CHANNEL_STATION_OPEN, OpenClosedType.OPEN);
+            if (station.getDiesel() != null) {
+                if (IS_NUMERIC_PATTERN.matcher(station.getDiesel()).matches()) {
+                    DecimalType diesel = new DecimalType(station.getDiesel());
+                    updateState(CHANNEL_DIESEL, diesel);
+                } else {
+                    updateState(CHANNEL_DIESEL, UnDefType.UNDEF);
+                }
+            } else {
+                updateState(CHANNEL_DIESEL, UnDefType.UNDEF);
+            }
+            if (station.getE10() != null) {
+                if (IS_NUMERIC_PATTERN.matcher(station.getE10()).matches()) {
+                    DecimalType e10 = new DecimalType(station.getE10());
+                    updateState(CHANNEL_E10, e10);
+                } else {
+                    updateState(CHANNEL_E10, UnDefType.UNDEF);
+                }
+            } else {
+                updateState(CHANNEL_E10, UnDefType.UNDEF);
+            }
+            if (station.getE10() != null) {
+                if (IS_NUMERIC_PATTERN.matcher(station.getE5()).matches()) {
+                    DecimalType e5 = new DecimalType(station.getE5());
+                    updateState(CHANNEL_E5, e5);
+                } else {
+                    updateState(CHANNEL_E5, UnDefType.UNDEF);
+                }
+            } else {
+                updateState(CHANNEL_E5, UnDefType.UNDEF);
+            }
         } else {
-            updateState(CHANNEL_E5, UnDefType.UNDEF);
+            logger.debug("Checked Station is closed!");
+            updateState(CHANNEL_STATION_OPEN, OpenClosedType.CLOSED);
         }
-        updateState(CHANNEL_STATION_OPEN, (station.isOpen() ? OpenClosedType.OPEN : OpenClosedType.CLOSED));
         updateStatus(ThingStatus.ONLINE);
     }
 
index 1a4b53d3b2809bb806421b03e193465f830b81d2..536c3d22d6420efec6ef8c0172fc0d1033dbec73 100644 (file)
@@ -293,11 +293,11 @@ public class WebserviceHandler extends BaseBridgeHandler {
                                     }
                                     break;
                             }
-                            if (foundIt) {
-                                start = open;
-                                ende = close;
-                                break;
-                            }
+                        }
+                        if (foundIt) {
+                            start = open;
+                            ende = close;
+                            break;
                         }
                         i = i + 1;
                     } while (i < o.length);