Skip to content

Keep last seen sensor available after first value#65

Open
LordMike wants to merge 1 commit into
OpenDisplay:feat/clean-portfrom
LordMike:feat/last-seen-availability
Open

Keep last seen sensor available after first value#65
LordMike wants to merge 1 commit into
OpenDisplay:feat/clean-portfrom
LordMike:feat/last-seen-availability

Conversation

@LordMike

Copy link
Copy Markdown
Contributor

Why

This follows up on the concern raised in #31 (comment).

The last_seen sensor represents historical Bluetooth observation data, not the current live state of the display. If the device disappears for a while, the last-seen timestamp is still meaningful; making the entity unavailable effectively turns "last seen at X" into "unknown" at exactly the time the timestamp is most useful.

Other entities like temperature, RSSI, battery, button events, and touch events are live advertisement-derived state, so tying them to device availability makes sense. last_seen is different: once it has observed a timestamp, it should remain available and keep reporting that timestamp.

What Changed

  • Changed only the last_seen sensor availability behavior.
  • last_seen now caches the first observed timestamp.
  • Before any timestamp has been observed, it still follows the coordinator availability.
  • After a timestamp has been observed, it remains available even if the coordinator later marks the device unavailable.
  • If Bluetooth history later returns no service info, the sensor keeps returning the cached last-seen timestamp.

Validation

  • PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=/mnt/n/Personal/opendisplay-work/Home_Assistant_Integration /home/mike/.venvs/hass-dev/bin/python -m pytest -q tests/test_last_seen.py -p no:cacheprovider
  • Result: 4 passed

@LordMike LordMike marked this pull request as ready for review July 16, 2026 20:50
@LordMike LordMike requested a review from g4bri3lDev as a code owner July 16, 2026 20:50
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.

1 participant