Skip to content
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

[netatmo] Add support for Presence camera events (#3059) #7807

Merged
merged 15 commits into from
Jun 8, 2020
Merged

[netatmo] Add support for Presence camera events (#3059) #7807

merged 15 commits into from
Jun 8, 2020

Conversation

Novanic
Copy link
Contributor

@Novanic Novanic commented May 27, 2020

This pull-request adds support for the events of the Netatmo Presence camera.

It ...

  • uses the updated Netatmo API (to support the sub-event structure which is used by the Presence events)
  • delivers all information of the Presence events to the home thing (the message and snapshot is now available/set)
  • adds new channels to the home thing to report if a human, animal or vehicle was detected
  • simplifies the process of updating the Netatmo API (the retrofit code generation is now embedded within the Maven build)

Please see issue 3059 for more information: #3059

@cpmeister cpmeister added the enhancement An enhancement or new feature for an existing add-on label May 28, 2020
@clinique
Copy link
Contributor

@Novanic : I really like the update of the pom regarding swagger generation. Nice shot.
Would you mind by the way starting the refactoring of the NAWelcomeHandler with @NonNullByDefault ?

@Novanic
Copy link
Contributor Author

Novanic commented May 28, 2020

Would you mind by the way starting the refactoring of the NAWelcomeHandler with @NonNullByDefault ?
I don't know what you mean? Did we talk about it before? ;-) And what is the meaning of NonNullByDefault?

@Owlbertz
Copy link

Hi @Novanic,
I am currently working on making use of your last PR regarding this topic. However, I am not able to get my Presence camera working with openHAB, as I am not sure about the correct Things configuration.
Would you mind enhancing the existing documentation, especially the Things configuration example, to include more details reagarding the Presence camera?

@Novanic
Copy link
Contributor Author

Novanic commented May 28, 2020

Hi @Novanic,
I am currently working on making use of your last PR regarding this topic. However, I am not able to get my Presence camera working with openHAB, as I am not sure about the correct Things configuration.
Would you mind enhancing the existing documentation, especially the Things configuration example, to include more details reagarding the Presence camera?

Hm, interesting, this is just missing in the README, for the welcome camera too. Just use PaperUI, there the things are discovered automatically after the Netatmo API thing is created. ;-) Maybe we can extract it from there (to document it)?

@Novanic
Copy link
Contributor Author

Novanic commented May 28, 2020

Hi @Novanic,
I am currently working on making use of your last PR regarding this topic. However, I am not able to get my Presence camera working with openHAB, as I am not sure about the correct Things configuration.
Would you mind enhancing the existing documentation, especially the Things configuration example, to include more details reagarding the Presence camera?

Ok, I got it working now and have now updated the readme with this pull-request. Here is my example. The home thing is also required and the IDs from Netatmo are important, maybe that was missing/broken in your configuration. To use PaperUI instead is really simple, just enter the credentials for the Netatmo API and everything is found and configured. ;-)

Bridge netatmo:netatmoapi:home [ clientId="<CLIENTID>", clientSecret="<CLIENTSECRET>", username = "<USERNAME>", password = "<PASSWORD>", readStation=false, readHealthyHomeCoach=false, readThermostat=false, readWelcome=false, readPresence=true] { Thing NAWelcomeHome home [ id="<HOME-ID-FROM-NETATMO>", refreshInterval=600000 ] Thing NOC presenceOutdoorCamera [ id="CAMERA-ID-FROM-NETATMO", parentId="<HOME-ID-FROM-NETATMO>" ] }

@clinique
Copy link
Contributor

Would you mind by the way starting the refactoring of the NAWelcomeHandler with @NonNullByDefault ?
I don't know what you mean? Did we talk about it before? ;-) And what is the meaning of NonNullByDefault?

Put @NonNullByDefaultjust before the class declaration, and discover a whole new world :-)

Example here

@Novanic
Copy link
Contributor Author

Novanic commented May 29, 2020

Would you mind by the way starting the refactoring of the NAWelcomeHandler with @NonNullByDefault ?
I don't know what you mean? Did we talk about it before? ;-) And what is the meaning of NonNullByDefault?

Put @NonNullByDefaultjust before the class declaration, and discover a whole new world :-)

Example here

Wow, are you sure that it is a good approach? ;-) I think it makes it more unreadable and it's not necessary at some places (but the IDE gives a warning when the annotation isn't present). Example:
@Nullable String url = findSnapshotURL(); if(url != null) { return HttpUtil.downloadImage(url); }
It was/is already clarified that "url" can be NULL, NULL is checked directly after the Nullable declaration... ;-)

@clinique
Copy link
Contributor

Wow, are you sure that it is a good approach? ;-) I think it makes it more unreadable and it's not necessary at some places (but the IDE gives a warning when the annotation isn't present).

All the currently PR merge takes this approach, the whole OH core is underconvertion on this.

@lolodomo
Copy link
Contributor

Normally no new PR is accepted without null annotations.
There is of course a tolerance when updating a class created before null annotations were a requirement.

@openhab openhab deleted a comment from TravisBuddy May 29, 2020
@openhab openhab deleted a comment from TravisBuddy May 29, 2020
@openhab openhab deleted a comment from TravisBuddy May 29, 2020
@cweitkamp
Copy link
Contributor

@Novanic Thanks for your contribution. This is a really nice example for using a Trigger Channel instead of three separate State Channels. You could emit a special event for each entity detected by the Netatmo Camera. Trigger Channels can be nicely combined with a specific binding Profile or used directly as Channel-Based Trigger in a Rule. Wdyt?

<channel-type id="camara-event">
    <kind>trigger</kind>
    <label>Camara Event</label>
    <event>
        <options>
            <option value="ANIMAL_DETECTED">Animal Detected</option>
            <option value="HUMAN_DETECTED">Human Detected</option>
            <option value="VEHICLE_DETECTED">Vehicle Detected</option>
        </options>
    </event>
</channel-type>

@Novanic
Copy link
Contributor Author

Novanic commented May 29, 2020

NonNullByDefault is now used

Update: OMG, it breaks the build without showing issues within the IDE. How terrible is that...?! I have now solved it, but I think the "feature" is also buggy. See method NAWelcomeHomeHandler#findFirstSubEvent(...). I had to make this method to be NULL-safe, but it is never called with NULL...

@clinique
Copy link
Contributor

@Novanic : I think @cweitkamp remark regarding event channels is very valid and make a cleaner interface.

@Novanic
Copy link
Contributor Author

Novanic commented May 30, 2020

Ok, I will tryout the trigger channel. Is there anything more which I should change before the pull-request can get accepted and merged?

@Novanic
Copy link
Contributor Author

Novanic commented May 31, 2020

Ok, I got the trigger channel now running. But it is not yet within the pull-request, because I don't know if it's not too confusing for the user. What is your opinion?

There are currently 2 solutions to provide event information:
1.) There are channels at the home thing level (one for each information of an event) and these are updated with a delay up to a few minutes but without the usage of a complicated and risky public webhook. Therefore I added the 3 channels to react on human, animal and vehicle and to match that concept to provide this missing data to make this concept usable for the Presence camera.
2.) There is already a "homeEvent" trigger channel to provide events via the public webhook. I will try to extend that for the Presence later (with another pull-request).

Now the new "cameraEvent" trigger channel will be introduced for concept 1 also at the home thing level. The user has to know that the homeEvent trigger channel has another concept of usage than the new cameraEvent trigger channel. The cameraEvent channel has to get used in combination with the other channels and the homeEvent channel has another trigger (webhook) and has nothing to do with the other channels of the home thing.

To add the cameraEvent channel only to the Presence thing wouldn't work. That wouldn't fit to concept 1 and all the other event information would be missing because the channels are on the home thing level.

I see 2 options:
1.) We use the 3 channels with concept 1, which is already within this pull-request. Then it is clear how to use these channels.
or 2.) I introduce the cameraEvent trigger channel and I document within the README that the cameraEvent channel is only useful in combination with the other home thing channels excepting the homeEvent channel. And I would realize that detected persons of the Welcome camera are also reported as a human to this cameraEvent channel so that this channel is usable for all camera models. One problem with this solution is that we can not simply process "lastEvent" anymore which is done with updating the channels, it is now required to check if the lastEvent is new, because we don't want to trigger the channel multiple times... To update channels with the same value is not a problem, but triggering channels multiple times is a problem / isn't expected...

Which solution are you prefering? Or do you have other ideas? (but I would not make it too compilicated, I hope that the pull-request can get applied for OpenHAB 2.5.6 to complete the support of the Presence camera which has begun with 2.5.6) ;-) Thank you in advance.

@Novanic
Copy link
Contributor Author

Novanic commented Jun 1, 2020

I have now updated the pull-request to use the suggested cameraEvent trigger channel instead of 3 separate channels for human, animal and vehicle detected. New is also:

  • Detected persons of a Welcome / indoor camera are also reported as a human to this new channel. That makes this cameraEvent trigger channel solution compatible with all cameras.
  • Unspecified movements which are also reported by the Presence camera can also get handled via this trigger channel (there is a now a fourth event option named "MOVEMENT_DETECTED").

Please check if you like this solution more than the 3 channels and if the pull-request can get successfully reviewed and merged soon.

@openhab openhab deleted a comment from TravisBuddy Jun 6, 2020
@openhab openhab deleted a comment from TravisBuddy Jun 6, 2020
@openhab openhab deleted a comment from TravisBuddy Jun 6, 2020
@openhab openhab deleted a comment from TravisBuddy Jun 6, 2020
@TravisBuddy
Copy link

Travis tests were successful

Hey @Novanic,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

1 similar comment
@TravisBuddy
Copy link

Travis tests were successful

Hey @Novanic,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@Novanic Novanic requested a review from clinique June 6, 2020 19:20
Copy link
Contributor

@cpmeister cpmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not my intention to set you down a painful road of refactoring, I only mentioned dealing with the warnings because you decided to add @NonNullByDefault to the top of the handler class.
I guess I misunderstood your intent when you added that annotation as an indication that you wanted to update the code to modern binding coding guidelines. I would have been perfectly ok with you not adding that annotation since you were only modifying the code of an existing binding. But I guess we are past the point of going back so lets progress forward.

I really appreciate you taking the time to deal with the warnings even if it wasn't what you intended to do.

Also wrt addressing most of the "false positive" warnings the easiest solution is often to cache fields to local variables and perform all the logic on the local variables instead. The reason that you see these "false positives" is that the null checker is trying to prevent NPE from occurring in a concurrent environments where the field values might be changed by another thread during execution.

Anyway, other than these last few changes I think everything looks good.

@Novanic
Copy link
Contributor Author

Novanic commented Jun 7, 2020

@cpmeister It was requested as a review result within this pull-request "Would you mind by the way starting the refactoring of the NAWelcomeHandler with @NonNullByDefault ?" I think I should have answered with just "No" / "No, I don't start it"... ;-)

Signed-off-by: Sven Strohschein <[email protected]>
@Novanic Novanic requested a review from cpmeister June 7, 2020 08:29
@TravisBuddy
Copy link

Travis tests were successful

Hey @Novanic,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@cpmeister
Copy link
Contributor

@clinique Is there anything else you want changed on this PR?

Copy link
Contributor

@clinique clinique left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @Novanic

@cpmeister cpmeister linked an issue Jun 8, 2020 that may be closed by this pull request
@cpmeister cpmeister merged commit 48117f4 into openhab:2.5.x Jun 8, 2020
@cpmeister cpmeister added this to the 2.5.6 milestone Jun 8, 2020
@Novanic
Copy link
Contributor Author

Novanic commented Jun 9, 2020

Yeah, thank you for your review and merge. :-) Now it's done for 2.5.6.

@clinique @cpmeister @lolodomo @cpmeister Is someone of you an employee of Netatmo or has a good connection to Netatmo? I tried to contact Netatmo several times but got no answer... For example it would be interesting if it is allowed (for this project) to use inofficial API endpoints. That would allow to switch the floodlight of the Presence camera or start and stop the video recording.

@clinique
Copy link
Contributor

@Novanic : unfortunately no, I have no connection with Netatmo - but if you've identified unofficial API endpoints, nothing prevents you to use them. The only issue may be that unofficial endpoints may change without notification.

knikhilwiz pushed a commit to knikhilwiz/openhab2-addons that referenced this pull request Jul 12, 2020
* - Netatmo API updated (to support the sub-event structure which is used by the Presence events)
- The message and snapshot data of the Presence events is now available at the home thing
- New channels to the home thing added to report if a human, animal or vehicle was detected
- Process of updating the Netatmo API simplified (the retrofit code generation is now embedded within the Maven build, therefore the netatmo-swagger-api project doesn't require an additional update and release anymore)
* README extended for the Presence outdoor camera thing configuration example
* NonNullByDefault is now used because it was mentioned in the code-review
* The new 3 channels (for human, animal and vehicle detection) are now replaced by a trigger channel called "cameraEvent". Trigger channels are triggered after the other channels are updated (so a rule can react on a trigger and get the other event information from the other updated channels). Movement event option - A Presence camera reports also generic movements when a movement is not recognizable as a human, animal or vehicle.

Signed-off-by: Sven Strohschein <[email protected]>
CSchlipp pushed a commit to CSchlipp/openhab-addons that referenced this pull request Jul 26, 2020
* - Netatmo API updated (to support the sub-event structure which is used by the Presence events)
- The message and snapshot data of the Presence events is now available at the home thing
- New channels to the home thing added to report if a human, animal or vehicle was detected
- Process of updating the Netatmo API simplified (the retrofit code generation is now embedded within the Maven build, therefore the netatmo-swagger-api project doesn't require an additional update and release anymore)
* README extended for the Presence outdoor camera thing configuration example
* NonNullByDefault is now used because it was mentioned in the code-review
* The new 3 channels (for human, animal and vehicle detection) are now replaced by a trigger channel called "cameraEvent". Trigger channels are triggered after the other channels are updated (so a rule can react on a trigger and get the other event information from the other updated channels). Movement event option - A Presence camera reports also generic movements when a movement is not recognizable as a human, animal or vehicle.

Signed-off-by: Sven Strohschein <[email protected]>
Signed-off-by: CSchlipp <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* - Netatmo API updated (to support the sub-event structure which is used by the Presence events)
- The message and snapshot data of the Presence events is now available at the home thing
- New channels to the home thing added to report if a human, animal or vehicle was detected
- Process of updating the Netatmo API simplified (the retrofit code generation is now embedded within the Maven build, therefore the netatmo-swagger-api project doesn't require an additional update and release anymore)
* README extended for the Presence outdoor camera thing configuration example
* NonNullByDefault is now used because it was mentioned in the code-review
* The new 3 channels (for human, animal and vehicle detection) are now replaced by a trigger channel called "cameraEvent". Trigger channels are triggered after the other channels are updated (so a rule can react on a trigger and get the other event information from the other updated channels). Movement event option - A Presence camera reports also generic movements when a movement is not recognizable as a human, animal or vehicle.

Signed-off-by: Sven Strohschein <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* - Netatmo API updated (to support the sub-event structure which is used by the Presence events)
- The message and snapshot data of the Presence events is now available at the home thing
- New channels to the home thing added to report if a human, animal or vehicle was detected
- Process of updating the Netatmo API simplified (the retrofit code generation is now embedded within the Maven build, therefore the netatmo-swagger-api project doesn't require an additional update and release anymore)
* README extended for the Presence outdoor camera thing configuration example
* NonNullByDefault is now used because it was mentioned in the code-review
* The new 3 channels (for human, animal and vehicle detection) are now replaced by a trigger channel called "cameraEvent". Trigger channels are triggered after the other channels are updated (so a rule can react on a trigger and get the other event information from the other updated channels). Movement event option - A Presence camera reports also generic movements when a movement is not recognizable as a human, animal or vehicle.

Signed-off-by: Sven Strohschein <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* - Netatmo API updated (to support the sub-event structure which is used by the Presence events)
- The message and snapshot data of the Presence events is now available at the home thing
- New channels to the home thing added to report if a human, animal or vehicle was detected
- Process of updating the Netatmo API simplified (the retrofit code generation is now embedded within the Maven build, therefore the netatmo-swagger-api project doesn't require an additional update and release anymore)
* README extended for the Presence outdoor camera thing configuration example
* NonNullByDefault is now used because it was mentioned in the code-review
* The new 3 channels (for human, animal and vehicle detection) are now replaced by a trigger channel called "cameraEvent". Trigger channels are triggered after the other channels are updated (so a rule can react on a trigger and get the other event information from the other updated channels). Movement event option - A Presence camera reports also generic movements when a movement is not recognizable as a human, animal or vehicle.

Signed-off-by: Sven Strohschein <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* - Netatmo API updated (to support the sub-event structure which is used by the Presence events)
- The message and snapshot data of the Presence events is now available at the home thing
- New channels to the home thing added to report if a human, animal or vehicle was detected
- Process of updating the Netatmo API simplified (the retrofit code generation is now embedded within the Maven build, therefore the netatmo-swagger-api project doesn't require an additional update and release anymore)
* README extended for the Presence outdoor camera thing configuration example
* NonNullByDefault is now used because it was mentioned in the code-review
* The new 3 channels (for human, animal and vehicle detection) are now replaced by a trigger channel called "cameraEvent". Trigger channels are triggered after the other channels are updated (so a rule can react on a trigger and get the other event information from the other updated channels). Movement event option - A Presence camera reports also generic movements when a movement is not recognizable as a human, animal or vehicle.

Signed-off-by: Sven Strohschein <[email protected]>
DaanMeijer pushed a commit to DaanMeijer/openhab-addons that referenced this pull request Sep 1, 2020
* - Netatmo API updated (to support the sub-event structure which is used by the Presence events)
- The message and snapshot data of the Presence events is now available at the home thing
- New channels to the home thing added to report if a human, animal or vehicle was detected
- Process of updating the Netatmo API simplified (the retrofit code generation is now embedded within the Maven build, therefore the netatmo-swagger-api project doesn't require an additional update and release anymore)
* README extended for the Presence outdoor camera thing configuration example
* NonNullByDefault is now used because it was mentioned in the code-review
* The new 3 channels (for human, animal and vehicle detection) are now replaced by a trigger channel called "cameraEvent". Trigger channels are triggered after the other channels are updated (so a rule can react on a trigger and get the other event information from the other updated channels). Movement event option - A Presence camera reports also generic movements when a movement is not recognizable as a human, animal or vehicle.

Signed-off-by: Sven Strohschein <[email protected]>
Signed-off-by: Daan Meijer <[email protected]>
markus7017 pushed a commit to markus7017/openhab-addons that referenced this pull request Sep 19, 2020
* - Netatmo API updated (to support the sub-event structure which is used by the Presence events)
- The message and snapshot data of the Presence events is now available at the home thing
- New channels to the home thing added to report if a human, animal or vehicle was detected
- Process of updating the Netatmo API simplified (the retrofit code generation is now embedded within the Maven build, therefore the netatmo-swagger-api project doesn't require an additional update and release anymore)
* README extended for the Presence outdoor camera thing configuration example
* NonNullByDefault is now used because it was mentioned in the code-review
* The new 3 channels (for human, animal and vehicle detection) are now replaced by a trigger channel called "cameraEvent". Trigger channels are triggered after the other channels are updated (so a rule can react on a trigger and get the other event information from the other updated channels). Movement event option - A Presence camera reports also generic movements when a movement is not recognizable as a human, animal or vehicle.

Signed-off-by: Sven Strohschein <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[netatmo] Support Presence Camera
8 participants