-
-
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
[pilight] Pilight Binding initial contribution + add discovery #9744
Conversation
b867a69
to
3ff4a63
Compare
Thanks for taking care of my pull request. Since I have not yet switched to openHAB 3, I didn't continue with it. |
3ff4a63
to
40448a7
Compare
I don't know why, but for some reason the last line break at the end of file
|
14cdeac
to
bc4ff2f
Compare
Could someone please set the rebuild label again? Thanks! Jenkins complained about the following in the last build, which has nothing to do with this binding from my point of view...
|
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 contribution! I reviewed your code and here is my feedback.
You code doesn't build, because the license header's year parameter isn't updated, yet.
To make the binding compile, you need to rebase your branch.
Here are the commands for rebasing your branch:
If not already done, add the upstream openHAB addon repo as a remote to your local repo and fetch it:
git remote add upstream https://github.com/openhab/openhab-addons.git
git fetch upstream
The remotes (git remote --verbose
) should look like this, now:
origin https://github.com/[your name]/openhab-addons.git (fetch)
origin https://github.com/[your name]/openhab-addons.git (push)
upstream https://github.com/openhab/openhab-addons.git (fetch)
upstream https://github.com/openhab/openhab-addons.git (push)
Then, you can rebase your PR's branch onto main
:
git rebase upstream/main
Finally force-push the rebased branch to this PR's branch:
git push origin [your branch name of this PR] --force-with-lease
DON'T use merge! This can clutter the Git history and make the PR unusable.
<dependencies> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.10.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<version>2.10.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
<version>2.10.4</version> | ||
</dependency> | ||
</dependencies> |
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.
Is there a reason why you don't use the default libraries for JSON processing? See https://www.openhab.org/docs/developer/guidelines.html#default-libraries
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 continue using jackson, because most of the code has been adopted from the Pilight binding for openHAB v1 and some functions are based on Jackson for which there is no direct equivalent in Gson. Maybe we can try to replace Jackson by Gson later.
bundles/org.openhab.binding.pilight/src/main/resources/OH-INF/binding/binding.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.pilight/src/main/resources/OH-INF/binding/binding.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.pilight/src/main/resources/OH-INF/i18n/pilight_de.properties
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.pilight/src/main/resources/OH-INF/thing/devices.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.pilight/src/main/resources/OH-INF/thing/devices.xml
Outdated
Show resolved
Hide resolved
Also-by: Stefan Roellin [email protected] Signed-off-by: Niklas Dörfler <[email protected]>
bc4ff2f
to
5ee4f93
Compare
Thank you @fwolter for your detailed comments. I'll take a look at the points and get back here as soon as I'm done with them. |
8d510d0
to
02452c7
Compare
Signed-off-by: Niklas Dörfler <[email protected]>
02452c7
to
24e735f
Compare
...hab.binding.pilight/src/main/java/org/openhab/binding/pilight/internal/PilightConnector.java
Outdated
Show resolved
Hide resolved
...hab.binding.pilight/src/main/java/org/openhab/binding/pilight/internal/PilightConnector.java
Outdated
Show resolved
Hide resolved
...hab.binding.pilight/src/main/java/org/openhab/binding/pilight/internal/PilightConnector.java
Outdated
Show resolved
Hide resolved
.../main/java/org/openhab/binding/pilight/internal/discovery/PilightBridgeDiscoveryService.java
Outdated
Show resolved
Hide resolved
.../main/java/org/openhab/binding/pilight/internal/discovery/PilightBridgeDiscoveryService.java
Outdated
Show resolved
Hide resolved
...pilight/src/main/java/org/openhab/binding/pilight/internal/handler/PilightDimmerHandler.java
Outdated
Show resolved
Hide resolved
...pilight/src/main/java/org/openhab/binding/pilight/internal/handler/PilightDimmerHandler.java
Outdated
Show resolved
Hide resolved
...pilight/src/main/java/org/openhab/binding/pilight/internal/handler/PilightDimmerHandler.java
Outdated
Show resolved
Hide resolved
...pilight/src/main/java/org/openhab/binding/pilight/internal/handler/PilightDimmerHandler.java
Outdated
Show resolved
Hide resolved
...pilight/src/main/java/org/openhab/binding/pilight/internal/handler/PilightDimmerHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Niklas Dörfler <[email protected]>
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.
Can you also try to address the compiler warnings that show up when building your project?
|
||
final Scanner scanner = new Scanner(new ByteArrayInputStream(recvData), | ||
StandardCharsets.UTF_8); | ||
scanner.findAll("Location:([0-9.]+):(.*)").forEach(matchResult -> { |
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.
You can avoid making loop
an AtomicBoolean by using Stream.peek().count() instead of foreach. You can use the returned count value to set your loop
value.
scanner.findAll("Location:([0-9.]+):(.*)").forEach(matchResult -> { | |
scanner.findAll("Location:([0-9.]+):(.*)").peek(matchResult -> { |
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.
Good idea, but is it good practise to use peek
for this? According to the documentation, it is mainly intended for debugging.
This method exists mainly to support debugging, where you want to see the elements as they flow past a certain point in a pipeline.
bundles/org.openhab.binding.pilight/src/main/resources/OH-INF/thing/devices.xml
Outdated
Show resolved
Hide resolved
.../main/java/org/openhab/binding/pilight/internal/discovery/PilightBridgeDiscoveryService.java
Outdated
Show resolved
Hide resolved
.../main/java/org/openhab/binding/pilight/internal/discovery/PilightDeviceDiscoveryService.java
Outdated
Show resolved
Hide resolved
.../main/java/org/openhab/binding/pilight/internal/discovery/PilightDeviceDiscoveryService.java
Outdated
Show resolved
Hide resolved
.../main/java/org/openhab/binding/pilight/internal/discovery/PilightDeviceDiscoveryService.java
Show resolved
Hide resolved
.../main/java/org/openhab/binding/pilight/internal/discovery/PilightDeviceDiscoveryService.java
Outdated
Show resolved
Hide resolved
.../main/java/org/openhab/binding/pilight/internal/discovery/PilightDeviceDiscoveryService.java
Outdated
Show resolved
Hide resolved
.../main/java/org/openhab/binding/pilight/internal/discovery/PilightDeviceDiscoveryService.java
Outdated
Show resolved
Hide resolved
@cpmeister: Yes, I already tried to get rid of the compiler warnings, but to be honest I'm not quite sure, why some of the warnings occur and how to fix them, e.g.: @Nullable Object test;
if (test != null) {
test.doSomething();
} This leads to a |
In order to resolve most of the compiler warnings you need to cache the |
I resolved most of the compiler warnings, except for two, that I'm not sure how to solve:
|
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.
You did a fantastic job on addressing the warnings. The remaining warnings don't need to be addressed.
I think there is only this last change then we are good to go.
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.10.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<version>2.10.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
<version>2.10.4</version> | ||
</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.
I think these libraries are already available to you from the core. They are version 2.10.1 though. Would it be alright to use those instead? If it doesn't work to remove these dependencies from the pom file then you can just manually specify them as a provided dependency like so:
<dependency> | |
<groupId>com.fasterxml.jackson.core</groupId> | |
<artifactId>jackson-databind</artifactId> | |
<version>2.10.4</version> | |
</dependency> | |
<dependency> | |
<groupId>com.fasterxml.jackson.core</groupId> | |
<artifactId>jackson-annotations</artifactId> | |
<version>2.10.4</version> | |
</dependency> | |
<dependency> | |
<groupId>com.fasterxml.jackson.core</groupId> | |
<artifactId>jackson-core</artifactId> | |
<version>2.10.4</version> | |
</dependency> | |
<dependency> | |
<groupId>com.fasterxml.jackson.core</groupId> | |
<artifactId>jackson-databind</artifactId> | |
<version>2.10.1</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>com.fasterxml.jackson.core</groupId> | |
<artifactId>jackson-annotations</artifactId> | |
<version>2.10.1</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>com.fasterxml.jackson.core</groupId> | |
<artifactId>jackson-core</artifactId> | |
<version>2.10.1</version> | |
<scope>provided</scope> | |
</dependency> |
If you are forced to add it as a provided dependency then you will also need to add those dependencies to the feature.xml file as well. Not terribly difficult but I would rather have you use an existing dependency than to bring in a new one.
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 the first step, I removed the dependencies from the .pom and my local build was successful. Let's see what Jenkins says. Looks like Jenkins is happy too.
03badc0
to
945d9a4
Compare
if (delayedActionWorkerFuture != null) { | ||
delayedActionWorkerFuture.cancel(false); | ||
} |
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 would cancel the already canceled future.
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'm not quite sure, what you mean. This call takes place in the lambda function of the fixed delay scheduler. In each run of it, I check if there are remaining elements in the delayedActionQueue
and poll one of them to call doSendAction()
. If the queue is empty I need to cancel the scheduler. I think it is a valid case here or am I wrong?
Maybe you can explain in more detail what you are thinking?
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'm saying that the old code referenced the delayedActionWorkerFuture
field, but now it is referencing the delayedActionWorkerFuture
local variable. The local variable has already been determined to be cancelled at this point in the code. It clear that your intent is to cancel the future field rather than the local variable. You need to make a second local variable inside the lambda to grab a fresh reference of the field.
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.
Ah sure, now I get your point!
Signed-off-by: Niklas Dörfler <[email protected]>
945d9a4
to
c352d60
Compare
bundles/org.openhab.binding.pilight/src/main/resources/OH-INF/thing/bridge.xml
Outdated
Show resolved
Hide resolved
…thing/bridge.xml Signed-off-by: Fabian Wolter <[email protected]>
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
Signed-off-by: Niklas Dörfler <[email protected]> Signed-off-by: John Marshall <[email protected]>
Signed-off-by: Niklas Dörfler <[email protected]>
Signed-off-by: Niklas Dörfler <[email protected]>
Migrate the already existing pilight binding from openhab1-addons (https://www.openhab.org/addons/bindings/pilight1/) to openHAB 3. Also some discovery logic to auto discover the pilight daemon as a bridge and the configured devices from the pilight daemon is added.
This PR is based on the still unmerged PR #8469, which could be closed afterwards, since it was used as a basis for this PR.
Built .jar of the binding is available here: https://openhab.jfrog.io/artifactory/libs-pullrequest-local/org/openhab/addons/bundles/org.openhab.binding.pilight/3.1.0-SNAPSHOT/org.openhab.binding.pilight-3.1.0-SNAPSHOT.jar