Skip to content

Commit 1beef1e

Browse files
svnsssdmarkus7017
authored andcommitted
[dahuadoor] Extend snapshot handling and align WebRTC URL (openhab#20759)
* Improve snapshot handling and add VTO file retrieval, align WebRTC URL Signed-off-by: Sven Schad <svnsssd@gmail.com>
1 parent c3fd8bd commit 1beef1e

10 files changed

Lines changed: 1092 additions & 149 deletions

File tree

bundles/org.openhab.binding.dahuadoor/README.md

Lines changed: 103 additions & 29 deletions
Large diffs are not rendered by default.

bundles/org.openhab.binding.dahuadoor/src/main/java/org/openhab/binding/dahuadoor/internal/DahuaDoorBaseHandler.java

Lines changed: 454 additions & 8 deletions
Large diffs are not rendered by default.

bundles/org.openhab.binding.dahuadoor/src/main/java/org/openhab/binding/dahuadoor/internal/DahuaDoorConfiguration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public class DahuaDoorConfiguration {
3131
public String password = "";
3232
public String snapshotPath = "";
3333
public int maxImages = 20;
34+
public int maxEvents = 20;
35+
public String snapshotMode = "api";
36+
public boolean enableDoorRecordingDownload = true;
37+
public boolean enableHangupSnapshotDownload = false;
38+
public boolean enableUnlockSnapshotDownload = true;
39+
public boolean enableVideoMessageDownload = true;
40+
public String hangupSnapshotPath = "/var/lib/openhab/door-images/hangup";
41+
public String unlockSnapshotPath = "/var/lib/openhab/door-images/unlock";
42+
public String recordingPath = "/var/lib/openhab/door-images/recording";
43+
public String videoMessagePath = "/var/lib/openhab/door-images/video-message";
3444
public boolean useHttps = false;
3545

3646
// WebRTC / go2rtc settings

bundles/org.openhab.binding.dahuadoor/src/main/java/org/openhab/binding/dahuadoor/internal/DahuaVto2202Handler.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package org.openhab.binding.dahuadoor.internal;
1414

1515
import org.eclipse.jdt.annotation.NonNullByDefault;
16-
import org.openhab.binding.dahuadoor.internal.dahuaeventhandler.DahuaEventClient;
1716
import org.openhab.binding.dahuadoor.internal.media.PlayStreamServlet;
1817
import org.openhab.core.thing.Channel;
1918
import org.openhab.core.thing.Thing;
@@ -57,24 +56,12 @@ protected void onButtonPressed(int lockNumber) {
5756
}
5857
triggerChannel(channel.getUID(), "PRESSED");
5958

60-
// Retrieve image asynchronously to avoid blocking the keepAlive event loop
61-
DahuaEventClient localClient = client;
62-
if (localClient == null) {
63-
logger.warn("Client not initialized, cannot retrieve doorbell image");
59+
if (isDhipSnapshotMode()) {
60+
logger.debug("snapshotMode=dhip: waiting for NewFile snapshot event instead of active API snapshot");
6461
return;
6562
}
6663

67-
scheduler.submit(() -> {
68-
byte[] buffer = localClient.requestImage();
69-
if (buffer != null && buffer.length > 0) {
70-
// Update image channel
71-
updateImageChannel(DahuaDoorBindingConstants.CHANNEL_DOOR_IMAGE, buffer);
72-
73-
// Save snapshot
74-
saveSnapshot(buffer);
75-
} else {
76-
logger.warn("Received empty or null image buffer from VTO2202");
77-
}
78-
});
64+
// Retrieve image asynchronously to avoid blocking the keepAlive event loop
65+
scheduler.submit(() -> requestApiSnapshotForChannel(DahuaDoorBindingConstants.CHANNEL_DOOR_IMAGE, "VTO2202"));
7966
}
8067
}

bundles/org.openhab.binding.dahuadoor/src/main/java/org/openhab/binding/dahuadoor/internal/DahuaVto3211Handler.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package org.openhab.binding.dahuadoor.internal;
1414

1515
import org.eclipse.jdt.annotation.NonNullByDefault;
16-
import org.openhab.binding.dahuadoor.internal.dahuaeventhandler.DahuaEventClient;
1716
import org.openhab.binding.dahuadoor.internal.media.PlayStreamServlet;
1817
import org.openhab.core.thing.Channel;
1918
import org.openhab.core.thing.Thing;
@@ -59,6 +58,17 @@ protected void restoreLastSnapshots() {
5958
updateImageChannel(DahuaDoorBindingConstants.CHANNEL_DOOR_IMAGE_2, buffer2);
6059
}
6160

61+
@Override
62+
protected String getDoorImageChannelForLock(int lockNumber) {
63+
return lockNumber == 2 ? DahuaDoorBindingConstants.CHANNEL_DOOR_IMAGE_2
64+
: DahuaDoorBindingConstants.CHANNEL_DOOR_IMAGE_1;
65+
}
66+
67+
@Override
68+
protected String getDoorbellSnapshotSuffixForLock(int lockNumber) {
69+
return lockNumber == 2 ? "-2" : "-1";
70+
}
71+
6272
@Override
6373
protected void onButtonPressed(int lockNumber) {
6474
int resolvedLockNumber = lockNumber == 2 ? 2 : 1;
@@ -85,25 +95,14 @@ protected void onButtonPressed(int lockNumber) {
8595
}
8696
triggerChannel(bellChannel.getUID(), "PRESSED");
8797

88-
// Retrieve image asynchronously to avoid blocking the keepAlive event loop
89-
DahuaEventClient localClient = client;
90-
if (localClient == null) {
91-
logger.warn("Client not initialized, cannot retrieve doorbell image");
98+
if (isDhipSnapshotMode()) {
99+
logger.debug("snapshotMode=dhip: waiting for NewFile snapshot event for lock {}", lockNumber);
92100
return;
93101
}
94102

103+
// Retrieve image asynchronously to avoid blocking the keepAlive event loop
95104
final String doorImageChannelIdFinal = doorImageChannelId;
96-
scheduler.submit(() -> {
97-
byte[] buffer = localClient.requestImage();
98-
if (buffer != null && buffer.length > 0) {
99-
// Update image channel for the specific button
100-
updateImageChannel(doorImageChannelIdFinal, buffer);
101-
102-
// Save snapshot image
103-
saveSnapshot(buffer, resolvedLockNumber);
104-
} else {
105-
logger.warn("Received empty or null image buffer from VTO3211 button {}", resolvedLockNumber);
106-
}
107-
});
105+
scheduler.submit(() -> requestApiSnapshotForChannel(doorImageChannelIdFinal, "VTO3211 button " + lockNumber,
106+
resolvedLockNumber));
108107
}
109108
}

0 commit comments

Comments
 (0)