Skip to content

Commit

Permalink
Wrap update in a procedure to catch errors
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed Feb 28, 2023
1 parent a96f39b commit 0ae6676
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions py_dormakaba_dkey/dkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,17 @@ async def execute(self) -> bool:
return True


class NullProcedure(BaseProcedure):
"""Do nothing."""

enable_notifications = True
need_auth = True

async def execute(self) -> bool:
"""Execute the procedure"""
return True


class DKEYLock:
"""Manage a Dormakaba DKEY lock."""

Expand Down Expand Up @@ -569,10 +580,11 @@ async def unlock(self) -> bool:
unlock_proc = UnlockProcedure(self)
return await self._execute(unlock_proc)

async def update(self) -> None:
async def update(self) -> bool:
"""Update the lock's status."""
_LOGGER.debug("%s: Update", self.name)
await self._enable_notifications()
null_proc = NullProcedure(self)
return await self._execute(null_proc)

@retry_bluetooth_connection_error(DEFAULT_ATTEMPTS) # type: ignore[misc]
async def _execute(self, procedure: BaseProcedure) -> bool:
Expand Down Expand Up @@ -602,18 +614,6 @@ async def _execute(self, procedure: BaseProcedure) -> bool:
self._disconnect(DisconnectReason.ERROR)
raise

async def _enable_notifications(self) -> None:
"""Enable notifications."""
if self._procedure_lock.locked():
_LOGGER.debug(
"%s: Procedure already in progress, waiting for it to complete; "
"RSSI: %s",
self.name,
self.rssi,
)
async with self._procedure_lock:
await self._enable_notifications_when_locked()

async def _enable_notifications_when_locked(self) -> None:
"""Enable notifications."""
await self._ensure_authenticated()
Expand Down

0 comments on commit 0ae6676

Please sign in to comment.