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

[pushbullet] Pushbullet Binding initial contribution #5668

Merged
merged 5 commits into from
Jul 3, 2019

Conversation

hakan42
Copy link
Contributor

@hakan42 hakan42 commented May 31, 2019

This is a reimplementation of the pushbullet action which I had authored for openHAB 1:

https://www.openhab.org/addons/actions/pushbullet/

Most of the "business" code is transplanted from OH1, and some adaptations made to be able to use this as an annotated action.

I have not tried to configure the rule via Paper UI, though.

@hakan42 hakan42 requested a review from a team as a code owner May 31, 2019 21:16
@wborn wborn added work in progress A PR that is not yet ready to be merged new binding If someone has started to work on a binding. For a new binding PR. labels May 31, 2019
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/pushbullet-re-implemented-for-openhab-2/75543/1

@davidgraeff
Copy link
Member

You need to add this bundle to the bill of materials (bom/..) file as well :)

@hakan42
Copy link
Contributor Author

hakan42 commented Jun 1, 2019

rebuild

@hakan42 hakan42 closed this Jun 1, 2019
@hakan42 hakan42 reopened this Jun 1, 2019
@hakan42 hakan42 changed the title [WIP] [pushbullet] Pushbullet binding, reimplemented for openHAB 2 [pushbullet] Pushbullet binding, reimplemented for openHAB 2 Jun 2, 2019
@hakan42
Copy link
Contributor Author

hakan42 commented Jun 2, 2019

rebuild...

@hakan42 hakan42 closed this Jun 2, 2019
@hakan42 hakan42 reopened this Jun 2, 2019
@hakan42
Copy link
Contributor Author

hakan42 commented Jun 2, 2019

Build failures are not caused by the binding itself.

See https://github.com/openhab/openhab2-addons/pull/5582

@wborn wborn added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build work in progress A PR that is not yet ready to be merged labels Jun 3, 2019
@wborn wborn changed the title [pushbullet] Pushbullet binding, reimplemented for openHAB 2 [pushbullet] Pushbullet Binding initial contribution Jun 3, 2019
Copy link
Member

@wborn wborn left a comment

Choose a reason for hiding this comment

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

Thanks for porting the action to an OH2 binding! I've added a few comments below:

bundles/org.openhab.binding.pushbullet/.project Outdated Show resolved Hide resolved
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.pushbullet;
Copy link
Member

Choose a reason for hiding this comment

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

Binding classes should no longer be exported by defaults.
So if possible move all classes into the internal package.

Suggested change
package org.openhab.binding.pushbullet;
package org.openhab.binding.internal.pushbullet;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would that be all classes like handlers and action definitions and so on? Or just the constants? Could you point me to a known-to-be-good example bundle?

Copy link
Member

Choose a reason for hiding this comment

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

All classes. Constants are actually the exception, if they are used across multiple bundles (like with the MQTT main and sub bundles).

Copy link
Member

Choose a reason for hiding this comment

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

It should be:

Suggested change
package org.openhab.binding.pushbullet;
package org.openhab.binding.pushbullet.internal;

The internal must be in the specific binding package not the other way around.

Copy link
Member

Choose a reason for hiding this comment

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

That's right! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

o.k., done.

@hakan42
Copy link
Contributor Author

hakan42 commented Jun 13, 2019

@wborn , your suggested changes lead to DCO violations.

Do you want me to squash the commits and force-push or will you manually "accept" them? Also, is there a way to improve our DCO checker for those "Co-Authored-By" lines?

@wborn
Copy link
Member

wborn commented Jun 13, 2019

I'm OK with squashing all the commits @hakan42 to fix the sign offs.

It's not strictly necessary because we can also fix the sign offs when we squash them when merging this PR.

DCO failing on those commits seems to be a known issue: dcoapp/app#102.

Also note that we use an Also-by: line for additional authors instead of Co-Authored-By:, see Sign your work.

If there are still pending or ongoing reviews it's usually better not to squash the commits so reviewers can check the changes.

@hakan42
Copy link
Contributor Author

hakan42 commented Jun 13, 2019

@wborn , @davidgraeff , I believe I adapted all your comments. Could you please give the PR another look? I'd love to have it merged for Milestone 2 😄

@hakan42
Copy link
Contributor Author

hakan42 commented Jun 13, 2019

Jenkins, please rebuild...

@hakan42 hakan42 closed this Jun 13, 2019
@hakan42 hakan42 reopened this Jun 13, 2019
@hakan42
Copy link
Contributor Author

hakan42 commented Jun 21, 2019

Jenkins, please rebuild...

@hakan42
Copy link
Contributor Author

hakan42 commented Jun 29, 2019

@openhab/2-x-add-ons-maintainers , could I ask for a friendly "LGTM"? This binding is working in my productive environment for multiple weeks now.

I squashed the commits to get rid of a wrong commit email address (incorrectly used the work git configuration), and rebased against the current master...

Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
Copy link
Member

@martinvw martinvw left a comment

Choose a reason for hiding this comment

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

Thanks for your binding I added some remarks, especially the catching of the Error is a no-go for me. Could you elaborate on that?

bundles/org.openhab.binding.pushbullet/README.md Outdated Show resolved Hide resolved

logger.debug("sendPush is called for ");
logger.debug("Thing {}", thing);
logger.debug("Thing Label: '{}'", thing.getLabel());
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this be resolved by the toString of the argument of the above logline

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In principle, yes. I just like being showed line-by-line debug information. Consider it a matter of taste please :)


PushbulletConfiguration configuration = getConfigAs(PushbulletConfiguration.class);
logger.debug("CFG {}", configuration);
logger.debug("CFG Name '{}'", configuration.getName());
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this be resolved by the toString of the argument of the above logline

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In principle, yes. I just like being showed line-by-line debug information. Consider it a matter of taste please :)

logger.warn("IO problems pushing note: {}", e.getMessage());
}

} catch (java.lang.Error e) {
Copy link
Member

Choose a reason for hiding this comment

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

Do not catch Error

Copy link
Contributor Author

@hakan42 hakan42 Jun 30, 2019

Choose a reason for hiding this comment

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

In this case, I have to catch Error to be able to obtain information about the HttpResponseException. Thereby, I can inform the user about expired tokens.

I could check for HttpResponseException, and if that is not the case, rethrow the original error. Would that be o.k. for you?

Copy link
Member

Choose a reason for hiding this comment

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

But who Throws an error, please not that errors are different branch from Exception it contains things like OutOfMemmoryError, StackOverflow etc

What exact error do you intend to catch and who threw it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Someone deep inside HttpUtil.executeUrl()... I'll try to provoke an exception so I can provide you with a full stack trace.

In the mean time, I'll check for the HttpResponseException (as mentioned above), and rethrow the exception if it did not contain what I was looking for. Would that be o.k. for you?

Copy link
Member

@martinvw martinvw Jul 1, 2019

Choose a reason for hiding this comment

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

Someone deep inside HttpUtil.executeUrl()... I'll try to provoke an exception so I can provide you with a full stack trace.

In the mean time, I'll check for the HttpResponseException (as mentioned above), and rethrow the exception if it did not contain what I was looking for. Would that be o.k. for you?

Exception would be 'fine' (and are indeed throw from HttpUtil) but you are catching the Error.

Please provide me with it, I would be surprised if its not an Exception but really an Error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please provide me with it, I would be surprised if its not an Exception but really an Error

As luck would have it, I am getting "normal" JSON answers to an invalid token just now. Whereas, earlier, it was packaged in the Error. Maybe the API changed since I had written the 1.x action class.

I'll remove the complete error-catching part and wait whether it happens again, then we can talk about how to handle it.

Copy link
Member

Choose a reason for hiding this comment

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

I'll remove the complete error-catching part and wait whether it happens again, then we can talk about how to handle it.

Great, just ping me when you are ready, we should be close to a merge then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@martinvw , I did refactor as discussed, and Travis is happy too. I think Jenkins will also be whenever it gets around to build this branch.

Could you give the PushbulletHandler class another look please?

logger.debug("Error in getResponseString: ", e);
}

return result;
Copy link
Member

Choose a reason for hiding this comment

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

Consider splitting up this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But how? logically, it is one operation. splitting it up would only serve to introduce multiple methods, but to no gain with regard to the logic that has to be performed.

Copy link
Member

Choose a reason for hiding this comment

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

I would say that it contains a lot of logic units, eg contructing the push message, or constructing and convert it to a string. Or performing the actual request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll refactor it later tonight, at the same time working on the error-catching part.

@@ -600,6 +600,11 @@
<artifactId>org.openhab.binding.pulseaudio</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Copy link
Member

Choose a reason for hiding this comment

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

@J-N-K / @maggu2810 / @openhab/2-x-add-ons-maintainers should a binding contain a feature.xml file now or only in special cases?

Choose a reason for hiding this comment

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

I did not follow the "a feature per addon" changes.
Perhaps this could be answered by @openhab/2-x-add-ons-maintainers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can see, all bindings contain a feature.xml (looking at the HEAD of openhab2-addons repo). Therefore, I moved "my" feature.xml into the binding source tree as well.

Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
@hakan42
Copy link
Contributor Author

hakan42 commented Jul 1, 2019

By the way, Jenkins failure is caused by an Out of Memory error while doing the karaf-feature-verification. Not directly caused by this binding, I hope :)

…ror anymore

Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
@hakan42
Copy link
Contributor Author

hakan42 commented Jul 3, 2019

Jenkins, please rebuild

@hakan42 hakan42 closed this Jul 3, 2019
@hakan42 hakan42 reopened this Jul 3, 2019
@@ -156,6 +156,7 @@
<module>org.openhab.binding.plugwise</module>
<module>org.openhab.binding.powermax</module>
<module>org.openhab.binding.pulseaudio</module>
<module>org.openhab.binding.pushbullet</module>
Copy link
Member

Choose a reason for hiding this comment

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

Could you add the binding to the codeowners

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first file in the "changes" tab shows the addition to CODEOWNERS.

I'll wait for your merge, and if does not show up in the HEAD , I'll create an additional PR as suggested

if ((null != response) && (null == response.getPushError())) {
result = true;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Formatting is a little bit a-typical

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe caused by my IntelliJ installation. It should have applied the Eclipse formatting rules though.

Can I fix that in an upcoming PR when I touch this code again?

Copy link
Member

@martinvw martinvw left a comment

Choose a reason for hiding this comment

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

Except for the missing codeowners its fine, feel free to create another PR for that. If no-one else has something before 22:00 CEST I will merge.

@martinvw martinvw requested a review from a team July 3, 2019 18:27
Copy link
Member

@davidgraeff davidgraeff left a comment

Choose a reason for hiding this comment

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

Looks good except those multiple debug lines (remember that each log line is executed even if not at the debug level. Meaning loading the arguments to registers, initiate a call stack, jump to the method, call the framework to determine the logger level we are in, aborting)

@martinvw
Copy link
Member

martinvw commented Jul 3, 2019

Looks good except those multiple debug lines (remember that each log line is executed even if not at the debug level. Meaning loading the arguments to registers, initiate a call stack, jump to the method, call the framework to determine the logger level we are in, aborting)

Agree on that, it would be nice if you be logging less next time or combine it in a lot less statements with the proper placeholders etc.

@martinvw martinvw merged commit 86191c5 into openhab:master Jul 3, 2019
@hakan42
Copy link
Contributor Author

hakan42 commented Jul 4, 2019

Thank you so much guys. And off I go, working on the next binding :)

@wborn wborn added this to the 2.5 milestone Jul 30, 2019
sprehn pushed a commit to sprehn/openhab-addons that referenced this pull request Aug 21, 2019
Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
ne0h pushed a commit to ne0h/openhab-addons that referenced this pull request Sep 15, 2019
Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
Signed-off-by: Maximilian Hess <mail@ne0h.de>
Pshatsillo pushed a commit to Pshatsillo/openhab-addons that referenced this pull request Dec 8, 2019
Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
tmrobert8 pushed a commit to tmrobert8/openhab-addons that referenced this pull request Jan 21, 2020
Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
Signed-off-by: Tim Roberts <timmarkroberts@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new binding If someone has started to work on a binding. For a new binding PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants