Skip to content

fix: keep the lock state when the operation-log read fails - #75

Merged
roquerodrigo merged 1 commit into
mainfrom
fix/keep-state-when-log-read-fails
Aug 7, 2026
Merged

fix: keep the lock state when the operation-log read fails#75
roquerodrigo merged 1 commit into
mainfrom
fix/keep-state-when-log-read-fails

Conversation

@roquerodrigo

Copy link
Copy Markdown
Owner

The operation log feeds the event entity only, but a failure while reading it aborted the whole poll and discarded the state and battery that same poll had already read. The coordinator then published a null state, so the entity kept whatever Home Assistant last wrote optimistically.

With the default one-hour scan interval that is the only channel refreshing the entity from the device, so anything done outside Home Assistant stayed invisible indefinitely. A confidently wrong locked is worse than an unavailable entity: a state condition reads the stale value and the automation silently does nothing.

Two layers were involved:

  • async_get_operation_log documents that it returns an empty list on failure, but only caught TTLockError. The SDK's log path reaches aes_decrypt unwrapped and raises ValueError on a garbled frame, which is the reported failure.
  • The coordinator had no guard of its own, so the invariant depended on that discipline holding. It now holds regardless of what the connection lets through.

Also pins ttlock-ble to 0.1.11, which fixes the framing bug that made this reproduce permanently on affected locks, and adds a test asserting the manifest pin and the tested pin name the same release.

Fixes #74

The operation log feeds the event entity only, but a failure while
reading it aborted the whole poll, discarding the state and battery the
same poll had already read. The coordinator then published a null state,
so the entity kept whatever Home Assistant last wrote optimistically.

With the default one-hour scan interval that is the only channel that
refreshes the entity from the device, so anything done outside Home
Assistant — keypad, fingerprint, card, the vendor app — stayed invisible
indefinitely. A confidently wrong `locked` is worse than an unavailable
entity: a state condition reads the stale value and the automation
silently does nothing.

Two layers were involved. `async_get_operation_log` documents that it
returns an empty list on failure, but only caught `TTLockError`, while
the SDK's log path reaches `aes_decrypt` unwrapped and raises
`ValueError` on a garbled frame. The coordinator, in turn, had no
guard of its own, so it depended on that discipline holding.

Also pins the SDK to 0.1.11, which fixes the framing bug that made this
reproduce permanently on affected locks, and adds a test asserting the
manifest and the tested pin name the same release.

Fixes #74
@roquerodrigo
roquerodrigo merged commit 566f2ab into main Aug 7, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A failed operation-log read discards an already-successful state read, so the lock entity never refreshes

1 participant