-
-
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
[epsonprojector] Update epsonprojector binding for OH3 #9021
Conversation
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
And thanks to you for finishing it @mlobstein! - it looks good and will surely be better maintained by you :) The implementation wasn't perfect, mostly straight from OH1, querying for unavailable data when off etc. But I had some stability issues when the connection was closed too frequently, after some time the projector wouldn't respond to any commands so I figure I didn't want to mess with it too much once it was stable enough for me. Nonetheless, glad to see that improved! I'll be sure to give it a try asap. |
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
...rojector/src/main/java/org/openhab/binding/epsonprojector/internal/EpsonProjectorDevice.java
Outdated
Show resolved
Hide resolved
...rojector/src/main/java/org/openhab/binding/epsonprojector/internal/EpsonProjectorDevice.java
Outdated
Show resolved
Hide resolved
...rojector/src/main/java/org/openhab/binding/epsonprojector/internal/EpsonProjectorDevice.java
Outdated
Show resolved
Hide resolved
...ava/org/openhab/binding/epsonprojector/internal/connector/EpsonProjectorSerialConnector.java
Outdated
Show resolved
Hide resolved
...ava/org/openhab/binding/epsonprojector/internal/connector/EpsonProjectorSerialConnector.java
Outdated
Show resolved
Hide resolved
...ava/org/openhab/binding/epsonprojector/internal/connector/EpsonProjectorSerialConnector.java
Outdated
Show resolved
Hide resolved
...ava/org/openhab/binding/epsonprojector/internal/connector/EpsonProjectorSerialConnector.java
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.epsonprojector/src/main/resources/OH-INF/binding/binding.xml
Outdated
Show resolved
Hide resolved
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
...rojector/src/main/java/org/openhab/binding/epsonprojector/internal/EpsonProjectorDevice.java
Outdated
Show resolved
Hide resolved
...ava/org/openhab/binding/epsonprojector/internal/connector/EpsonProjectorSerialConnector.java
Outdated
Show resolved
Hide resolved
...ava/org/openhab/binding/epsonprojector/internal/connector/EpsonProjectorSerialConnector.java
Outdated
Show resolved
Hide resolved
Are you kidding? This is the field where the major contributors, present
and past, are given credit.
Author(s) != maintainer.
Not that I care that much to have mine kept here, it's for the principle,
much dissention has already happened because of things like that...
…On Sun, Nov 22, 2020, 09:31 Fabian Wolter ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
bundles/org.openhab.binding.epsonprojector/src/main/resources/OH-INF/binding/binding.xml
<#9021 (comment)>
:
> @@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<binding:binding id="epsonprojector" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:binding="https://openhab.org/schemas/binding/v1.0.0"
+ xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd">
+
+ <name>Epson Projector Binding</name>
+ <description>This binding is compatible with Epson projectors which support the ESC/VP21 protocol</description>
+ <author>Pauli Anttila, Yannick Schaus</author>
If I understand correctly, you took over the binding and you are the
maintainer now. So, I'd suggest that it's only your name in the author tag.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9021 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPJJMYQPYAML336HCWBNN3SRDD4RANCNFSM4TVLQU4Q>
.
|
It was only a suggestion. I'm fine if you keep all three authors. |
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
...ava/org/openhab/binding/epsonprojector/internal/connector/EpsonProjectorSerialConnector.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
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
...va/org/openhab/binding/epsonprojector/internal/connector/EpsonProjectorDefaultConnector.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/openhab/binding/epsonprojector/internal/handler/EpsonProjectorHandler.java
Outdated
Show resolved
Hide resolved
pollingJob = scheduler.scheduleWithFixedDelay(() -> { | ||
for (Channel channel : channels) { | ||
// only query power & lamp time when projector is off | ||
if (isPowerOn || (channel.getUID().getId().equals(CHANNEL_TYPE_POWER) | ||
|| channel.getUID().getId().equals(CHANNEL_TYPE_LAMPTIME))) { | ||
updateChannelState(channel); | ||
} | ||
} | ||
}, 0, (pollingInterval > 0) ? pollingInterval : DEFAULT_POLLING_INTERVAL_SEC, TimeUnit.SECONDS); |
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 should avoid assigning class fields asynchronously since this handler might get disposed before you have a chance to assign it. This might lead to the case where this periodic task is never canceled.
Instead you should create this task during initialize
and then inside the task just check if the device is connected or not before trying to update the channels.
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 should be fixed now.
if (in.markSupported()) { | ||
in.reset(); | ||
} |
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.
At no point to you create any marks. What exactly are you resetting here?
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.
...ava/org/openhab/binding/epsonprojector/internal/connector/EpsonProjectorSerialConnector.java
Outdated
Show resolved
Hide resolved
...n/java/org/openhab/binding/epsonprojector/internal/connector/EpsonProjectorTcpConnector.java
Outdated
Show resolved
Hide resolved
private @Nullable InputStream in = null; | ||
private @Nullable OutputStream out = null; |
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 only seem to write characters to these streams. Why not make these a Reader and Writer instead?
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 had not considered this since the code was already written and had been scrutinized by the above mentioned PRs.
private @Nullable InputStream in = null; | ||
private @Nullable OutputStream out = null; |
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.
same suggestion
public void serialEvent(SerialPortEvent arg0) { | ||
} | ||
|
||
private String sendMmsg(String data, int timeout) throws IOException, EpsonProjectorException { |
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.
How are you handling the case where multiple message are sent at the same time from multiple threads? Are you already preventing this from happening?
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 is called by sendQuery() which is a synchronized method... Is that sufficient?
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 sufficient, but it would be safer if you did the synchronization in this class instead. It looks safe enough as is though, so you don't have to change it.
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
if (THING_TYPE_PROJECTOR_SERIAL.equals(thingTypeUID)) { | ||
device = new EpsonProjectorDevice(serialPortManager, getConfigAs(EpsonProjectorConfiguration.class)); | ||
} else { | ||
device = new EpsonProjectorDevice(getConfigAs(EpsonProjectorConfiguration.class)); | ||
} |
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 should move this to initialize() method, otherwise user configuration changes are not taken in use.
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.
Hmm, but then device still needs to be set to something here to satisfy the notnullbydefault. And EpsonProjectorDevice needs a connector in the constructor which is why I had done the EpsonProjectorDefaultConnector.
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.
Well, notnullbydefault just forces you to think which field can be null and which not. In this case device can't be initialised or be final as it depends on the thing configuration an it can change during thing life time.
So it should be fine to be nullable
private @Nullable EpsonProjectorDevice device;
or if you want to avoid nulls, you could make it optional
private Optional<EpsonProjectorDevice> device = Optional.empty();
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.
OK, fixed (using Optional).
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
public void serialEvent(SerialPortEvent arg0) { | ||
} | ||
|
||
private String sendMmsg(String data, int timeout) throws IOException, EpsonProjectorException { |
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 sufficient, but it would be safer if you did the synchronization in this class instead. It looks safe enough as is though, so you don't have to change it.
...src/main/java/org/openhab/binding/epsonprojector/internal/handler/EpsonProjectorHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
scheduler.scheduleWithFixedDelay(() -> { | ||
ready = true; | ||
}, 0, 10000, TimeUnit.MILLISECONDS); |
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 need to keep track of the Future this returns so you can cancel it during disconnect.
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 this was put in to get rid of a 10 second thread.sleep(). It should only be a one time delay for 10 seconds before setting ready back to true, so I changed it to schedule() instead.
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 still need to track the future so you can cancel it if the handler is disposed before 10 seconds expires.
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 there's a glitch in the Matrix #9021 (comment)
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 made it cancel on disconnect.
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
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.
Just some minor final tweaks.
...rojector/src/main/java/org/openhab/binding/epsonprojector/internal/EpsonProjectorDevice.java
Outdated
Show resolved
Hide resolved
...rojector/src/main/java/org/openhab/binding/epsonprojector/internal/EpsonProjectorDevice.java
Outdated
Show resolved
Hide resolved
...rojector/src/main/java/org/openhab/binding/epsonprojector/internal/EpsonProjectorDevice.java
Outdated
Show resolved
Hide resolved
...rojector/src/main/java/org/openhab/binding/epsonprojector/internal/EpsonProjectorDevice.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/openhab/binding/epsonprojector/internal/handler/EpsonProjectorHandler.java
Outdated
Show resolved
Hide resolved
|
||
private void updateChannelState(Channel channel) { | ||
try { | ||
if (!isLinked(channel.getUID()) && !channel.getUID().getId().equals(CHANNEL_TYPE_POWER)) { |
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.
power state will be queried even if the channel isn't linked?
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.
Yes for two reasons:
- If no channels are linked, power is still checked as a ping of the device to set the status to ONLINE and later OFFLINE if the connection is lost.
- In the edge case of the user not linking the power channel, the power status still needs to be known to properly set the isPowerOn boolean (ie: only PWR? and LAMP? queries can be done when the power is off, because all others would fail).
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
* baseline EpsonProjector code from ysc * Improvements for OH3 * Finish epsonprojector binding for OH3 * improve exception logging * cleanup exception logging * Make connection specific thing types
* baseline EpsonProjector code from ysc * Improvements for OH3 * Finish epsonprojector binding for OH3 * improve exception logging * cleanup exception logging * Make connection specific thing types Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
* baseline EpsonProjector code from ysc * Improvements for OH3 * Finish epsonprojector binding for OH3 * improve exception logging * cleanup exception logging * Make connection specific thing types Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
I have picked up where PR #7370 left off to bring the epsonprojector binding back for OH3. I have finished cleaning up the code & documentation and tested with two older projectors. Thanks to @ghys for starting this effort.
Test build:
https://github.com/mlobstein/mlobstein-beta-test/raw/master/org.openhab.binding.epsonprojector-3.0.0-SNAPSHOT.jar
https://github.com/mlobstein/mlobstein-beta-test/raw/master/org.openhab.binding.epsonprojector-3.0.0-SNAPSHOT-sources.jar