From be0b3cf5b92a5347d00bcd9c34bf45a16268d6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Baginski?= Date: Tue, 3 Nov 2020 07:48:05 +0100 Subject: [PATCH] [Tankerkoenig] Fixes #8876 (#8940) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [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 Signed-off-by: Jürgen Baginski --- .../internal/handler/StationHandler.java | 52 +++++++++++++------ .../internal/handler/WebserviceHandler.java | 10 ++-- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/handler/StationHandler.java b/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/handler/StationHandler.java index a3c998ca8e2..b80de2b5353 100644 --- a/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/handler/StationHandler.java +++ b/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/handler/StationHandler.java @@ -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); + 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_DIESEL, UnDefType.UNDEF); + logger.debug("Checked Station is closed!"); + updateState(CHANNEL_STATION_OPEN, OpenClosedType.CLOSED); } - 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); - } else { - updateState(CHANNEL_E5, UnDefType.UNDEF); - } - updateState(CHANNEL_STATION_OPEN, (station.isOpen() ? OpenClosedType.OPEN : OpenClosedType.CLOSED)); updateStatus(ThingStatus.ONLINE); } diff --git a/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/handler/WebserviceHandler.java b/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/handler/WebserviceHandler.java index f0ce7e1ba17..0803744584b 100644 --- a/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/handler/WebserviceHandler.java +++ b/bundles/org.openhab.binding.tankerkoenig/src/main/java/org/openhab/binding/tankerkoenig/internal/handler/WebserviceHandler.java @@ -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);