]> git.basschouten.com Git - openhab-addons.git/commitdiff
[shelly] Add check and ThingStatus for local IP issue (APIPA) (#16306)
authorMarkus Michels <markus7017@gmail.com>
Sat, 27 Jan 2024 20:58:44 +0000 (21:58 +0100)
committerGitHub <noreply@github.com>
Sat, 27 Jan 2024 20:58:44 +0000 (21:58 +0100)
* Check for local_ip == 169.254.x.xm, which is the result when DHCP IP
assignment failed. Avoid that the binding passes this address to the
device as part of the callback url.

Signed-off-by: Markus Michels <markus7017@gmail.com>
Co-authored-by: markus7017 <markus7017@gmail..com>
bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyEventServlet.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/manager/ShellyManagerCache.java
bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties

index 16a48935cbef19fbfebee82591033c5a21cb8f8b..9e3609e2d488facbcbccd5448f27ac6c51b21067 100644 (file)
@@ -75,12 +75,13 @@ public class ShellyEventServlet extends WebSocketServlet {
      * Servlet handler. Shelly1: http request, Shelly2: WebSocket call
      */
     @Override
-    protected void service(HttpServletRequest request, HttpServletResponse resp)
+    protected void service(@Nullable HttpServletRequest request, @Nullable HttpServletResponse resp)
             throws ServletException, IOException, IllegalArgumentException {
         String path = getString(request.getRequestURI()).toLowerCase();
-
         if (path.equals(SHELLY2_CALLBACK_URI)) { // Shelly2 WebSocket
-            super.service(request, resp);
+            if (request != null && resp != null) {
+                super.service(request, resp);
+            }
             return;
         }
 
index 003a20eadd6f3ff852c689ccb888ca57564d5ffd..64eac84506e15e1932b8d45fbbfa4a538bffdaa7 100755 (executable)
@@ -1008,6 +1008,12 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
         config.serviceName = getString(properties.get(PROPERTY_SERVICE_NAME));
         config.localIp = bindingConfig.localIP;
         config.localPort = String.valueOf(bindingConfig.httpPort);
+        if (config.localIp.startsWith("169.254")) {
+            setThingOffline(ThingStatusDetail.COMMUNICATION_ERROR, "config-status.error.network-config",
+                    config.localIp);
+            return;
+        }
+
         if (!profile.isGen2 && config.userId.isEmpty() && !bindingConfig.defaultUserId.isEmpty()) {
             // Gen2 has hard coded user "admin"
             config.userId = bindingConfig.defaultUserId;
index 85bc0cf65be6d372802eec678fae3aaa2a92640d..ef39f19ea90b9f8959cf0f19a018a390a5ca06af 100644 (file)
@@ -16,7 +16,6 @@ import java.util.Date;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 
 /**
@@ -24,7 +23,6 @@ import org.eclipse.jdt.annotation.Nullable;
  *
  * @author Markus Michels - Initial contribution
  */
-@NonNullByDefault
 public class ShellyManagerCache<K, V> extends ConcurrentHashMap<K, V> {
 
     private static final long serialVersionUID = 1L;
@@ -46,7 +44,7 @@ public class ShellyManagerCache<K, V> extends ConcurrentHashMap<K, V> {
     }
 
     @Override
-    public @Nullable V put(K key, V value) {
+    public V put(K key, V value) {
         Date date = new Date();
         timeMap.put(key, date.getTime());
         return super.put(key, value);
@@ -66,7 +64,7 @@ public class ShellyManagerCache<K, V> extends ConcurrentHashMap<K, V> {
     }
 
     @Override
-    public @Nullable V putIfAbsent(K key, V value) {
+    public V putIfAbsent(K key, V value) {
         if (!containsKey(key)) {
             return put(key, value);
         } else {
@@ -86,7 +84,6 @@ public class ShellyManagerCache<K, V> extends ConcurrentHashMap<K, V> {
             }
         }
 
-        @SuppressWarnings("null")
         private void cleanMap() {
             long currentTime = new Date().getTime();
             for (K key : timeMap.keySet()) {
index ff38304728669d1b08258cb2b64e16b123018ace..91e71dece6a23b2c46e6b84d37cb32bcf262d09f 100644 (file)
@@ -11,6 +11,7 @@ addon.shelly.config.autoCoIoT.label = Auto-CoIoT
 addon.shelly.config.autoCoIoT.description = If enabled CoIoT will be automatically used when the devices runs a firmware version 1.6 or newer; false: Use thing configuration to enabled/disable CoIoT events.  
 
 # Config status messages
+message.config-status.error.network-config = Invalid system or openHAB network configuration was detected (local IP {0}).
 message.config-status.error.missing-device-address = IP/MAC Address of the Shelly device is missing.
 message.config-status.error.missing-userid = No user ID in the Thing configuration