openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

SqueezeBoxServerHandler cannot connect anymore in latest nightly #5524

Closed triller-telekom closed 5 years ago

triller-telekom commented 5 years ago

I installed the latest openhabian nightly from 28.04.2019 and wondered why the squeezebox binding isn't working anymore.

Then I stumbled across: https://github.com/openhab/openhab2-addons/pull/5497

If I undo the changes in the SqueezeBoxServerHandler, everything works as expected again.

kaikreuzer commented 5 years ago

@cweitkamp Could you have a look?

cweitkamp commented 5 years ago

Hm, Yes, of course. Maybe my fixes were a little bit too pessimistic.

A try-with-resources statement for the BufferedWriter should be sufficient. We do not have to take care of the passed Writer instance.

        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()))) {
cweitkamp commented 5 years ago

@triller-telekom Can you test my suggestion? It looks like [closing the stream will close an associated socket](https://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#getOutputStream()) too. I think [closing the reader](https://docs.oracle.com/javase/7/docs/api/java/io/BufferedWriter.html#close()) will itself will also result in a closed socket.

triller-telekom commented 5 years ago

@cweitkamp I have tested your suggestion with:

logger.debug("Sending command: {}", sanitizeCommand(command));
    try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()))) {
            writer.write(command + NEW_LINE);
            writer.flush();
        } catch (IOException e) {
            logger.error("Error while sending command to Squeeze Server ({}) ", sanitizeCommand(command), e);
        }

and it does not work.

Since the developer documentation still says

"TODO: We are currently reworking how to setup a perfect development enviroment. A new step by step guide will appear here after the migration is done. Watch Issue 5005 for further information and progress."

And I tried to install the IDE for about 1.5 hours without any success on sunday, so I cannot help with this issue. I just changed it on the console and built it with maven, but for debugging that's not an option.

staehler commented 5 years ago

Hi, I've a problem with squeezeboxserver, too. Are this log messages relatet to this issue?

==> /var/log/openhab2/openhab.log <==
2019-05-08 22:10:34.052 [WARN ] [rnal.handler.SqueezeBoxServerHandler] - failed to read line from squeeze server socket: Socket closed

==> /var/log/openhab2/events.log <==
2019-05-08 22:10:34.078 [hingStatusInfoChangedEvent] - 'squeezebox:squeezeboxserver:server' changed from OFFLINE (COMMUNICATION_ERROR): Socket closed to ONLINE
2019-05-08 22:10:34.114 [hingStatusInfoChangedEvent] - 'squeezebox:squeezeboxplayer:server:wohnen' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
2019-05-08 22:10:34.147 [hingStatusInfoChangedEvent] - 'squeezebox:squeezeboxplayer:server:bad' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
2019-05-08 22:10:34.181 [hingStatusInfoChangedEvent] - 'squeezebox:squeezeboxplayer:server:gaeste' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
2019-05-08 22:10:34.215 [hingStatusInfoChangedEvent] - 'squeezebox:squeezeboxplayer:server:schlafen' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
2019-05-08 22:10:34.257 [hingStatusInfoChangedEvent] - 'squeezebox:squeezeboxserver:server' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Socket closed
2019-05-08 22:10:34.290 [hingStatusInfoChangedEvent] - 'squeezebox:squeezeboxplayer:server:bad' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
2019-05-08 22:10:34.324 [hingStatusInfoChangedEvent] - 'squeezebox:squeezeboxplayer:server:schlafen' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
2019-05-08 22:10:34.357 [hingStatusInfoChangedEvent] - 'squeezebox:squeezeboxplayer:server:gaeste' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
2019-05-08 22:10:34.391 [hingStatusInfoChangedEvent] - 'squeezebox:squeezeboxplayer:server:wohnen' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)

Unfortunately lots of my automations suffer from this failure. What is your advice for me to do?

debian stretch openhab2 2.5.0~S1587-1

staehler commented 5 years ago

Where can I download an earlier version of squeezebox binding? Please advice

triller-telekom commented 5 years ago

I have attached my binding where I have reverted the breaking change. Just disable the official binding, rename mine into .jar instead of .zip (github does not allow uploading of jar files) and then put it into your addons folder.

org.openhab.binding.squeezebox-2.5.0-SNAPSHOT.zip

staehler commented 5 years ago

Thanks, that helped. squeezebox is running again :-)

cweitkamp commented 5 years ago

Thank you for testing. I will revert my changes tomorrow.

jpk8201 commented 5 years ago

I have attached my binding where I have reverted the breaking change. Just disable the official binding, rename mine into .jar instead of .zip (github does not allow uploading of jar files) and then put it into your addons folder.

org.openhab.binding.squeezebox-2.5.0-SNAPSHOT.zip

Hmm - i made this, but i have the same error again. Any idea?