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

[lgtvserial] Fix sending commands using serial port #11776

Merged
merged 1 commit into from
Dec 17, 2021

Conversation

carlospg79
Copy link
Contributor

I tried to fix bugs mentioned in #8646 about the problems to be able to send command to LG tv through serial port.

Bugfix for lg tv serial binding for greather versions of openHAB than 2.5

In previous versions of openHab <=2.4 the binding runs succesfully and can send commands to tv. But after upgrading openHAB, it didn't work anymore.

After debugging original component, I detected two bugs.

  1. channellinked function is never called, as mentioned for example in openHAB core repo #The channelLinked method is not called after restart openhab-core#1707 . Resulting in a null command because the commands list is empty. This is fixed in initalization as explained in the issue
  2. reading from serial ports hangs the thread. After channel initalization, the binding sends a command to retrieve the status (for example, if the tv is powered on or off) and then, reads the serial port to get the status. The binding tries to read all the characters, and stops after getting a -1, that means the end of the communication.
    The problem here, is that sometime reading from serial port don't send anything or timeout until the device writes something, resulting in a thread blocked waiting for a read.
    I tried to fix it adding a while (input.available() > 0 && (data = input.read()) > -1) { where input.available() returns remaining characters on the buffer.

@carlospg79 carlospg79 requested a review from fa2k as a code owner December 13, 2021 23:59
Signed-off-by: Carlos Primo <[email protected]>
Signed-off-by: carlospg79 <[email protected]>
@carlospg79 carlospg79 force-pushed the bugfix-lgtvserial-binding branch from 6440a54 to 5a3559c Compare December 14, 2021 15:39
Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

LGTM

@lolodomo lolodomo merged commit fcd6ed6 into openhab:main Dec 17, 2021
@lolodomo lolodomo added the bug An unexpected problem or unintended behavior of an add-on label Dec 17, 2021
@lolodomo lolodomo added this to the 3.2 milestone Dec 17, 2021
@wborn wborn changed the title [lgtvserial] Fixes #8646 - fix binding for recent openHab versions [lgtvserial] Fix sending commands using serial port Dec 18, 2021
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this pull request Dec 30, 2021
Signed-off-by: Carlos Primo <[email protected]>
Signed-off-by: carlospg79 <[email protected]>
Signed-off-by: Nick Waterton <[email protected]>
mischmidt83 pushed a commit to mischmidt83/openhab-addons that referenced this pull request Jan 9, 2022
Signed-off-by: Carlos Primo <[email protected]>
Signed-off-by: carlospg79 <[email protected]>
Signed-off-by: Michael Schmidt <[email protected]>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Jan 28, 2022
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
andan67 pushed a commit to andan67/openhab-addons that referenced this pull request Nov 6, 2022
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Nov 12, 2022
Signed-off-by: Carlos Primo <[email protected]>
Signed-off-by: carlospg79 <[email protected]>
Signed-off-by: Andras Uhrin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants