From 4b6e815c1dc71669bb368320faa958c936b4f681 Mon Sep 17 00:00:00 2001 From: Matthew Skinner Date: Mon, 2 Aug 2021 04:06:28 +1000 Subject: [PATCH] [ipcamera] Improve FFmpeg motion detection to support wider FPS range (#11067) * Fix urls are null until binding restarts. Signed-off-by: Matthew Skinner * Change to using port config. Signed-off-by: Matthew Skinner * automate the ffmpeg output folder to follow the UID. Signed-off-by: Matthew Skinner * spotless fixes. Signed-off-by: Matthew Skinner * Update readme. Signed-off-by: Matthew Skinner * change to using the userdata folder. Signed-off-by: Matthew Skinner * change to better field description. Signed-off-by: Matthew Skinner * Add advanced. Signed-off-by: Matthew Skinner * Add link to docs. Signed-off-by: Matthew Skinner * improve readme. Signed-off-by: Matthew Skinner * improve example path in readme. Signed-off-by: Matthew Skinner * Update bundles/org.openhab.binding.ipcamera/README.md Cut and paste bandit strikes again. thanks. Signed-off-by: Matthew Skinner Co-authored-by: Fabian Wolter * Change to using ipcamera as folder loc. Signed-off-by: Matthew Skinner * Improve Ffmpeg motion and refactor to remove compiler warnings. Signed-off-by: Matthew Skinner Co-authored-by: Fabian Wolter Signed-off-by: Dave J Schoepel --- .../ipcamera/internal/DahuaHandler.java | 56 +++++++++---------- .../binding/ipcamera/internal/Ffmpeg.java | 33 ++++++++--- .../internal/IpCameraBindingConstants.java | 3 + .../internal/IpCameraHandlerFactory.java | 5 +- .../ipcamera/internal/MyNettyAuthHandler.java | 2 +- .../internal/StreamServerGroupHandler.java | 4 +- .../internal/StreamServerHandler.java | 2 +- .../internal/handler/IpCameraHandler.java | 18 +++--- .../internal/onvif/OnvifConnection.java | 42 +++++++------- .../internal/onvif/OnvifDiscovery.java | 4 +- 10 files changed, 93 insertions(+), 76 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 65234b506364a..05a6fd7c2a32a 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 @@ -65,105 +65,105 @@ private void processEvent(String content) { String action = content.substring(startIndex, endIndex); switch (code) { case "VideoMotion": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.motionDetected(CHANNEL_MOTION_ALARM); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM); } break; case "TakenAwayDetection": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.motionDetected(CHANNEL_ITEM_TAKEN); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.noMotionDetected(CHANNEL_ITEM_TAKEN); } break; case "LeftDetection": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.motionDetected(CHANNEL_ITEM_LEFT); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.noMotionDetected(CHANNEL_ITEM_LEFT); } break; case "SmartMotionVehicle": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.motionDetected(CHANNEL_CAR_ALARM); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.noMotionDetected(CHANNEL_CAR_ALARM); } break; case "SmartMotionHuman": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.motionDetected(CHANNEL_HUMAN_ALARM); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.noMotionDetected(CHANNEL_HUMAN_ALARM); } break; case "CrossLineDetection": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.motionDetected(CHANNEL_LINE_CROSSING_ALARM); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.noMotionDetected(CHANNEL_LINE_CROSSING_ALARM); } break; case "AudioMutation": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.audioDetected(); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.noAudioDetected(); } break; case "FaceDetection": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.motionDetected(CHANNEL_FACE_DETECTED); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.noMotionDetected(CHANNEL_FACE_DETECTED); } break; case "ParkingDetection": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.setChannelState(CHANNEL_PARKING_ALARM, OnOffType.ON); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.setChannelState(CHANNEL_PARKING_ALARM, OnOffType.OFF); } break; case "CrossRegionDetection": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.motionDetected(CHANNEL_FIELD_DETECTION_ALARM); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.noMotionDetected(CHANNEL_FIELD_DETECTION_ALARM); } break; case "VideoLoss": case "VideoBlind": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.setChannelState(CHANNEL_TOO_DARK_ALARM, OnOffType.ON); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.setChannelState(CHANNEL_TOO_DARK_ALARM, OnOffType.OFF); } break; case "VideoAbnormalDetection": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.setChannelState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.ON); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.setChannelState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.OFF); } break; case "VideoUnFocus": - if (action.equals("Start")) { + if ("Start".equals(action)) { ipCameraHandler.setChannelState(CHANNEL_TOO_BLURRY_ALARM, OnOffType.ON); - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { ipCameraHandler.setChannelState(CHANNEL_TOO_BLURRY_ALARM, OnOffType.OFF); } break; case "AlarmLocal": - if (action.equals("Start")) { + if ("Start".equals(action)) { if (content.contains("index=0")) { ipCameraHandler.setChannelState(CHANNEL_EXTERNAL_ALARM_INPUT, OnOffType.ON); } else { ipCameraHandler.setChannelState(CHANNEL_EXTERNAL_ALARM_INPUT2, OnOffType.ON); } - } else if (action.equals("Stop")) { + } else if ("Stop".equals(action)) { if (content.contains("index=0")) { ipCameraHandler.setChannelState(CHANNEL_EXTERNAL_ALARM_INPUT, OnOffType.OFF); } else { diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/Ffmpeg.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/Ffmpeg.java index bc5c960179e6d..e2e51a11870ca 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/Ffmpeg.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/Ffmpeg.java @@ -127,20 +127,39 @@ public void run() { BufferedReader bufferedReader = new BufferedReader(errorStreamReader); String line = null; while ((line = bufferedReader.readLine()) != null) { + logger.debug("{}", line); if (format.equals(FFmpegFormat.RTSP_ALARMS)) { - logger.debug("{}", line); if (line.contains("lavfi.")) { - if (countOfMotions == 4) { - ipCameraHandler.motionDetected(CHANNEL_FFMPEG_MOTION_ALARM); - } else { + // When the number of pixels that change are below the noise floor we need to look + // across frames to confirm it is motion and not noise. + if (countOfMotions < 10) {// Stop increasing otherwise it will take too long to go OFF. countOfMotions++; } + if (countOfMotions > 9) { + ipCameraHandler.motionDetected(CHANNEL_FFMPEG_MOTION_ALARM); + } else if (countOfMotions > 4 && ipCameraHandler.motionThreshold.intValue() > 10) { + ipCameraHandler.motionDetected(CHANNEL_FFMPEG_MOTION_ALARM); + } else if (countOfMotions > 3 && ipCameraHandler.motionThreshold.intValue() > 15) { + ipCameraHandler.motionDetected(CHANNEL_FFMPEG_MOTION_ALARM); + } else if (countOfMotions > 2 && ipCameraHandler.motionThreshold.intValue() > 30) { + ipCameraHandler.motionDetected(CHANNEL_FFMPEG_MOTION_ALARM); + } else if (countOfMotions > 0 && ipCameraHandler.motionThreshold.intValue() > 89) { + ipCameraHandler.motionDetected(CHANNEL_FFMPEG_MOTION_ALARM); + countOfMotions = 4;// Used to debounce the Alarm. + } } else if (line.contains("speed=")) { if (countOfMotions > 0) { - countOfMotions--; - countOfMotions--; + if (ipCameraHandler.motionThreshold.intValue() > 89) { + countOfMotions--; + } + if (ipCameraHandler.motionThreshold.intValue() > 10) { + countOfMotions -= 2; + } else { + countOfMotions -= 4; + } if (countOfMotions <= 0) { ipCameraHandler.noMotionDetected(CHANNEL_FFMPEG_MOTION_ALARM); + countOfMotions = 0; } } } else if (line.contains("silence_start")) { @@ -148,8 +167,6 @@ public void run() { } else if (line.contains("silence_end")) { ipCameraHandler.audioDetected(); } - } else { - logger.debug("{}", line); } } } diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java index 475f91a53d761..c8561291e9355 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.ipcamera.internal; +import java.math.BigDecimal; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -42,6 +43,8 @@ public static enum FFmpegFormat { SNAPSHOT } + public static final BigDecimal BIG_DECIMAL_SCALE_MOTION = new BigDecimal(5000); + // List of all Thing Type UIDs public static final ThingTypeUID THING_TYPE_GROUP = new ThingTypeUID(BINDING_ID, "group"); public static final String GENERIC_THING = "generic"; diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraHandlerFactory.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraHandlerFactory.java index 50d80fcb1b0df..7652bedb22933 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraHandlerFactory.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraHandlerFactory.java @@ -50,10 +50,7 @@ public IpCameraHandlerFactory(final @Reference NetworkAddressService networkAddr @Override public boolean supportsThingType(ThingTypeUID thingTypeUID) { - if (SUPPORTED_THING_TYPES.contains(thingTypeUID) || GROUP_SUPPORTED_THING_TYPES.contains(thingTypeUID)) { - return true; - } - return false; + return (SUPPORTED_THING_TYPES.contains(thingTypeUID) || GROUP_SUPPORTED_THING_TYPES.contains(thingTypeUID)); } @Override diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/MyNettyAuthHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/MyNettyAuthHandler.java index e59b4055f5b6b..63df45cd5f6f1 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/MyNettyAuthHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/MyNettyAuthHandler.java @@ -104,7 +104,7 @@ public void processAuth(String authenticate, String httpMethod, String requestUR } String stale = Helper.searchString(authenticate, "stale=\""); - if (stale.equalsIgnoreCase("true")) { + if ("true".equalsIgnoreCase(stale)) { logger.debug("Camera reported stale=true which normally means the NONCE has expired."); } diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerGroupHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerGroupHandler.java index 07ebc214b6b89..98d1971a70372 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerGroupHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerGroupHandler.java @@ -70,7 +70,7 @@ public void handlerAdded(@Nullable ChannelHandlerContext ctx) { } private String resolveIndexToPath(String uri) { - if (!uri.substring(1, 2).equals("i")) { + if (!"i".equals(uri.substring(1, 2))) { return ipCameraGroupHandler.getOutputFolder(Integer.parseInt(uri.substring(1, 2))); } return "notFound"; @@ -87,7 +87,7 @@ public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object ms HttpRequest httpRequest = (HttpRequest) msg; String requestIP = "(" + ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress() + ")"; - if (!whiteList.contains(requestIP) && !whiteList.equals("DISABLE")) { + if (!whiteList.contains(requestIP) && !"DISABLE".equals(whiteList)) { logger.warn("The request made from {} was not in the whitelist and will be ignored.", requestIP); return; } else if (HttpMethod.GET.equals(httpRequest.method())) { diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerHandler.java index 6ec1c9b54178f..0763115fcbc7b 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerHandler.java @@ -81,7 +81,7 @@ public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object ms try { if (msg instanceof HttpRequest) { HttpRequest httpRequest = (HttpRequest) msg; - if (!whiteList.equals("DISABLE")) { + if (!"DISABLE".equals(whiteList)) { String requestIP = "(" + ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress() + ")"; if (!whiteList.contains(requestIP)) { 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 5dd9481ecdc82..635b51f27ec9a 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 @@ -19,6 +19,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.math.BigDecimal; import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.URL; @@ -189,7 +190,7 @@ public class IpCameraHandler extends BaseThingHandler { private boolean isOnline = false; // Used so only 1 error is logged when a network issue occurs. private boolean firstAudioAlarm = false; private boolean firstMotionAlarm = false; - public Double motionThreshold = 0.0016; + public BigDecimal motionThreshold = BigDecimal.ZERO; public int audioThreshold = 35; @SuppressWarnings("unused") private @Nullable StreamServerHandler streamServerHandler; @@ -1035,15 +1036,15 @@ public void setupFfmpegFormat(FFmpegFormat format) { String usersMotionOptions = cameraConfig.getMotionOptions(); if (usersMotionOptions.startsWith("-")) { // Need to put the users custom options first in the chain before the motion is detected - filterOptions += " " + usersMotionOptions + ",select='gte(scene," + motionThreshold - + ")',metadata=print"; + filterOptions += " " + usersMotionOptions + ",select='gte(scene," + + motionThreshold.divide(BIG_DECIMAL_SCALE_MOTION) + ")',metadata=print"; } else { filterOptions = filterOptions + " " + usersMotionOptions + " -vf select='gte(scene," - + motionThreshold + ")',metadata=print"; + + motionThreshold.divide(BIG_DECIMAL_SCALE_MOTION) + ")',metadata=print"; } } else if (motionAlarmEnabled) { - filterOptions = filterOptions - .concat(" -vf select='gte(scene," + motionThreshold + ")',metadata=print"); + filterOptions = filterOptions.concat(" -vf select='gte(scene," + + motionThreshold.divide(BIG_DECIMAL_SCALE_MOTION) + ")',metadata=print"); } ffmpegRtspHelper = new Ffmpeg(this, format, cameraConfig.getFfmpegLocation(), inputOptions, input, filterOptions, "-f null -", cameraConfig.getUser(), cameraConfig.getPassword()); @@ -1262,10 +1263,9 @@ public void handleCommand(ChannelUID channelUID, Command command) { } else if (OnOffType.OFF.equals(command) || DecimalType.ZERO.equals(command)) { motionAlarmEnabled = false; noMotionDetected(CHANNEL_FFMPEG_MOTION_ALARM); - } else { + } else if (command instanceof PercentType) { motionAlarmEnabled = true; - motionThreshold = Double.valueOf(command.toString()); - motionThreshold = motionThreshold / 10000; + motionThreshold = ((PercentType) command).toBigDecimal(); } setupFfmpegFormat(FFmpegFormat.RTSP_ALARMS); return; 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 773f57ffd08d0..eb86c7081e5ea 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 @@ -576,87 +576,87 @@ public void eventRecieved(String eventMessage) { } switch (topic) { case "RuleEngine/CellMotionDetector/Motion": - if (dataValue.equals("true")) { + if ("true".equals(dataValue)) { ipCameraHandler.motionDetected(CHANNEL_CELL_MOTION_ALARM); - } else if (dataValue.equals("false")) { + } else if ("false".equals(dataValue)) { ipCameraHandler.noMotionDetected(CHANNEL_CELL_MOTION_ALARM); } break; case "VideoSource/MotionAlarm": - if (dataValue.equals("true")) { + if ("true".equals(dataValue)) { ipCameraHandler.motionDetected(CHANNEL_MOTION_ALARM); - } else if (dataValue.equals("false")) { + } else if ("false".equals(dataValue)) { ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM); } break; case "AudioAnalytics/Audio/DetectedSound": - if (dataValue.equals("true")) { + if ("true".equals(dataValue)) { ipCameraHandler.audioDetected(); - } else if (dataValue.equals("false")) { + } else if ("false".equals(dataValue)) { ipCameraHandler.noAudioDetected(); } break; case "RuleEngine/FieldDetector/ObjectsInside": - if (dataValue.equals("true")) { + if ("true".equals(dataValue)) { ipCameraHandler.motionDetected(CHANNEL_FIELD_DETECTION_ALARM); - } else if (dataValue.equals("false")) { + } else if ("false".equals(dataValue)) { ipCameraHandler.noMotionDetected(CHANNEL_FIELD_DETECTION_ALARM); } break; case "RuleEngine/LineDetector/Crossed": - if (dataName.equals("ObjectId")) { + if ("ObjectId".equals(dataName)) { ipCameraHandler.motionDetected(CHANNEL_LINE_CROSSING_ALARM); } else { ipCameraHandler.noMotionDetected(CHANNEL_LINE_CROSSING_ALARM); } break; case "RuleEngine/TamperDetector/Tamper": - if (dataValue.equals("true")) { + if ("true".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_TAMPER_ALARM, OnOffType.ON); - } else if (dataValue.equals("false")) { + } else if ("false".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_TAMPER_ALARM, OnOffType.OFF); } break; case "Device/HardwareFailure/StorageFailure": - if (dataValue.equals("true")) { + if ("true".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_STORAGE_ALARM, OnOffType.ON); - } else if (dataValue.equals("false")) { + } else if ("false".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_STORAGE_ALARM, OnOffType.OFF); } break; case "VideoSource/ImageTooDark/AnalyticsService": case "VideoSource/ImageTooDark/ImagingService": case "VideoSource/ImageTooDark/RecordingService": - if (dataValue.equals("true")) { + if ("true".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_TOO_DARK_ALARM, OnOffType.ON); - } else if (dataValue.equals("false")) { + } else if ("false".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_TOO_DARK_ALARM, OnOffType.OFF); } break; case "VideoSource/GlobalSceneChange/AnalyticsService": case "VideoSource/GlobalSceneChange/ImagingService": case "VideoSource/GlobalSceneChange/RecordingService": - if (dataValue.equals("true")) { + if ("true".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.ON); - } else if (dataValue.equals("false")) { + } else if ("false".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_SCENE_CHANGE_ALARM, OnOffType.OFF); } break; case "VideoSource/ImageTooBright/AnalyticsService": case "VideoSource/ImageTooBright/ImagingService": case "VideoSource/ImageTooBright/RecordingService": - if (dataValue.equals("true")) { + if ("true".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_TOO_BRIGHT_ALARM, OnOffType.ON); - } else if (dataValue.equals("false")) { + } else if ("false".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_TOO_BRIGHT_ALARM, OnOffType.OFF); } break; case "VideoSource/ImageTooBlurry/AnalyticsService": case "VideoSource/ImageTooBlurry/ImagingService": case "VideoSource/ImageTooBlurry/RecordingService": - if (dataValue.equals("true")) { + if ("true".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_TOO_BLURRY_ALARM, OnOffType.ON); - } else if (dataValue.equals("false")) { + } else if ("false".equals(dataValue)) { ipCameraHandler.changeAlarmState(CHANNEL_TOO_BLURRY_ALARM, OnOffType.OFF); } break; diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifDiscovery.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifDiscovery.java index 1705733152adb..6d5956f2627e7 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifDiscovery.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/onvif/OnvifDiscovery.java @@ -112,7 +112,7 @@ void searchReply(String url, String xml) { ipAddress = temp.substring(beginIndex, endIndex); } String brand = checkForBrand(xml); - if (brand.equals("onvif")) { + if ("onvif".equals(brand)) { try { brand = getBrandFromLoginPage(ipAddress); } catch (IOException e) { @@ -127,7 +127,7 @@ void processCameraReplys() { String xml = packet.content().toString(CharsetUtil.UTF_8); logger.trace("Device replied to discovery with:{}", xml); String xAddr = Helper.fetchXML(xml, "", "d:XAddrs>");// Foscam and all other brands - if (!xAddr.equals("")) { + if (!xAddr.isEmpty()) { searchReply(xAddr, xml); } else if (xml.contains("onvif")) { logger.info("Possible ONVIF camera found at:{}", packet.sender().getHostString());