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

Try harder to avoid missing button presses #336

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions aiohomekit/controller/ble/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def __init__(

self._start_notify_timer: asyncio.TimerHandle | None = None

self._tried_to_connect_once = False
self._did_first_sync = False
self._restore_pending = False
self._fetched_gsn_this_session = False
self._had_notify_this_session = False
Expand Down Expand Up @@ -581,9 +581,9 @@ async def _async_pair_verify(self) -> None:

async def _process_disconnected_events(self) -> None:
"""Handle disconnected events seen from the advertisement."""
if not self._tried_to_connect_once:
# We never tried connected to the accessory, so we don't need to
# process the disconnected events
if not self._did_first_sync:
# We never did a first sync, so we don't know what the state number is
# so we can't process disconnected events
logger.debug(
"%s: Skipping disconnected events because we have not yet connected.",
self.name,
Expand Down Expand Up @@ -636,6 +636,11 @@ async def _process_disconnected_events_with_retry(
await self._get_characteristics_while_connected(
chars_to_update,
notify_listeners=True,
# Still read the event characteristics on disconnected events
# since the default is to skip IGNORE_POLL_CHARACTERISTICS and
# EVENT_CHARACTERISTICS is a subset of IGNORE_POLL_CHARACTERISTICS
# so we explicitly only skip IGNORE_READ_CHARACTERISTICS
skip_characteristics=IGNORE_READ_CHARACTERISTICS,
)
return protocol_param

Expand Down Expand Up @@ -1079,14 +1084,7 @@ async def _populate_accessories_and_characteristics(
if self._shutdown:
return

try:
made_connection = await self._ensure_connected(attempts)
finally:
# Only set _tried_to_connect_once after the connection
# attempt is complete so we don't try to process disconnected
# events while we are still trying to connect.
self._tried_to_connect_once = True

made_connection = await self._ensure_connected(attempts)
logger.debug(
"%s: Populating accessories and characteristics: made_connection=%s restore_pending=%s",
self.name,
Expand Down Expand Up @@ -1129,6 +1127,8 @@ async def _populate_accessories_and_characteristics(
if config_changed:
self._callback_and_save_config_changed(self.config_num)

self._did_first_sync = True

async def _async_subscribe_broadcast_events(
self, subscriptions: list[tuple[int, int]]
) -> None:
Expand Down
Loading