Potential fix for failed reconnection#83
Conversation
|
Is this likely to be merged soon? The current state of this integration is very annoying to use with the constant disconnections. |
zehnm
left a comment
There was a problem hiding this comment.
Sorry I've ignored the PR because of the failed tests.
Please fix the linting issue:
ERROR: integration-androidtv/src/tv.py Imports are incorrectly sorted and/or formatted.
But the android library triggers one last reconnection after in the connection loop after disconnection request. this raise an event caught by your AndroidTv::_is_available_updated callback that resets the state back to CONNECTING
This sounds like a major issue. If the androidtv library tells us in the callback that it is available, then we should trust it.
The CONNECTED event is only emitted if the library tells us is_available: true.
The only clean solution I see is to rewrite the whole connection logic with a proper state machine.
zehnm
left a comment
There was a problem hiding this comment.
Looks good and it should improve reconnection for certain devices.
If this still doesn't fix the reported issues, then the whole reconnection logic needs to be rewritten with a proper state machine.
Hi Markus,
following this reported issue : unfoldedcircle/feature-and-bug-tracker#526
I have replaced the test of the connection status (CONNECTING) with an asyncio lock to check after the connection task.
In that way we have these 2 requirements :
As pointed out in the issue, the connection status is not reliable as it may be set to CONNECTING whereas it is not
But after second thoughts, I still wonder if this is the right way to do. The rootcause here is that things don't happen in the right order :
DISCONNECTEDAndroidTv::_is_available_updatedcallback that resets the state back toCONNECTINGAndroidTv::connectmethod will do nothing because it will skip task when status ==CONNECTING