Skip to content

[WIP] Add device history tracking for wake/sleep events#94

Merged
renedierking merged 3 commits intomasterfrom
claude/feature-device-history-event-tracking
Apr 11, 2026
Merged

[WIP] Add device history tracking for wake/sleep events#94
renedierking merged 3 commits intomasterfrom
claude/feature-device-history-event-tracking

Conversation

@Claude
Copy link
Copy Markdown
Contributor

@Claude Claude AI commented Apr 11, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.


This section details on the original issue you should resolve

<issue_title>Feature: Device History — Track wake/sleep events with timestamps</issue_title>
<issue_description>## Description

Record and display a history of device events: wake commands sent, device came online, device went offline. This provides visibility into device behavior and supports future analytics (v2.0.0).

Affected Files

  • New model: src/API/Models/DeviceEvent.cs — Id, PcDeviceId (FK), EventType (enum: WakeCommandSent, CameOnline, WentOffline), Timestamp, Details (optional string, e.g., ping latency)
  • src/API/Data/AppDbContext.csDbSet<DeviceEvent>, migration, index on (PcDeviceId, Timestamp)
  • src/API/Services/DeviceMonitoringService.cs — Log CameOnline / WentOffline events when status changes (currently only updates IsOnline and OnlineSince)
  • src/API/Handler/PcDeviceHandler.cs — Log WakeCommandSent event in WakeDevice()
  • New endpoints (in existing or new strategy):
    • GET /api/v1/pc-devices/{id}/history?limit=50&offset=0 — paginated event history
    • Optional: GET /api/v1/pc-devices/{id}/history/summary — uptime stats
  • New UI component: Device history dialog or expandable section showing event timeline
  • src/UI/Pages/Home.razor — "History" action button on each device

Design Decisions

  1. Retention policy: Events will grow indefinitely. Add a configurable max-age or max-count with automatic cleanup (e.g., keep last 90 days or 1000 events per device).
  2. Scoped DB context: DeviceMonitoringService is a singleton but AppDbContext is scoped — use IServiceScopeFactory (already the pattern used in DeviceMonitoringService.CheckAllDevicesAsync).
  3. Event granularity: Log every check cycle vs. only status changes. Recommend only status changes + explicit wake commands to keep volume manageable.

Acceptance Criteria

  • A DeviceEvent is recorded each time a wake command is sent
  • A DeviceEvent is recorded when a device transitions online → offline or offline → online
  • Events are viewable per device in the UI with timestamps
  • API supports paginated history retrieval
  • Events are stored in SQLite and survive restarts
  • Deleting a device cascades to its event history
  • Unit tests cover event recording in monitoring service and handler
    </issue_description>

Comments on the Issue (you are @claude[agent] in this section)

Copy link
Copy Markdown
Owner

@renedierking renedierking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude[agent] where is the UI Component

Agent-Logs-Url: https://github.com/renedierking/LANdalf/sessions/f8983b28-ac07-4bbd-81b2-ca87fec18fda

Co-authored-by: renedierking <91347202+renedierking@users.noreply.github.com>
@Claude
Copy link
Copy Markdown
Contributor Author

Claude AI commented Apr 11, 2026

@claude[agent] where is the UI Component

I've added the UI component in commit f0cb463. The implementation includes:

DeviceHistoryDialog Component:

  • Timeline view showing all device events (Wake Command Sent, Came Online, Went Offline)
  • Color-coded icons and text (blue for wake commands, green for online, red for offline)
  • Human-readable timestamps ("5m ago", "2h ago", or full date for older events)
  • Paginated loading with "Load More" button (20 events per page)
  • Displays event details when available

Integration:

  • Added History icon button to DeviceCard (visible in card view)
  • Added History icon button to table view actions column
  • Clicking the History button opens a modal dialog showing the device's event timeline

The UI component uses MudBlazor's MudTimeline for the visual timeline and connects to the device history API endpoint (GET /api/v1/pc-devices/{id}/history) that was implemented in the previous commit.

@Claude Claude AI requested a review from renedierking April 11, 2026 16:28
@renedierking renedierking marked this pull request as ready for review April 11, 2026 16:29
Copy link
Copy Markdown
Owner

@renedierking renedierking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

@renedierking renedierking merged commit 97cf542 into master Apr 11, 2026
3 checks passed
@renedierking renedierking deleted the claude/feature-device-history-event-tracking branch April 11, 2026 18:28
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.

Feature: Device History — Track wake/sleep events with timestamps

2 participants