]> git.basschouten.com Git - openhab-addons.git/commitdiff
[shelly] improved logging on WebSocket connection problems (#16303)
authorMarkus Michels <markus7017@gmail.com>
Fri, 19 Jan 2024 20:58:18 +0000 (15:58 -0500)
committerGitHub <noreply@github.com>
Fri, 19 Jan 2024 20:58:18 +0000 (21:58 +0100)
* Improve logging on WebSocket connection problems

Signed-off-by: Markus Michels <markus7017@gmail.com>
bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java
bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/ShellyBluApi.java
bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java
bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBluSensorHandler.java
bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties
bundles/org.openhab.binding.shelly/src/main/resources/scripts/oh-blu-scanner.js

index df0a0602e934591571f436df33811874d4a8107c..5b654e685c4197e7aed85917073b900760229f90 100644 (file)
@@ -672,7 +672,7 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
                         getThing().requestUpdates(1, true); // refresh config
                         break;
                     case SHELLY2_EVENT_SLEEP:
-                        logger.debug("{}: Device went to sleep mode", thingName);
+                        logger.debug("{}: Connection terminated, e.g. device in sleep mode", thingName);
                         break;
                     case SHELLY2_EVENT_WIFICONNFAILED:
                         logger.debug("{}: WiFi connect failed, check setup, reason {}", thingName,
@@ -700,10 +700,14 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
     }
 
     @Override
-    public void onClose(int statusCode, String reason) {
+    public void onClose(int statusCode, String description) {
         try {
-            logger.debug("{}: WebSocket connection closed, status = {}/{}", thingName, statusCode, getString(reason));
-            if (statusCode == StatusCode.ABNORMAL && !discovery && getProfile().alwaysOn) { // e.g. device rebooted
+            String reason = getString(description);
+            logger.debug("{}: WebSocket connection closed, status = {}/{}", thingName, statusCode, reason);
+            if ("Bye".equalsIgnoreCase(reason)) {
+                logger.debug("{}: Device went to sleep mode", thingName);
+            } else if (statusCode == StatusCode.ABNORMAL && !discovery && getProfile().alwaysOn) {
+                // e.g. device rebooted
                 thingOffline("WebSocket connection closed abnormal");
             }
         } catch (ShellyApiException e) {
@@ -714,7 +718,7 @@ public class Shelly2ApiRpc extends Shelly2ApiClient implements ShellyApiInterfac
 
     @Override
     public void onError(Throwable cause) {
-        logger.debug("{}: WebSocket error", thingName);
+        logger.debug("{}: WebSocket error: {}", thingName, cause.getMessage());
         if (thing != null && thing.getProfile().alwaysOn) {
             thingOffline("WebSocket error");
         }
index 1778a2184b4f6ce72b97f52696513fef94edbd9e..3758cee18125e972ce81565f0a2571893ced9f85 100644 (file)
@@ -18,9 +18,9 @@ import static org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.*;
 import static org.openhab.binding.shelly.internal.util.ShellyUtils.*;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Map;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.shelly.internal.api.ShellyApiException;
 import org.openhab.binding.shelly.internal.api.ShellyDeviceProfile;
@@ -50,25 +50,24 @@ import org.slf4j.LoggerFactory;
  *
  * @author Markus Michels - Initial contribution
  */
+@NonNullByDefault
 public class ShellyBluApi extends Shelly2ApiRpc {
     private static final Logger logger = LoggerFactory.getLogger(ShellyBluApi.class);
     private boolean connected = false; // true = BLU devices has connected
     private ShellySettingsStatus deviceStatus = new ShellySettingsStatus();
     private int lastPid = -1;
 
-    private static final Map<String, String> MAP_INPUT_EVENT_TYPE = new HashMap<>();
-    static {
-        MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_1PUSH, SHELLY_BTNEVENT_1SHORTPUSH);
-        MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_2PUSH, SHELLY_BTNEVENT_2SHORTPUSH);
-        MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_3PUSH, SHELLY_BTNEVENT_3SHORTPUSH);
-        MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_LPUSH, SHELLY_BTNEVENT_LONGPUSH);
-        MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_LSPUSH, SHELLY_BTNEVENT_LONGSHORTPUSH);
-        MAP_INPUT_EVENT_TYPE.put(SHELLY2_EVENT_SLPUSH, SHELLY_BTNEVENT_SHORTLONGPUSH);
-        MAP_INPUT_EVENT_TYPE.put("1", SHELLY_BTNEVENT_1SHORTPUSH);
-        MAP_INPUT_EVENT_TYPE.put("2", SHELLY_BTNEVENT_2SHORTPUSH);
-        MAP_INPUT_EVENT_TYPE.put("3", SHELLY_BTNEVENT_3SHORTPUSH);
-        MAP_INPUT_EVENT_TYPE.put("4", SHELLY_BTNEVENT_LONGPUSH);
-    }
+    private static final Map<String, String> MAP_INPUT_EVENT_TYPE = Map.of( //
+            SHELLY2_EVENT_1PUSH, SHELLY_BTNEVENT_1SHORTPUSH, //
+            SHELLY2_EVENT_2PUSH, SHELLY_BTNEVENT_2SHORTPUSH, //
+            SHELLY2_EVENT_3PUSH, SHELLY_BTNEVENT_3SHORTPUSH, //
+            SHELLY2_EVENT_LPUSH, SHELLY_BTNEVENT_LONGPUSH, //
+            SHELLY2_EVENT_LSPUSH, SHELLY_BTNEVENT_LONGSHORTPUSH, //
+            SHELLY2_EVENT_SLPUSH, SHELLY_BTNEVENT_SHORTLONGPUSH, //
+            "1", SHELLY_BTNEVENT_1SHORTPUSH, //
+            "2", SHELLY_BTNEVENT_2SHORTPUSH, //
+            "3", SHELLY_BTNEVENT_3SHORTPUSH, //
+            "4", SHELLY_BTNEVENT_LONGPUSH);
 
     /**
      * Regular constructor - called by Thing handler
index 4e0a4a1f14152e1050106617f92b4a4b3326d922..003a20eadd6f3ff852c689ccb888ca57564d5ffd 100755 (executable)
@@ -340,7 +340,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
                     ? tmpPrf.settings.sleepMode.period * 60 // minutes
                     : tmpPrf.settings.sleepMode.period * 3600; // hours
             tmpPrf.updatePeriod += 60; // give 1min extra
-        } else if ((tmpPrf.settings.coiot != null) && tmpPrf.settings.coiot.updatePeriod != null) {
+        } else if (tmpPrf.settings.coiot != null && tmpPrf.settings.coiot.updatePeriod != null) {
             // Derive from CoAP update interval, usually 2*15+10s=40sec -> 70sec
             tmpPrf.updatePeriod = Math.max(UPDATE_SETTINGS_INTERVAL_SECONDS,
                     2 * getInteger(tmpPrf.settings.coiot.updatePeriod)) + 10;
index 3325cc8673bdb5c222dbfcccd001433a7844c73f..d6c10719791ed5bb982d0d314961b5ae045c2426 100644 (file)
@@ -20,6 +20,7 @@ import static org.openhab.core.thing.Thing.PROPERTY_MODEL_ID;
 import java.util.Map;
 import java.util.TreeMap;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jetty.client.HttpClient;
 import org.openhab.binding.shelly.internal.api.ShellyDeviceProfile;
@@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author Markus Michels - Initial contribution
  */
+@NonNullByDefault
 public class ShellyBluSensorHandler extends ShellyBaseHandler {
     private static final Logger logger = LoggerFactory.getLogger(ShellyBluSensorHandler.class);
 
@@ -52,7 +54,7 @@ public class ShellyBluSensorHandler extends ShellyBaseHandler {
         super.initialize();
     }
 
-    public static void addBluThing(String gateway, Shelly2NotifyEvent e, ShellyThingTable thingTable) {
+    public static void addBluThing(String gateway, Shelly2NotifyEvent e, @Nullable ShellyThingTable thingTable) {
         String model = substringBefore(getString(e.data.name), "-").toUpperCase();
         String mac = e.data.addr.replaceAll(":", "");
         String ttype = "";
index 94797887498801575fd0bc04763b5c296be693c6..ff38304728669d1b08258cb2b64e16b123018ace 100644 (file)
@@ -101,9 +101,6 @@ thing-type.shelly.shellyplussmoke.description = Shelly Plus Smoke - Smoke Detect
 thing-type.shelly.shellypluswdus.description = Shelly Wall Dimmer US Device
 thing-type.shelly.shellyplus10v.description = Shelly Plus Dimmer 10V
 
-# Wall displays
-thing-type.shelly.shellywalldisplay.description = Shelly Wall Display with sensors and input/output
-
 # Plus Mini Devices
 thing-type.shelly.shellyplusmini1.description = Shelly Plus Mini 1 - Single Relay Switch
 thing-type.shelly.shellyplusminipm.description =  Shelly Plus Mini PM - Power Meter
@@ -125,8 +122,8 @@ thing-type.shelly.shellyblubutton.description = Shelly BLU Button 1
 thing-type.shelly.shellybludw.description = Shelly BLU Door/Window Sensor
 thing-type.shelly.shellyblumotion.description = Shelly BLU Motion Sensor
  
- # Wall Displays
- thing-type.shelly.shellywalldisplay.description = Shelly Wall Display with sensors and input/output
+# Wall Displays
+thing-type.shelly.shellywalldisplay.description = Shelly Wall Display with sensors and input/output
  
 # thing config - shellydevice
 thing-type.config.shelly.deviceIp.label = IP Address
index 3dd38932ad727a4ed0f673849f015b6838c058b0..005f85860d28241370d15be1729f64adc8b84920 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * This script uses the BLE scan functionality in scripting to pass scan reults to openHAB
- * Supported BLU Devices: SBBT , SBDW
+ * This script uses the BLE scan functionality in scripting to pass scan results to openHAB
+ * Supported BLU Devices: BLU Button 1, BLU Door/Window, BLU Motion
  * Version 0.2
  */