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] Support for switching video surveillance on/off (#7938) #7968

Merged
merged 11 commits into from
Jun 28, 2020
Merged

[netatmo] Support for switching video surveillance on/off (#7938) #7968

merged 11 commits into from
Jun 28, 2020

Conversation

Novanic
Copy link
Contributor

@Novanic Novanic commented Jun 21, 2020

With this change it is possible to switch the video surveillance on and off (for all cameras / Welcome and Presence). See issue #7938 for more information.

When a camera related command is executed a refresh is executed after 2 seconds to update all channels. This has for example following effects:

  • When the floodlight is switched on/off a new live picture gets received with the new floodlight state.
  • When the video surveillance is switched on/off an event is received to confirm the new state.

Novanic and others added 10 commits June 10, 2020 19:50
- The video surveillance can now get switched on/off
- When the command is executed (floodlight or video surveillance switched on/off) a refresh is executed after 2 seconds to update all channels

Signed-off-by: Sven Strohschein <[email protected]>
Signed-off-by: Sven Strohschein <[email protected]>
@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.

@lolodomo
Copy link
Contributor

lolodomo commented Jun 21, 2020

Version deployed and I can confirm that last event and live picture are now correctly refreshed quickly just after switching on or off the surveillance.

This is probably the enhancement that will add the best value to my home automation system since months. Thanks for finding that.

Remains to review the code.

Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

Just a comment about the log level for me.

Your new method getModule() could be used in the same way in other handlers (to be done in separate PRs).

try {
return executeGETRequest(url).map(JSONObject::new);
} catch (JSONException e) {
logger.warn("Error on parsing the content as JSON!", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

A DEBUG log will be sufficient I think.

Copy link
Contributor Author

@Novanic Novanic Jun 21, 2020

Choose a reason for hiding this comment

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

Debug? When this error occurs, it is an error, the functionality is broken when it occurs. That shouldn't happen. Actually warning isn't enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

My general rule for logging levels is:

  • trace - used for normal expected execution paths
  • debug - used for unexepected execution paths, but well within normal operation
  • info - used for notable points in an execution path, like a milestone. (in openhab we try reserve this logging level for the core, so bindings should rarely ever call this.)
  • warn - used for notable unexpected execution paths that a regular user (not just a developer) should be notified of. Warnings should be used to indicate that something not-normal occurred and user intervention is required to resolve. Warnings do not indicate a failure to operate merely an abnormal condition of operation that can still be handled by the binding. Failures in binding operation should be indicated by changing the thing status to offline.
  • error - used to indicate catastrophic program failure. This should be used to indicate a catastrophic failure in openhab's ability to operate. A failure in a binding would never cause openhab as a whole to fail so a failure in a bindings should never log an error. Instead that failure should be indicated by changing the thing status.

Now if a JSONException does occur here it doesn't really reflect a failure in the binding so much a failure in an external system and can be thought of more or less akin to connection loss. If you think that such a json parsing failure should be elevated above "warn" then I suggest changing the thing status to OFFLINE to reflect that.

return Optional.of(content);
}
} catch (IOException e) {
logger.warn("Error on accessing local camera url!", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

A DEBUG log will be sufficient I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that such an exception should probably be elevated to the caller since I don't think that simple logging would be how all callers would like this particular issue to be handled.

@Novanic
Copy link
Contributor Author

Novanic commented Jun 21, 2020

Debug? When this error occurs, it is an error, the functionality is broken when it occurs. That shouldn't happen. Actually warning isn't enough.

@lolodomo
Copy link
Contributor

lolodomo commented Jun 21, 2020

Please read the coding guidelines for binding developers, there is an explanation about log levels.

@lolodomo
Copy link
Contributor

@lolodomo
Copy link
Contributor

@cpmeister will correct me if I am wrong in my comments.

Signed-off-by: Sven Strohschein <[email protected]>
@Novanic
Copy link
Contributor Author

Novanic commented Jun 21, 2020

I have found a performance / network resource optimization. At the moment the home data (which is requested at least every 5 minutes and after every executed command) is requested with 30 events by default (+ sub-events), but the binding processes only the latest event. So the request within NetatmoBridgeHandler#getWelcomeDataBody(...) could get changed to request just 1 event (via a query-parameter). Should I change the line with this pull-request or should I open a new issue and pull-request?

@lolodomo
Copy link
Contributor

I have found a performance / network resource optimization. At the moment the home data (which is requested at least every 5 minutes and after every executed command) is requested with 30 events by default (+ sub-events), but the binding processes only the latest event. So the request within NetatmoBridgeHandler#getWelcomeDataBody(...) could get changed to request just 1 event (via a query-parameter). Should I change the line with this pull-request or should I open a new issue and pull-request?

I would suggest a separate PR.
Maybe wait for @clinique comment, I have in mind this point was discussed a long time ago. We have to be sure that only the last event is processed, and not all new events since the last retrieval. For the persons detection, are you really sure that some of the events are ignored ?

@Novanic
Copy link
Contributor Author

Novanic commented Jun 21, 2020

I have found a performance / network resource optimization. At the moment the home data (which is requested at least every 5 minutes and after every executed command) is requested with 30 events by default (+ sub-events), but the binding processes only the latest event. So the request within NetatmoBridgeHandler#getWelcomeDataBody(...) could get changed to request just 1 event (via a query-parameter). Should I change the line with this pull-request or should I open a new issue and pull-request?

I would suggest a separate PR.
Maybe wait for @clinique comment, I have in mind this point was discussed a long time ago. We have to be sure that only the last event is processed, and not all new events since the last retrieval. For the persons detection, are you really sure that some of the events are ignored ?

Yes, I'm sure. Only the event with the newest time is processed, all other events are ignored/filtered. You can search for usages of NAWelcomeHome#getEvents(). There is only this one usage.

@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.

@lolodomo
Copy link
Contributor

lolodomo commented Jun 21, 2020

At this place, I see we are going through the list of events to filter on events relative to a person, that means it is not necessarily the most recent event. This must not be broken.
https://github.com/openhab/openhab-addons/blob/2.5.x/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/welcome/NAWelcomePersonHandler.java#L59

@lolodomo
Copy link
Contributor

@cpmeister : could you please review and tell us what should be done regarding log levels (my only comments about this PR).

PS: I am waiting for the merge of this PR to restart adding null annotations.

try {
return executeGETRequest(url).map(JSONObject::new);
} catch (JSONException e) {
logger.warn("Error on parsing the content as JSON!", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

My general rule for logging levels is:

  • trace - used for normal expected execution paths
  • debug - used for unexepected execution paths, but well within normal operation
  • info - used for notable points in an execution path, like a milestone. (in openhab we try reserve this logging level for the core, so bindings should rarely ever call this.)
  • warn - used for notable unexpected execution paths that a regular user (not just a developer) should be notified of. Warnings should be used to indicate that something not-normal occurred and user intervention is required to resolve. Warnings do not indicate a failure to operate merely an abnormal condition of operation that can still be handled by the binding. Failures in binding operation should be indicated by changing the thing status to offline.
  • error - used to indicate catastrophic program failure. This should be used to indicate a catastrophic failure in openhab's ability to operate. A failure in a binding would never cause openhab as a whole to fail so a failure in a bindings should never log an error. Instead that failure should be indicated by changing the thing status.

Now if a JSONException does occur here it doesn't really reflect a failure in the binding so much a failure in an external system and can be thought of more or less akin to connection loss. If you think that such a json parsing failure should be elevated above "warn" then I suggest changing the thing status to OFFLINE to reflect that.

return Optional.of(content);
}
} catch (IOException e) {
logger.warn("Error on accessing local camera url!", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that such an exception should probably be elevated to the caller since I don't think that simple logging would be how all callers would like this particular issue to be handled.

@cpmeister cpmeister added the enhancement An enhancement or new feature for an existing add-on label Jun 25, 2020
@Novanic
Copy link
Contributor Author

Novanic commented Jun 25, 2020

@cpmeister : could you please review and tell us what should be done regarding log levels (my only comments about this PR).

PS: I am waiting for the merge of this PR to restart adding null annotations.

Hm, that you for the explanation, but I don't know what I should do.
1.) Debug?
2.) Debug + Thing to offline?
3.) Warn?
4.) Warn + Thing to offline?

@cpmeister
Copy link
Contributor

Hm, that you for the explanation, but I don't know what I should do.
1.) Debug?
2.) Debug + Thing to offline?
3.) Warn?
4.) Warn + Thing to offline?

If you think that an IOException can be considered making the binding inoperable, then just set the thing to offline along with a message. Otherwise log it as a warn in order for the user to be notified of the issue. Debug should be used if those errors would be a regular occurrence during binding operation.

@lolodomo
Copy link
Contributor

lolodomo commented Jun 26, 2020

So finally the WARN level was no so bad ;)
We could keep your code as it is.

Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

LGTM

@lolodomo
Copy link
Contributor

I need the merge of this PR to progress.
@clinique can you review it?
@cpmeister : not available?

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.

Good job. LGTM

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.

LGTM

@cpmeister cpmeister linked an issue Jun 28, 2020 that may be closed by this pull request
@cpmeister cpmeister merged commit 05eb61d into openhab:2.5.x Jun 28, 2020
@cpmeister cpmeister added this to the 2.5.7 milestone Jun 28, 2020
knikhilwiz pushed a commit to knikhilwiz/openhab2-addons that referenced this pull request Jul 12, 2020
* [7938] Support for switching video surveillance on/off
- The video surveillance can now get switched on/off
- When the command is executed (floodlight or video surveillance switched on/off) a refresh is executed after 2 seconds to update all channels
* Warnings fixed
* New tests for isNewLastEvent added

Signed-off-by: Sven Strohschein <[email protected]>
CSchlipp pushed a commit to CSchlipp/openhab-addons that referenced this pull request Jul 26, 2020
* [7938] Support for switching video surveillance on/off
- The video surveillance can now get switched on/off
- When the command is executed (floodlight or video surveillance switched on/off) a refresh is executed after 2 seconds to update all channels
* Warnings fixed
* New tests for isNewLastEvent added

Signed-off-by: Sven Strohschein <[email protected]>
Signed-off-by: CSchlipp <[email protected]>
MPH80 pushed a commit to MPH80/openhab-addons that referenced this pull request Aug 3, 2020
* [7938] Support for switching video surveillance on/off
- The video surveillance can now get switched on/off
- When the command is executed (floodlight or video surveillance switched on/off) a refresh is executed after 2 seconds to update all channels
* Warnings fixed
* New tests for isNewLastEvent added

Signed-off-by: Sven Strohschein <[email protected]>
Signed-off-by: MPH80 <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [7938] Support for switching video surveillance on/off
- The video surveillance can now get switched on/off
- When the command is executed (floodlight or video surveillance switched on/off) a refresh is executed after 2 seconds to update all channels
* Warnings fixed
* New tests for isNewLastEvent added

Signed-off-by: Sven Strohschein <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [7938] Support for switching video surveillance on/off
- The video surveillance can now get switched on/off
- When the command is executed (floodlight or video surveillance switched on/off) a refresh is executed after 2 seconds to update all channels
* Warnings fixed
* New tests for isNewLastEvent added

Signed-off-by: Sven Strohschein <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [7938] Support for switching video surveillance on/off
- The video surveillance can now get switched on/off
- When the command is executed (floodlight or video surveillance switched on/off) a refresh is executed after 2 seconds to update all channels
* Warnings fixed
* New tests for isNewLastEvent added

Signed-off-by: Sven Strohschein <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [7938] Support for switching video surveillance on/off
- The video surveillance can now get switched on/off
- When the command is executed (floodlight or video surveillance switched on/off) a refresh is executed after 2 seconds to update all channels
* Warnings fixed
* New tests for isNewLastEvent added

Signed-off-by: Sven Strohschein <[email protected]>
DaanMeijer pushed a commit to DaanMeijer/openhab-addons that referenced this pull request Sep 1, 2020
* [7938] Support for switching video surveillance on/off
- The video surveillance can now get switched on/off
- When the command is executed (floodlight or video surveillance switched on/off) a refresh is executed after 2 seconds to update all channels
* Warnings fixed
* New tests for isNewLastEvent added

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
* [7938] Support for switching video surveillance on/off
- The video surveillance can now get switched on/off
- When the command is executed (floodlight or video surveillance switched on/off) a refresh is executed after 2 seconds to update all channels
* Warnings fixed
* New tests for isNewLastEvent added

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 for switching video surveillance on/off
6 participants