-
-
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
[pushbullet] Pushbullet Binding initial contribution #5668
Conversation
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 |
You need to add this bundle to the bill of materials (bom/..) file as well :) |
rebuild |
rebuild... |
Build failures are not caused by the binding itself. See https://github.com/openhab/openhab2-addons/pull/5582 |
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.
Thanks for porting the action to an OH2 binding! I've added a few comments below:
...nding.pushbullet/src/main/java/org/openhab/binding/pushbullet/handler/PushbulletHandler.java
Outdated
Show resolved
Hide resolved
...nding.pushbullet/src/main/java/org/openhab/binding/pushbullet/handler/PushbulletHandler.java
Outdated
Show resolved
Hide resolved
...hab.binding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/model/Push.java
Outdated
Show resolved
Hide resolved
...inding.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/model/PushError.java
Outdated
Show resolved
Hide resolved
...ing.pushbullet/src/main/java/org/openhab/binding/pushbullet/internal/model/PushResponse.java
Outdated
Show resolved
Hide resolved
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.pushbullet; |
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.
Binding classes should no longer be exported by defaults.
So if possible move all classes into the internal package.
package org.openhab.binding.pushbullet; | |
package org.openhab.binding.internal.pushbullet; |
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.
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?
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.
All classes. Constants are actually the exception, if they are used across multiple bundles (like with the MQTT main and sub bundles).
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 should be:
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.
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.
That's right! 👍
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.
o.k., done.
...nding.pushbullet/src/main/java/org/openhab/binding/pushbullet/handler/PushbulletHandler.java
Outdated
Show resolved
Hide resolved
...nding.pushbullet/src/main/java/org/openhab/binding/pushbullet/handler/PushbulletHandler.java
Outdated
Show resolved
Hide resolved
...nding.pushbullet/src/main/java/org/openhab/binding/pushbullet/handler/PushbulletHandler.java
Outdated
Show resolved
Hide resolved
@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? |
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 If there are still pending or ongoing reviews it's usually better not to squash the commits so reviewers can check the changes. |
@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 😄 |
Jenkins, please rebuild... |
Jenkins, please rebuild... |
0df3f93
to
b9cba02
Compare
d8e5933
to
d80050a
Compare
@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>
d80050a
to
deeef36
Compare
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.
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?
...hbullet/src/main/java/org/openhab/binding/pushbullet/internal/handler/PushbulletHandler.java
Outdated
Show resolved
Hide resolved
|
||
logger.debug("sendPush is called for "); | ||
logger.debug("Thing {}", thing); | ||
logger.debug("Thing Label: '{}'", thing.getLabel()); |
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.
Wouldn't this be resolved by the toString of the argument of the above logline
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.
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()); |
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.
Wouldn't this be resolved by the toString of the argument of the above logline
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.
In principle, yes. I just like being showed line-by-line debug information. Consider it a matter of taste please :)
...hbullet/src/main/java/org/openhab/binding/pushbullet/internal/handler/PushbulletHandler.java
Outdated
Show resolved
Hide resolved
logger.warn("IO problems pushing note: {}", e.getMessage()); | ||
} | ||
|
||
} catch (java.lang.Error e) { |
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.
Do not catch Error
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.
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?
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.
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?
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.
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?
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.
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
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.
Please provide me with it, I would be surprised if its not an
Exception
but really anError
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.
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.
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
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.
@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; |
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.
Consider splitting up this method
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.
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.
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.
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.
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.
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> |
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.
@J-N-K / @maggu2810 / @openhab/2-x-add-ons-maintainers should a binding contain a feature.xml file now or only in special cases?
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.
I did not follow the "a feature per addon" changes.
Perhaps this could be answered by @openhab/2-x-add-ons-maintainers
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.
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>
1fa8067
to
74a35a8
Compare
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>
Jenkins, please rebuild |
@@ -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> |
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.
Could you add the binding to the codeowners
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 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; | ||
} | ||
} |
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.
Formatting is a little bit a-typical
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.
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?
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.
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.
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.
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. |
Thank you so much guys. And off I go, working on the next binding :) |
Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
Signed-off-by: Hakan Tandogan <hakan@tandogan.com> Signed-off-by: Maximilian Hess <mail@ne0h.de>
Signed-off-by: Hakan Tandogan <hakan@tandogan.com>
Signed-off-by: Hakan Tandogan <hakan@tandogan.com> Signed-off-by: Tim Roberts <timmarkroberts@gmail.com>
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.