diff --git a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronAlarmHandler.java b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronAlarmHandler.java index 254904df7c7..828b30c5484 100644 --- a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronAlarmHandler.java +++ b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronAlarmHandler.java @@ -72,9 +72,13 @@ public abstract class JablotronAlarmHandler extends BaseThingHandler { @Override public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) { super.bridgeStatusChanged(bridgeStatusInfo); - if (ThingStatus.UNINITIALIZED == bridgeStatusInfo.getStatus()) { + if (ThingStatus.OFFLINE == bridgeStatusInfo.getStatus() + || ThingStatus.UNINITIALIZED == bridgeStatusInfo.getStatus()) { cleanup(); } + if (ThingStatus.ONLINE == bridgeStatusInfo.getStatus()) { + initialize(); + } } @Override @@ -85,6 +89,7 @@ public abstract class JablotronAlarmHandler extends BaseThingHandler { @Override public void initialize() { + logger.debug("Initializing the alarm: {}", getThing().getUID()); thingConfig = getConfigAs(JablotronDeviceConfig.class); future = scheduler.scheduleWithFixedDelay(this::updateAlarmStatus, 1, thingConfig.getRefresh(), TimeUnit.SECONDS); @@ -144,6 +149,7 @@ public abstract class JablotronAlarmHandler extends BaseThingHandler { } protected synchronized boolean updateAlarmStatus() { + logger.debug("Updating status of alarm: {}", getThing().getUID()); JablotronDataUpdateResponse dataUpdate = sendGetStatusRequest(); if (dataUpdate == null) { return false; diff --git a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronBridgeHandler.java b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronBridgeHandler.java index c0650efcf38..857678b8b91 100644 --- a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronBridgeHandler.java +++ b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronBridgeHandler.java @@ -90,9 +90,14 @@ public class JablotronBridgeHandler extends BaseBridgeHandler { } private void updateAlarmThings() { + logger.debug("Updating overall alarm's statuses..."); @Nullable List services = discoverServices(); if (services != null) { + Bridge localBridge = getThing(); + if (localBridge != null && ThingStatus.ONLINE != localBridge.getStatus()) { + updateStatus(ThingStatus.ONLINE); + } for (JablotronDiscoveredService service : services) { updateAlarmThing(service); } @@ -101,6 +106,11 @@ public class JablotronBridgeHandler extends BaseBridgeHandler { private void updateAlarmThing(JablotronDiscoveredService service) { for (Thing th : getThing().getThings()) { + if (ThingStatus.ONLINE != th.getStatus()) { + logger.debug("Thing {} is not online", th.getUID()); + continue; + } + JablotronAlarmHandler handler = (JablotronAlarmHandler) th.getHandler(); if (handler == null) { @@ -150,12 +160,13 @@ public class JablotronBridgeHandler extends BaseBridgeHandler { private @Nullable T sendMessage(String url, String urlParameters, Class classOfT, String encoding, boolean relogin) { + String line = ""; try { ContentResponse resp = createRequest(url).content(new StringContentProvider(urlParameters), encoding) .send(); logger.trace("Request: {} with data: {}", url, urlParameters); - String line = resp.getContentAsString(); + line = resp.getContentAsString(); logger.trace("Response: {}", line); return gson.fromJson(line, classOfT); } catch (TimeoutException e) { @@ -166,6 +177,7 @@ public class JablotronBridgeHandler extends BaseBridgeHandler { "Interrupt during calling url: " + url); Thread.currentThread().interrupt(); } catch (JsonSyntaxException e) { + logger.debug("Invalid JSON received: {}", line); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Syntax error during calling url: " + url); } catch (ExecutionException e) { diff --git a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java index 75baefa64f0..d295673fbf9 100644 --- a/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java +++ b/bundles/org.openhab.binding.jablotron/src/main/java/org/openhab/binding/jablotron/internal/handler/JablotronJa100Handler.java @@ -160,7 +160,7 @@ public class JablotronJa100Handler extends JablotronAlarmHandler { if (channel != null) { logger.debug("Updating channel: {} to value: {}", channel.getUID(), segment.getSegmentState()); State newState; - if (segmentId.startsWith("PGM_")) { + if (segmentId.startsWith("pgm_")) { newState = "unset".equals(segment.getSegmentState()) ? OnOffType.OFF : OnOffType.ON; } else { newState = new StringType(segment.getSegmentState());