-
-
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
[novafinedust] Optimizations on access to the serial port #10005
Conversation
- retry logic if port does not yet exist on startup - do not write sleep command on shutdown if port has issues - no not register data listener on port but wait for data instead to be compatible with RFC2217 serial over network implementation - ignore all buffered data from device during initialization to get the device into a defined state Signed-off-by: Stefan Triller <github@stefantriller.de>
This PR makes the usage of the binding MUCH more reliable, i.e. I do not fear restarting my openHAB installation where I had to pray whether or not the device is still working afterwards. |
@@ -78,33 +86,40 @@ public boolean initialize(WorkMode mode, Duration interval) | |||
throws PortInUseException, TooManyListenersException, IOException, UnsupportedCommOperationException { | |||
boolean initSuccessful = true; | |||
|
|||
logger.debug("Initializing with mode={}, interval={}", mode, interval); |
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 suggest changing the logging level of most of these to trace
instead.
My general rule for logging levels is:
- trace - used for normal expected execution paths
- debug - used for unexepected execution paths, but well within normal operation
- info - used for notable points in an execution path, like a milestone. (in openhab we try reserve this logging level for the core, so bindings should rarely ever call this.)
- warn - used for notable unexpected execution paths that a regular user (not just a developer) should be notified of. Warnings should be used to indicate that something not-normal occurred and user intervention is required to resolve. Warnings do not indicate a failure to operate merely an abnormal condition of operation that can still be handled by the binding. Failures in binding operation should be indicated by changing the thing status to offline.
- error - used to indicate catastrophic program failure. This should be used to indicate a catastrophic failure in openhab's ability to operate. A failure in a binding would never cause openhab as a whole to fail so a failure in a bindings should never log an error. Instead that failure should be indicated by changing the thing status.
if (localScheduler != null) { | ||
Future<?> sleepJob = null; | ||
try { | ||
sleepJob = localScheduler.submit(new Runnable() { |
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 use a lambda here instead.
- moved most "normal" logging to TRACE level - used lambda function Signed-off-by: Stefan Triller <github@stefantriller.de>
Thanks for your review. I have moved most logging to TRACE and changed the scheduling of the sleepjob to use a lambda. I would appreciate if you can have another look. Thanks! |
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.
Only a few last changes I'd like.
try { | ||
write(commandData); | ||
} catch (IOException ioex) { | ||
logger.debug("Got an exception while writing a command, will not try to fetch a reply for 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.
You should include the exception message in the log so that it is easier to know what went wrong.
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, | ||
"Cannot query data from device"); |
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 include the exception message in the status detail so that users have a better idea of what went wrong.
Signed-off-by: Stefan Triller <github@stefantriller.de>
@cpmeister Thank you very much, I have integrated your changes. |
) * [novafinedust] Test for optimizations on access to the serial port - retry logic if port does not yet exist on startup - do not write sleep command on shutdown if port has issues - no not register data listener on port but wait for data instead to be compatible with RFC2217 serial over network implementation - ignore all buffered data from device during initialization to get the device into a defined state * Adress review comments - moved most "normal" logging to TRACE level - used lambda function * Improve error messages as requested in the review Signed-off-by: Stefan Triller <github@stefantriller.de> Signed-off-by: John Marshall <john.marshall.au@gmail.com>
) * [novafinedust] Test for optimizations on access to the serial port - retry logic if port does not yet exist on startup - do not write sleep command on shutdown if port has issues - no not register data listener on port but wait for data instead to be compatible with RFC2217 serial over network implementation - ignore all buffered data from device during initialization to get the device into a defined state * Adress review comments - moved most "normal" logging to TRACE level - used lambda function * Improve error messages as requested in the review Signed-off-by: Stefan Triller <github@stefantriller.de>
) * [novafinedust] Test for optimizations on access to the serial port - retry logic if port does not yet exist on startup - do not write sleep command on shutdown if port has issues - no not register data listener on port but wait for data instead to be compatible with RFC2217 serial over network implementation - ignore all buffered data from device during initialization to get the device into a defined state * Adress review comments - moved most "normal" logging to TRACE level - used lambda function * Improve error messages as requested in the review Signed-off-by: Stefan Triller <github@stefantriller.de>
compatible with RFC2217 serial over network implementation (see RFC2217 serial port over network: SerialPortEventListener does not work openhab-core#2170)
device into a defined state
Signed-off-by: Stefan Triller github@stefantriller.de