]> git.basschouten.com Git - openhab-addons.git/commitdiff
[ipcamera] Add channel Privacy Mode to Amcrest and Dahua handlers (#9092)
authorsidamos <thomas@boerkel.de>
Thu, 26 Nov 2020 17:53:52 +0000 (18:53 +0100)
committerGitHub <noreply@github.com>
Thu, 26 Nov 2020 17:53:52 +0000 (09:53 -0800)
* Add channel Privacy Mode to Amcrest and Dahua handlers

Signed-off-by: Thomas <thomas@boerkel.de>
bundles/org.openhab.binding.ipcamera/README.md
bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/AmcrestHandler.java
bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java
bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml

index cfdbe24d79a7409317f59e7271006f00bd0728ee..fd826ff21c0d0152d362ad26c1a9f14faff3fb41 100644 (file)
@@ -246,6 +246,7 @@ The channels are kept consistent as much as possible from brand to brand to make
 | `pan` | Dimmer | Works with ONVIF cameras that can be moved. |
 | `parkingAlarm` | Switch (read only) | When an API camera detects a car, this will turn ON. |
 | `pirAlarm` | Switch (read only) | When a camera with PIR ability detects motion, this turns ON. |
+| `privacyMode` | Switch | Enable or disable the Privacy Mode of newer Amcrest/Dahua cameras. The camera will move the lens way down and stop the stream. |
 | `recordingGif` | Number (read only) | How many seconds recording to GIF for. 0 when file ready. |
 | `recordingMp4` | Number (read only) | How many seconds recording to MP4 for. 0 when file ready. |
 | `rtspUrl` | String | The URL for the cameras auto detected RTSP stream. |
index 3cedaff611b2ec8cd5cab72bd2366057791102cc..8117d1e4490f344970119fedc9c3676d84af9018 100644 (file)
@@ -95,6 +95,13 @@ public class AmcrestHandler extends ChannelDuplexHandler {
                 String value = ipCameraHandler.returnValueFromString(content, "table.AudioDetect[0].MutationThreold=");
                 ipCameraHandler.setChannelState(CHANNEL_THRESHOLD_AUDIO_ALARM, PercentType.valueOf(value));
             }
+            // Privacy Mode on/off
+            if (content.contains("Code=LensMaskOpen;") || content.contains("table.LeLensMask[0].Enable=true")) {
+                ipCameraHandler.setChannelState(CHANNEL_ENABLE_PRIVACY_MODE, OnOffType.ON);
+            } else if (content.contains("Code=LensMaskClose;")
+                    || content.contains("table.LeLensMask[0].Enable=false")) {
+                ipCameraHandler.setChannelState(CHANNEL_ENABLE_PRIVACY_MODE, OnOffType.OFF);
+            }
         } finally {
             ReferenceCountUtil.release(msg);
             ctx.close();
@@ -118,6 +125,9 @@ public class AmcrestHandler extends ChannelDuplexHandler {
                 case CHANNEL_ENABLE_MOTION_ALARM:
                     ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=getConfig&name=MotionDetect[0]");
                     return;
+                case CHANNEL_ENABLE_PRIVACY_MODE:
+                    ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=getConfig&name=LeLensMask[0]");
+                    return;
             }
             return; // Return as we have handled the refresh command above and don't need to
                     // continue further.
@@ -205,6 +215,15 @@ public class AmcrestHandler extends ChannelDuplexHandler {
                     ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&AlarmOut[1].Mode=0");
                 }
                 return;
+            case CHANNEL_ENABLE_PRIVACY_MODE:
+                if (OnOffType.OFF.equals(command)) {
+                    ipCameraHandler
+                            .sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&LeLensMask[0].Enable=false");
+                } else if (OnOffType.ON.equals(command)) {
+                    ipCameraHandler
+                            .sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&LeLensMask[0].Enable=true");
+                }
+                return;
         }
     }
 
index 35c418bb948ffd4eee8c12fc457f781113655050..0a2c54c6811a240f8e2814e4cc9abdb53dda7082 100644 (file)
@@ -143,6 +143,13 @@ public class DahuaHandler extends ChannelDuplexHandler {
             } else if (content.contains("table.VideoAnalyseRule[0][1].Enable=false")) {
                 ipCameraHandler.setChannelState(CHANNEL_ENABLE_LINE_CROSSING_ALARM, OnOffType.OFF);
             }
+            // Privacy Mode on/off
+            if (content.contains("Code=LensMaskOpen;") || content.contains("table.LeLensMask[0].Enable=true")) {
+                ipCameraHandler.setChannelState(CHANNEL_ENABLE_PRIVACY_MODE, OnOffType.ON);
+            } else if (content.contains("Code=LensMaskClose;")
+                    || content.contains("table.LeLensMask[0].Enable=false")) {
+                ipCameraHandler.setChannelState(CHANNEL_ENABLE_PRIVACY_MODE, OnOffType.OFF);
+            }
         } finally {
             ReferenceCountUtil.release(msg);
         }
@@ -164,6 +171,9 @@ public class DahuaHandler extends ChannelDuplexHandler {
                 case CHANNEL_ENABLE_MOTION_ALARM:
                     ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=getConfig&name=MotionDetect[0]");
                     return;
+                case CHANNEL_ENABLE_PRIVACY_MODE:
+                    ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=getConfig&name=LeLensMask[0]");
+                    return;
             }
             return; // Return as we have handled the refresh command above and don't need to
                     // continue further.
@@ -251,6 +261,15 @@ public class DahuaHandler extends ChannelDuplexHandler {
                     ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&AlarmOut[1].Mode=0");
                 }
                 return;
+            case CHANNEL_ENABLE_PRIVACY_MODE:
+                if (OnOffType.OFF.equals(command)) {
+                    ipCameraHandler
+                            .sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&LeLensMask[0].Enable=false");
+                } else if (OnOffType.ON.equals(command)) {
+                    ipCameraHandler
+                            .sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&LeLensMask[0].Enable=true");
+                }
+                return;
         }
     }
 
index ee272259e0d2eba0a5c22cd96e82984071b14cdc..e399c48ee3e6278aae0706156ce1fd1a7c93687d 100644 (file)
@@ -129,4 +129,5 @@ public class IpCameraBindingConstants {
     public static final String CHANNEL_LAST_MOTION_TYPE = "lastMotionType";
     public static final String CHANNEL_GOTO_PRESET = "gotoPreset";
     public static final String CHANNEL_START_STREAM = "startStream";
+    public static final String CHANNEL_ENABLE_PRIVACY_MODE = "enablePrivacyMode";
 }
index d7ed31478c222895ede01d9e245fb6fea414f3df..2081f08faecbc80e231868eaf8bb0ed959d6cd56 100644 (file)
                        <channel id="rtspUrl" typeId="rtspUrl"/>
                        <channel id="imageUrl" typeId="imageUrl"/>
                        <channel id="hlsUrl" typeId="hlsUrl"/>
+                       <channel id="enablePrivacyMode" typeId="enablePrivacyMode"/>
                </channels>
                <config-description>
 
                        <channel id="rtspUrl" typeId="rtspUrl"/>
                        <channel id="imageUrl" typeId="imageUrl"/>
                        <channel id="hlsUrl" typeId="hlsUrl"/>
+                       <channel id="enablePrivacyMode" typeId="enablePrivacyMode"/>
                </channels>
                <config-description>
 
                <category>Light</category>
        </channel-type>
 
+       <channel-type id="enablePrivacyMode">
+               <item-type>Switch</item-type>
+               <label>Enable Privacy Mode</label>
+               <description>Turn the Privacy Mode on and off.</description>
+       </channel-type>
+
        <channel-type id="autoLED" advanced="true">
                <item-type>Switch</item-type>
                <label>Auto LED</label>