Skip to content

Commit

Permalink
Dont crash if there are no logs on the device
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronen Gruengras authored and ronengr committed May 24, 2024
1 parent 4ee273b commit 10785fa
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions custom_components/hass_nuki_bt/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,21 @@ async def _async_update(
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"]:
# 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"]),
start_index=logs[0].index,
)
for log in logs:
if log.type == NukiConst.LogEntryType.LOCK_ACTION:
self.last_nuki_log_entry = log
break
if logs:
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"]:
# 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"]),
start_index=logs[0].index,
)
for log in logs:
if log.type == NukiConst.LogEntryType.LOCK_ACTION:
self.last_nuki_log_entry = log
break

self.async_update_nuki_listeners()

Expand Down

0 comments on commit 10785fa

Please sign in to comment.