Skip to content

Commit

Permalink
Fix issue when no last_nuki_log_entry exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronen Gruengras authored and ronengr committed Mar 30, 2024
1 parent e592ca2 commit 8973d21
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions custom_components/hass_nuki_bt/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(
self.device_name = device_name
self.base_unique_id = base_unique_id
self.model = None
self.last_nuki_log_entry = {}
self.last_nuki_log_entry = {"index" : 0}
self._security_pin = security_pin
self._nuki_listeners: dict[
CALLBACK_TYPE, tuple[CALLBACK_TYPE, object | None]
Expand Down Expand Up @@ -110,17 +110,18 @@ async def _async_update(
await self.device.update_state()
if self._security_pin:
# get the latest log enrty
# todo: check if Nuki looging is enabled
logs = await self.device.request_log_entries(
security_pin=self._security_pin, count=1
)
if logs[0].type == NukiConst.LogEntryType.LOCK_ACTION:
# todo: handle other log types
self.last_nuki_log_entry = logs[0]
elif logs[0].index > self.last_nuki_log_entry.index:
elif logs[0].index > self.last_nuki_log_entry["index"]:
# if there are new log entries, get max 10 entries
logs = await self.device.request_log_entries(
security_pin=self._security_pin,
count=min(10, logs[0].index - self.last_nuki_log_entry.index),
count=min(10, logs[0].index - self.last_nuki_log_entry["index"]),
start_index=logs[0].index,
)
for log in logs:
Expand Down

0 comments on commit 8973d21

Please sign in to comment.