]> git.basschouten.com Git - openhab-addons.git/commitdiff
Allow ONVIF to come online if they dont support events. (#16332)
authorMatthew Skinner <matt@pcmus.com>
Sun, 4 Feb 2024 10:19:24 +0000 (21:19 +1100)
committerGitHub <noreply@github.com>
Sun, 4 Feb 2024 10:19:24 +0000 (11:19 +0100)
Remove commented out code.

Signed-off-by: Matthew Skinner <matt@pcmus.com>
bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java
bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java

index da01b4dc64d169c5e25a74ad7241da350ff07da1..6a6650de9d5c8d8fcf170365f9920c7bf695a55f 100644 (file)
@@ -514,17 +514,16 @@ public class IpCameraHandler extends BaseThingHandler {
     private void checkCameraConnection() {
         if (snapshotPolling) { // Currently polling a real URL for snapshots, so camera must be online.
             return;
-        } else if (ffmpegSnapshotGeneration) { // Use RTSP stream creating snapshots to know camera is online.
+        } else if (ffmpegSnapshotGeneration) {
             Ffmpeg localSnapshot = ffmpegSnapshot;
             if (localSnapshot != null && !localSnapshot.isAlive()) {
                 cameraCommunicationError("FFmpeg Snapshots Stopped: Check that your camera can be reached.");
             }
-            return; // ffmpeg snapshot stream is still alive
+            return; // RTSP stream is creating snapshots, so camera is online.
         }
 
-        // ONVIF cameras get regular event messages from the camera
-        if (supportsOnvifEvents() && onvifCamera.isConnected()) {
-            return;
+        if (supportsOnvifEvents() && onvifCamera.isConnected() && onvifCamera.getEventsSupported()) {
+            return;// ONVIF cameras that are getting event messages must be online
         }
 
         // Open a HTTP connection without sending any requests as we do not need a snapshot.
index edc42f35d81a1d63525c4fb1d817fb888773c18c..e6cd9d10d8b94d78a756ce84a6f3fd5995fb1934 100644 (file)
@@ -131,9 +131,10 @@ public class OnvifConnection {
     private String subscriptionXAddr = "http://" + ipAddress + "/onvif/device_service";
     private boolean isConnected = false;
     private int mediaProfileIndex = 0;
-    // private String snapshotUri = "";
     private String rtspUri = "";
     private IpCameraHandler ipCameraHandler;
+    private boolean supportsEvents = false; // camera has replied that it can do events
+    // Use/skip events even if camera support them. API cameras skip, as their own methods give better results.
     private boolean usingEvents = false;
 
     // These hold the cameras PTZ position in the range that the camera uses, ie
@@ -312,7 +313,7 @@ public class OnvifConnection {
         } else if (message.contains("RenewResponse")) {
             sendOnvifRequest(RequestType.PullMessages, subscriptionXAddr);
         } else if (message.contains("GetSystemDateAndTimeResponse")) {// 1st to be sent.
-            setIsConnected(true);
+            setIsConnected(true);// Instar profile T only cameras need this
             parseDateAndTime(message);
             logger.debug("openHAB UTC dateTime is: {}", getUTCdateTime());
         } else if (message.contains("GetCapabilitiesResponse")) {// 2nd to be sent.
@@ -337,6 +338,7 @@ public class OnvifConnection {
         } else if (message.contains("GetEventPropertiesResponse")) {
             sendOnvifRequest(RequestType.CreatePullPointSubscription, eventXAddr);
         } else if (message.contains("CreatePullPointSubscriptionResponse")) {
+            supportsEvents = true;
             subscriptionXAddr = Helper.fetchXML(message, "SubscriptionReference>", "Address>");
             logger.debug("subscriptionXAddr={}", subscriptionXAddr);
             sendOnvifRequest(RequestType.PullMessages, subscriptionXAddr);
@@ -958,6 +960,10 @@ public class OnvifConnection {
         }
     }
 
+    public boolean getEventsSupported() {
+        return supportsEvents;
+    }
+
     public void setIsConnected(boolean isConnected) {
         connecting.lock();
         try {