Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

allow correct reconnection with bluetooth proxy #50

Merged
merged 1 commit into from
Oct 9, 2022
Merged
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
12 changes: 8 additions & 4 deletions custom_components/yeelight_bt/yeelightbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,19 @@ def run_state_changed_cb(self) -> None:
func()

def diconnected_cb(self, client: BaseBleakClient) -> None:
_LOGGER.debug(f"Disconnected CB from client {client}")
# ensure we are responding to the newest client:
if client != self._client:
return
_LOGGER.debug(f"Client with address {client.address} got disconnected!")
# if client != self._client:
# return
self._mode = None # lamp not available
self._conn = Conn.DISCONNECTED
self.run_state_changed_cb()

async def connect(self, num_tries: int = 3) -> None:
if (
self._client and not self._client.is_connected
): # check the connection has not dropped
await self.disconnect()
if self._conn == Conn.PAIRING or self._conn == Conn.PAIRED:
# We do not try to reconnect if we are disconnected or unpaired
return
Expand All @@ -151,7 +155,7 @@ async def connect(self, num_tries: int = 3) -> None:
if self._client:
await self.disconnect()

_LOGGER.debug("Connecting now:...")
_LOGGER.debug(f"Connecting now to {self._ble_device}:...")
self._client = await establish_connection(
BleakClient,
device=self._ble_device,
Expand Down