Skip to content

Commit

Permalink
allow correct reconnection with bluetooth proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoohb committed Oct 9, 2022
1 parent 587e875 commit cd511a7
Showing 1 changed file with 8 additions and 4 deletions.
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

0 comments on commit cd511a7

Please # to comment.