Skip to content

Commit

Permalink
fix: handle dbus already having the lock connected at startup (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 10, 2022
1 parent d214fb7 commit b47b132
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 0 additions & 3 deletions src/yalexs_ble/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from bleak_retry_connector import get_device

from .const import ConnectionInfo, DoorStatus, LockInfo, LockState, LockStatus
from .lock import Lock
from .push import PushLock
Expand All @@ -26,7 +24,6 @@
"LockStatus",
"PushLock",
"ValidatedLockConfig",
"get_device",
"serial_to_local_name",
"local_name_to_serial",
"unique_id_from_device_adv",
Expand Down
10 changes: 9 additions & 1 deletion src/yalexs_ble/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
from bleak.backends.scanner import AdvertisementData
from bleak.backends.service import BleakGATTServiceCollection
from bleak.exc import BleakDBusError
from bleak_retry_connector import BleakError, BleakNotFoundError, ble_device_has_changed
from bleak_retry_connector import (
BleakError,
BleakNotFoundError,
ble_device_has_changed,
get_device,
)

from .const import (
APPLE_MFR_ID,
Expand Down Expand Up @@ -502,6 +507,9 @@ async def start(self) -> Callable[[], None]:
raise RuntimeError("Already running")
self.last_error = "No Bluetooth advertisement received"
self._running = True
if device := await get_device(self.address):
self.set_ble_device(device)
self._schedule_update(ADV_UPDATE_COALESCE_SECONDS)

def _cancel() -> None:
self._running = False
Expand Down

0 comments on commit b47b132

Please sign in to comment.