@page "/" @inject ReplayOrchestrationService Replay @implements IDisposable

History Replay Dashboard

@switch (Replay.Status) { case ReplayStatus.FetchingHistory:
@(Replay.ProgressMessage ?? "Fetching history data from Home Assistant...")
break; case ReplayStatus.Running:
@(Replay.ProgressMessage ?? "Running replay...")
break; case ReplayStatus.Completed:
Replay completed -- @Replay.Timeline.GetAllEvents().Count event(s)
break; case ReplayStatus.Failed:
Replay failed: @Replay.ErrorMessage
break; }
@if (Replay.Status == ReplayStatus.Completed) {
@if (_activeTab == NordPoolTab) {
NordPool Price Timeline
} else if (_activeTab == BoilerTab) {
Boiler Power and Budget
} else if (_activeTab == ShowerTab) {
Humidity and Shower Detection
} else if (_activeTab == PowerTab) {
Power Breakdown
} else if (_activeTab == LightTab) {
Light Control Events
} else if (_activeTab == ServiceCallsTab) { }
} @code { private const string NordPoolTab = "NordPool"; private const string BoilerTab = "Boiler"; private const string ShowerTab = "Shower"; private const string PowerTab = "Power"; private const string LightTab = "Light"; private const string ServiceCallsTab = "ServiceCalls"; private const string ServiceCallMonitor = "ServiceCall"; private DateTime _startTime = DateTime.Today.AddDays(-1); private DateTime _endTime = DateTime.Today.AddHours(23).AddMinutes(59); private readonly ReplayMonitorFlags _monitors = new(); private bool _isRunning; private string _activeTab = NordPoolTab; private IReadOnlyList _enabledMonitors = []; protected override void OnInitialized() { Replay.OnStateChanged += HandleStateChanged; } private IReadOnlyList GetMonitorEvents(string monitor) => Replay.Timeline.GetEventsByMonitor(monitor); private void SetActiveTab(string tab) { _activeTab = tab; StateHasChanged(); } private async Task RunReplay() { _isRunning = true; _enabledMonitors = BuildEnabledMonitors(); _activeTab = _enabledMonitors.FirstOrDefault() ?? NordPoolTab; var start = new DateTimeOffset(_startTime, TimeZoneInfo.Local.GetUtcOffset(_startTime)); var end = new DateTimeOffset(_endTime, TimeZoneInfo.Local.GetUtcOffset(_endTime)); try { await Task.Run(async () => await Replay.RunReplayAsync(start, end, _monitors)); } catch (Exception ex) { Replay.SetError(ex.Message); } finally { _isRunning = false; await InvokeAsync(StateHasChanged); } } private IReadOnlyList BuildEnabledMonitors() { var list = new List(); if (_monitors.NordPool) list.Add(NordPoolTab); if (_monitors.Boiler) list.Add(BoilerTab); if (_monitors.Shower) list.Add(ShowerTab); if (_monitors.Power) list.Add(PowerTab); if (_monitors.Light) list.Add(LightTab); return list; } private async void HandleStateChanged() { try { await InvokeAsync(StateHasChanged); } catch (ObjectDisposedException) { // Component was disposed while an update was in flight } } public void Dispose() { Replay.OnStateChanged -= HandleStateChanged; } }