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

[ihc] Changed pulse command to use scheduling #5417

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -428,25 +428,21 @@ private void sendPulseCommand(ChannelUID channelUID, ChannelParams params, WSRes
// set resource to ON
logger.debug("Update resource value (inverted output={}): {}", params.isInverted(), valOn);
if (updateResource(valOn)) {
scheduler.submit(() -> {
// sleep a while
try {
logger.debug("Sleeping: {}ms", pulseWidth);
Thread.sleep(pulseWidth);
} catch (InterruptedException e) {
// do nothing
}
// set resource back to OFF

logger.debug("Update resource value (inverted output={}): {}", params.isInverted(), valOff);
try {
if (!updateResource(valOff)) {
logger.warn("Channel {} update to resource '{}' failed.", channelUID, valOff);
logger.debug("Sleeping: {}ms", pulseWidth);
scheduler.schedule(new Runnable() {
@Override
public void run() {
// set resource back to OFF
logger.debug("Update resource value (inverted output={}): {}", params.isInverted(), valOff);
try {
if (!updateResource(valOff)) {
logger.warn("Channel {} update to resource '{}' failed.", channelUID, valOff);
}
} catch (IhcExecption e) {
logger.error("Can't update channel '{}' value, cause ", channelUID, e.getMessage(), e);
Copy link
Member

Choose a reason for hiding this comment

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

Can you change log levels from error to warn in a follow up PR? That would be really great.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I can do it, but I made quick search to openhab2 addons project and there seems to be almost 1500 error levels used over 100 bindings 😃

Copy link
Member

Choose a reason for hiding this comment

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

Yup. They are all wrong. But good point, need to be automatically replaced.
See also my PR on the contribution page: openhab/openhab-docs#933

}
} catch (IhcExecption e) {
logger.error("Can't update channel '{}' value, cause ", channelUID, e.getMessage(), e);
}
});
}, pulseWidth, TimeUnit.MILLISECONDS);
} else {
logger.warn("Channel {} update failed.", channelUID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -536,38 +535,32 @@ private void mysleep(long milli) {
}

private void sendErrorEvent(IhcExecption err) {
Iterator<IhcEventListener> iterator = eventListeners.iterator();

while (iterator.hasNext()) {
eventListeners.forEach(listener -> {
try {
iterator.next().errorOccured(err);
listener.errorOccured(err);
} catch (RuntimeException e) {
logger.debug("Event listener invoking error. ", e);
logger.debug("Event listener invoking error.", e);
}
}
});
}

private void sendControllerStateUpdateEvent(WSControllerState state) {
Iterator<IhcEventListener> iterator = eventListeners.iterator();

while (iterator.hasNext()) {
eventListeners.forEach(listener -> {
try {
iterator.next().statusUpdateReceived(state);
listener.statusUpdateReceived(state);
} catch (RuntimeException e) {
logger.debug("Event listener invoking error. ", e);
logger.debug("Event listener invoking error.", e);
}
}
});
}

private void sendResourceValueUpdateEvent(WSResourceValue value) {
Iterator<IhcEventListener> iterator = eventListeners.iterator();

while (iterator.hasNext()) {
eventListeners.forEach(listener -> {
try {
iterator.next().resourceValueUpdateReceived(value);
listener.resourceValueUpdateReceived(value);
} catch (RuntimeException e) {
logger.debug("Event listener invoking error. ", e);
logger.debug("Event listener invoking error.", e);
}
}
});
}
}