Skip to content

Potential fix for failed reconnection#83

Merged
zehnm merged 2 commits into
unfoldedcircle:mainfrom
albaintor:stopworking
Oct 29, 2025
Merged

Potential fix for failed reconnection#83
zehnm merged 2 commits into
unfoldedcircle:mainfrom
albaintor:stopworking

Conversation

@albaintor
Copy link
Copy Markdown
Contributor

@albaintor albaintor commented Jul 18, 2025

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 :

  • Only one connection request at a time (skip new requests if connecting)
  • Trigger a new connection task after wakeup

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 :

  1. Disconnection from driver requests disconnection to the android library and returns
  2. You set the state to DISCONNECTED
  3. 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
  4. Then when the remote wakes up again, the AndroidTv::connect method will do nothing because it will skip task when status == CONNECTING

@sjftech
Copy link
Copy Markdown

sjftech commented Aug 6, 2025

Is this likely to be merged soon? The current state of this integration is very annoying to use with the constant disconnections.

Copy link
Copy Markdown
Contributor

@zehnm zehnm left a comment

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

@zehnm zehnm left a comment

Choose a reason for hiding this comment

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

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.

@zehnm zehnm merged commit 5be7332 into unfoldedcircle:main Oct 29, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants