-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ipcamera] Add new channels for Dahua API-based doorphones #13313
Conversation
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
ipCameraHandler.setChannelState(CHANNEL_EXTERNAL_ALARM_INPUT2, OnOffType.OFF); | ||
ipCameraHandler.logger.debug("External alarm Dahua event, content={}", content); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, IMHO remove the logging as the alarm is going OFF I really doubt the content is useful.
The PR is badly signed. Maybe you can check @Skinah if your review comments were all considered. |
@@ -352,6 +437,16 @@ public void handleCommand(ChannelUID channelUID, Command command) { | |||
.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=false"); | |||
} | |||
return; | |||
case CHANNEL_MOTION_DETECTION_LEVEL: | |||
int motionlevel = Math.round(Float.valueOf(command.toString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This channel is a DIMMER so this line of code will fail if ON or OFF commands are sent which are valid for this channel type. You could use something like the following if (command instanceof DecimalType)
, but a better way would be not to turn into a String and then parse and round it if a less costly approach can be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests required to set actually usable Motion Detection Level limits. I've found out for my VTO that I do need levels from 1 to 4, and level 4 is extremely sensitive in my case. But my VTO is placed outdoors, and objects max distance from camera is something like 10 meters. Could you test those settings with your camera? If you'll find out the same results, item's type could be changed to type Number, limited from 1 to 4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I do not own a VTO camera, is that a requirement to test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ofc no. Should work with any Dahua-like camera with motion detection.
Thanks for the contribution. Before being happy with this I would like to discuss the extra channels and if they are needed, or if the lastEventData channel can be used? Please read this for the background... #11391 The change to using it is pretty easy.. ipCameraHandler.motionDetected(CHANNEL_DOOR_UNLOCK); The decision was made not to create hundreds of channels to expose the extra event data, but to offer the data in a single channel. The number of the card in my opinion falls into this category. If every piece of advanced data from an event was filtered into separate channels, this binding would have 200+ channels and be a pain to navigate and find the right channel. We should discuss the above point FIRST and then I would like to go over the code and the readme a little more carefully, but it looks pretty good already. |
As a user - I always will prefer just to choose a right channel, than to look at lastEventData string trying to figure out, where are all my camera's advanced possibilities. Average ipcamera user never ever heard about json, has no way to get camera's API description, fail even at simple rules, not saying about those which will require parsing. lastEventData usage will need a creation of additional rule, a dummy item, resolve possible persistence problems - user will have to do all those things binding is intended to do manually. Not mentioning Openhab's rules are often rather limited and not allowing to do all those things, which are available inside bindings code. |
I do agree with your comments, and I am looking for your feedback to discuss this with an open mind. Separate channels are what I prefer for the reasons you have listed, I also do not like a user scrolling through 200 channels that their model of camera does not support just to find the one which does do something... The other option would be to REMOVE the channels if the binding can ask the camera if they are supported or not with an API call? Is it possible to make an API call to see if the camera supports each channel, or is it possible to ask if the camera is a SIP capable model and then bulk remove them if the camera does not? If the approach to remove the channels were made, then you leave all the coding the way it is and only add a small amount, which could be done in this PR or a future one. Once this is decided then I can review the readme and go over the code 1 more time. |
Check could be done by API call like |
bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
Ok that is everything I can contribute to the review. As a summary:
Thanks for the PR. |
|
int motionlevel = Math.round(Float.valueOf(command.toString())); | ||
|
||
if (motionlevel == 0) { | ||
ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Level=1"); | ||
} else { | ||
ipCameraHandler.sendHttpGET( | ||
"/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Level=" + motionlevel); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int motionlevel = Math.round(Float.valueOf(command.toString())); | |
if (motionlevel == 0) { | |
ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Level=1"); | |
} else { | |
ipCameraHandler.sendHttpGET( | |
"/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Level=" + motionlevel); | |
} | |
if (command instanceof PercentType) { | |
if (PercentType.ZERO.equals(command)) { | |
ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Level=1"); | |
}else{ | |
ipCameraHandler.sendHttpGET( | |
"/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Level=" + ((PercentType) command).intValue()); | |
} | |
} |
Please test and use this code instead of yours, it should do the exact same result. This is much more CPU efficient and also will not create issues if someone does not send a slider value to the channel. PercentType is a BigDecimal internally, so it is very simple to get it as an Integer. If someone was to send a String command, my guess is your code would fail with an error of some kind.
ipCameraHandler.setChannelState(CHANNEL_DOOR_UNLOCK, OnOffType.ON); | ||
} | ||
} | ||
if (content.contains("\"Method\" : 5")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be ELSE IF instead of IF? If it matches method1 do we need to keep checking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not showing as changed in this PR, can you push the updated code or tell me if I am wrong, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not pushed, as I'm a bit stuck with other issue - what if we'll just organize additional channels to make channels easier to use for binding's user?
<channel-group-type id="doorphoneProperties"> <label>Doorphone Properties</label> <description>This is a group of channels relating to doorphone properties</description> <category>Door</category> <channels> <channel id="acceptedCardNumber" typeId="acceptedCardNumber"/> <channel id="doorUnlock" typeId="doorUnlock"/> <channel id="doorContact" typeId="doorContact"/> <channel id="exitButton" typeId="exitButton"/> <channel id="motionDetectionLevel" typeId="motionDetectionLevel"/> </channels> </channel-group-type>
This way I will just implement all VTO's additional channels. There will be a plenty of them, but they will be at the bottom and categorized.
ipCameraHandler.setChannelState(CHANNEL_DOOR_UNLOCK, OnOffType.ON); | ||
ipCameraHandler.logger.debug("Door opened from button"); | ||
} | ||
if (content.contains("\"Method\" : 4")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be ELSE IF instead of IF? If it matches method1 or Method 5, do we need to keep checking?
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
@mesetka : any feedback? Please also note that something is not well signed off. |
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Fixed another merge conflict. |
LGTM |
I am going to review this PR but please fix the conflicting file. |
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/update/instructions.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Show resolved
Hide resolved
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Show resolved
Hide resolved
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default translations are also missing.
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
...enhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you
…3313) * Made all changes requested by codeowner, added additional useful channels, fixing changes before going to channels organizing into groups and dynamic channels deletion. Signed-off-by: mesetka <yarkiyluch@gmail.com> Co-authored-by: Matthew Skinner <matt@pcmus.com> Co-authored-by: Leo Siepel <leosiepel@gmail.com>
…3313) * Made all changes requested by codeowner, added additional useful channels, fixing changes before going to channels organizing into groups and dynamic channels deletion. Signed-off-by: mesetka <yarkiyluch@gmail.com> Co-authored-by: Matthew Skinner <matt@pcmus.com> Co-authored-by: Leo Siepel <leosiepel@gmail.com>
This commit is adding some new possibilities for Dahua API-based doorphones
exit button state
door contact state
accepted access card channel
door unlock channel
motion detection sensitivity level
And a few spaces cleaning for README.md.
Signed-off-by: mesetka yarkiyluch@gmail.com