]> git.basschouten.com Git - openhab-addons.git/commitdiff
[ipcamera] Add motion and alarm support for Axis branded cameras (#17419)
authorMatthew Skinner <matt@pcmus.com>
Sun, 15 Sep 2024 20:48:00 +0000 (06:48 +1000)
committerGitHub <noreply@github.com>
Sun, 15 Sep 2024 20:48:00 +0000 (22:48 +0200)
* Add support for Axis motion detection
Signed-off-by: Matthew Skinner <matt@pcmus.com>
bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java

index 0c27eabcd9764d1fb4725112b7d9c491ffb8b6fd..daab2b30d4afb30260295e2040beb170a1659393 100644 (file)
@@ -129,6 +129,7 @@ public class OnvifConnection {
     private String imagingXAddr = "http://" + ipAddress + "/onvif/device_service";
     private String ptzXAddr = "http://" + ipAddress + "/onvif/ptz_service";
     public String subscriptionXAddr = "http://" + ipAddress + "/onvif/device_service";
+    public String subscriptionId = "";
     private boolean isConnected = false;
     private int mediaProfileIndex = 0;
     private String rtspUri = "";
@@ -340,7 +341,12 @@ public class OnvifConnection {
         } else if (message.contains("CreatePullPointSubscriptionResponse")) {
             supportsEvents = true;
             subscriptionXAddr = Helper.fetchXML(message, "SubscriptionReference>", "Address>");
-            logger.debug("subscriptionXAddr={}", subscriptionXAddr);
+            int start = message.indexOf("<dom0:SubscriptionId");
+            int end = message.indexOf("</dom0:SubscriptionId>");
+            if (start > -1 && end > start) {
+                subscriptionId = message.substring(start, end + 22);
+            }
+            logger.debug("subscriptionXAddr={} subscriptionId={}", subscriptionXAddr, subscriptionId);
             sendOnvifRequest(RequestType.PullMessages, subscriptionXAddr);
         } else if (message.contains("GetStatusResponse")) {
             processPTZLocation(message);
@@ -532,7 +538,12 @@ public class OnvifConnection {
                     + encodeBase64(nonce)
                     + "</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"
                     + dateTime + "</Created></UsernameToken></Security>";
-            headers = "<s:Header>" + security + headerTo + "</s:Header>";
+
+            if (requestType.equals(RequestType.PullMessages) || requestType.equals(RequestType.Renew)) {
+                headers = "<s:Header>" + security + headerTo + subscriptionId + "</s:Header>";
+            } else {
+                headers = "<s:Header>" + security + headerTo + "</s:Header>";
+            }
         } else {// GetSystemDateAndTime must not be password protected as per spec.
             headers = "";
         }
@@ -674,10 +685,12 @@ public class OnvifConnection {
                     ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM);
                 }
                 break;
+            case "RuleEngine/tnsaxis:VMD3/vmd3_video_1":
+            case "RuleEngine/MotionRegionDetector/Motion":
             case "VideoSource/MotionAlarm":
-                if ("true".equals(dataValue)) {
+                if ("true".equals(dataValue) || "1".equals(dataValue)) {
                     ipCameraHandler.motionDetected(CHANNEL_MOTION_ALARM);
-                } else if ("false".equals(dataValue)) {
+                } else if ("false".equals(dataValue) || "0".equals(dataValue)) {
                     ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM);
                 }
                 break;
@@ -709,10 +722,11 @@ public class OnvifConnection {
                     ipCameraHandler.changeAlarmState(CHANNEL_TAMPER_ALARM, OnOffType.OFF);
                 }
                 break;
+            case "Device/tnsaxis:HardwareFailure/StorageFailure":
             case "Device/HardwareFailure/StorageFailure":
-                if ("true".equals(dataValue)) {
+                if ("true".equals(dataValue) || "1".equals(dataValue)) {
                     ipCameraHandler.changeAlarmState(CHANNEL_STORAGE_ALARM, OnOffType.ON);
-                } else if ("false".equals(dataValue)) {
+                } else if ("false".equals(dataValue) || "0".equals(dataValue)) {
                     ipCameraHandler.changeAlarmState(CHANNEL_STORAGE_ALARM, OnOffType.OFF);
                 }
                 break;
@@ -728,9 +742,9 @@ public class OnvifConnection {
             case "VideoSource/GlobalSceneChange/AnalyticsService":
             case "VideoSource/GlobalSceneChange/ImagingService":
             case "VideoSource/GlobalSceneChange/RecordingService":
-                if ("true".equals(dataValue)) {
+                if ("true".equals(dataValue) || "1".equals(dataValue)) {
                     ipCameraHandler.changeAlarmState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.ON);
-                } else if ("false".equals(dataValue)) {
+                } else if ("false".equals(dataValue) || "0".equals(dataValue)) {
                     ipCameraHandler.changeAlarmState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.OFF);
                 }
                 break;