lokonli / slide-domoticz-local

GNU General Public License v3.0
2 stars 1 forks source link

Disconnected state in onConnect #1

Closed heggink closed 3 years ago

heggink commented 3 years ago

Switching to the local api, I find a number of errors in the log:

2021-02-08 17:11:29.571 Error: (SlideLocal) Transport is not connected, write directive to 'Slide_61' ignored.
2021-02-08 17:11:29.571 Error: (SlideLocal) Transport is not connected, write directive to 'Slide_62' ignored.
2021-02-08 17:11:29.571 Error: (SlideLocal) Transport is not connected, write directive to 'Slide_63' ignored.
2021-02-08 17:11:29.571 Error: (SlideLocal) Transport is not connected, write directive to 'Slide_64' ignored.
2021-02-08 17:11:29.571 Error: (SlideLocal) Transport is not connected, write directive to 'Slide_60' ignored.
2021-02-08 17:18:50.947 Error: (SlideLocal) Transport is not connected, write directive to 'Slide_68' ignored.
2021-02-08 17:18:50.947 Error: (SlideLocal) Transport is not connected, write directive to 'Slide_69' ignored.
2021-02-08 17:18:50.947 Error: (SlideLocal) Transport is not connected, write directive to 'Slide_67' ignored.
2021-02-08 17:18:50.947 Error: (SlideLocal) Transport is not connected, write directive to 'Slide_70' ignored.
2021-02-08 17:18:50.947 Error: (SlideLocal) Transport is not connected, write directive to 'Slide_71' ignored.
2021-02-08 17:26:07.538 Error: (SlideLocal) Failed to connect (125) to: 192.168.1.96 with error: Operation canceled
2021-02-08 17:26:07.539 Error: (SlideLocal) Failed to connect (125) to: 192.168.1.97 with error: Operation canceled
2021-02-08 17:26:07.540 Error: (SlideLocal) Failed to connect (125) to: 192.168.1.114 with error: Operation canceled
2021-02-08 17:26:07.540 Error: (SlideLocal) Failed to connect (125) to: 192.168.1.201 with error: Operation canceled
2021-02-08 17:26:07.541 Error: (SlideLocal) Failed to connect (125) to: 192.168.1.51 with error: Operation canceled

When debugging, it appears that, just before onConnect is called, the slide disconnects. onCommand is still called with a status =0 so the plugin thinks it can send data resulting in the listed errors. I added a check for Connected() right after the first debug statement:

        if not Connection.Connected():
            Domoticz.Error("onConnect already disconnected: "+Connection.Address+" "+Connection.Name)

Which shows up just before the error statements so the connection is indeed closed :-(. From what I understood reading the code, the mechanism is to pop a message from the messageQueue, put the message in the connection, create a connection, connect and let the onConnect handle the send (because it would only get called if there was a connection which there is not). Not sure what the best way to reconnect would be since simply calling connect() results in creating a new connection entry where the old would never be freed (the pop() isn't until onMessage). For now I have added a simple return under the check above but that would mean that the message itself would get lost. Not a problem if a heartbeat but less helpful if an actual command.

Thoughts? The python plugin framework is a piece of work sometimes.

H

heggink commented 3 years ago

Proposed a change to plugin.py that fixes the issues for me. No more errors or lost messages since.

flopp999 commented 2 years ago

Proposed a change to plugin.py that fixes the issues for me. No more errors or lost messages since.

What was the propose, I do not find any PR?