From 8acae42aafe359059ffb8c71bd2cfdd0e7017788 Mon Sep 17 00:00:00 2001 From: Matthew Skinner Date: Sat, 12 Oct 2024 11:51:21 +1100 Subject: [PATCH] fix mjpeg does not work if overridden Signed-off-by: Matthew Skinner --- .../binding/ipcamera/internal/DahuaHandler.java | 13 ++++++++++--- .../binding/ipcamera/internal/ReolinkHandler.java | 2 +- .../ipcamera/internal/handler/IpCameraHandler.java | 2 +- .../ipcamera/internal/onvif/OnvifConnection.java | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java index fa97c5ddc451a..37d4c889227fa 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java @@ -20,6 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.ipcamera.internal.handler.IpCameraHandler; +import org.openhab.binding.ipcamera.internal.onvif.OnvifConnection.RequestType; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.PercentType; @@ -156,6 +157,7 @@ private void processEvent(String content) { ipCameraHandler.setChannelState(CHANNEL_TOO_DARK_ALARM, OnOffType.OFF); } break; + case "SceneChange": case "VideoAbnormalDetection": if ("Start".equals(action)) { ipCameraHandler.setChannelState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.ON); @@ -191,10 +193,14 @@ private void processEvent(String content) { case "LensMaskClose": ipCameraHandler.setChannelState(CHANNEL_ENABLE_PRIVACY_MODE, OnOffType.OFF); break; - // Skip these so they are not logged. case "TimeChange": + // Check updated time matches openHAB's and store the offset which is needed for ONVIF + ipCameraHandler.onvifCamera.sendOnvifRequest(RequestType.GetSystemDateAndTime, + ipCameraHandler.onvifCamera.deviceXAddr); + break; + // Skip these so they are not logged. + case "NTPAdjustTime": // will trigger a TimeChange event no need to check twice case "IntelliFrame": - case "NTPAdjustTime": case "StorageChange": case "Reboot": case "NewFile": @@ -202,6 +208,7 @@ private void processEvent(String content) { case "RtspSessionDisconnect": case "LeFunctionStatusSync": case "RecordDelete": + case "InterVideoAccess": break; default: ipCameraHandler.logger.debug("Unrecognised Dahua event, Code={}, action={}", code, action); @@ -324,7 +331,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { } else if (command instanceof PercentType percentCommand) { ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&Lighting_V2[" + nvrChannelAdjusted + "][0][1].Mode=Manual&Lighting_V2[" + nvrChannelAdjusted - + "][0][1].NearLight[0].Light=" + command.toString()); + + "][0][1].NearLight[0].Light=" + percentCommand.toString()); } return; case CHANNEL_AUTO_WHITE_LED: diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/ReolinkHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/ReolinkHandler.java index c4f8100df3dbb..5ea9b76eccd2f 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/ReolinkHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/ReolinkHandler.java @@ -452,7 +452,7 @@ public void handleCommand(ChannelUID channelUID, Command command) { ipCameraHandler.sendHttpPOST("/api.cgi?cmd=SetIrLights" + ipCameraHandler.reolinkAuth, "[{\"cmd\": \"SetIrLights\",\"action\": 0,\"param\": {\"IrLights\": {\"channel\": " + ipCameraHandler.cameraConfig.getNvrChannel() + ",\"state\": \"Off\"}}}]"); - } else if (OnOffType.ON.equals(command) || command instanceof PercentType percentCommand) { + } else if (OnOffType.ON.equals(command) || command instanceof PercentType) { ipCameraHandler.sendHttpPOST("/api.cgi?cmd=SetIrLights" + ipCameraHandler.reolinkAuth, "[{\"cmd\": \"SetIrLights\",\"action\": 0,\"param\": {\"IrLights\": {\"channel\": " + ipCameraHandler.cameraConfig.getNvrChannel() + ",\"state\": \"On\"}}}]"); diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java index 94c9cb437c51c..70223f7b5effa 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java @@ -241,7 +241,7 @@ public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object ms } if (contentType.contains("multipart")) { boundary = Helper.searchString(contentType, "boundary="); - if (mjpegUri.equals(requestUrl)) { + if (mjpegUri.endsWith(requestUrl)) { if (msg instanceof HttpMessage) { // very start of stream only mjpegContentType = contentType; diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java index 71c0d7ac0a74f..bbe4457e073a4 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifConnection.java @@ -124,7 +124,7 @@ public enum RequestType { private String user = ""; private String password = ""; private int onvifPort = 80; - private String deviceXAddr = "http://" + ipAddress + "/onvif/device_service"; + public String deviceXAddr = "http://" + ipAddress + "/onvif/device_service"; private String eventXAddr = "http://" + ipAddress + "/onvif/device_service"; private String mediaXAddr = "http://" + ipAddress + "/onvif/device_service"; @SuppressWarnings("unused")