Skip to content

✨ Device log misses device-scoped events (zha_event, pings) — REST logbook has no device filter #17

Description

@iTerminate

Problem

Opening the device log (A) on a Zigbee/deconz device — say a wireless button — only ever shows
its entities' state changes. Home Assistant's own device page shows more: button presses, pings,
automation triggers fired by that device. hatty's device log is missing exactly the events that
make it useful for battery-powered sensors and buttons, which often have no state-bearing entity
at all for "someone just pressed this."

Root cause

HAClient.fetch_logbook (client.py:268-282) fetches over REST:
GET /api/logbook/{start}?entity=<csv>&end_time=<iso>.

Home Assistant's REST logbook view (homeassistant/components/logbook/rest_api.py) accepts
only period, entity, end_time, context_id — there is no device filter on this endpoint
at all. Device-scoped events (e.g. zha_event) carry a device_id in their event data and have
no entity_id, so they can never match an entity= filter, no matter what's passed.

(Ironically, before #13 fixed entity_identity, the filter was silently ignored by HA and
the whole-instance logbook came back — which is why these events used to appear, by accident.)

Only the websocket commands accept device ids:

# logbook/websocket_api.py
{"type": "logbook/get_events", "start_time": ..., "end_time": ...,
 "entity_ids": [...], "device_ids": [...], "context_id": ...}

{"type": "logbook/event_stream", "start_time": ..., "end_time": ...,
 "entity_ids": [...], "device_ids": [...]}

Home Assistant's own frontend device page (ha-config-device-page.ts) passes both:

<ha-logbook .entityIds=${this._entityIds(entities)} .deviceIds=${this._deviceIdInList(this.deviceId)} ...>

async_determine_event_types (logbook/helpers.py) confirms external events like zha_event are
only included in the result set when device_ids is supplied and the device's config-entry domain
is among the "interested domains" — passing device_ids is exactly what unlocks them.

Two response-shape differences to handle

The WS logbook/get_events handler builds its EventProcessor with
timestamp=True, include_entity_name=False, while the REST view uses the opposite
(timestamp=False, include_entity_name=True). So WS entries differ from what hatty renders today:

  1. when is a float epoch, not an ISO string.
  2. State-change entries have no name key — the caller must resolve display names itself.
    External/"describe" events (like zha_event) do carry name + message.

This will need a normalization layer so ActivityLogPanel and the fullscreen graph's event-mark
overlay (plot_render.render_event_marks, which calls datetime.fromisoformat on when today)
both keep working.

Depends on

#1 — fetching via WS and awaiting the response needs a request/response mechanism HAClient
doesn't have yet.

Refs #1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions