1010@using TeslaSolarCharger .Shared .Localization .Contracts
1111@using TeslaSolarCharger .Shared .Localization .Registries
1212@using TeslaSolarCharger .Shared .Localization .Registries .Components .StartPage
13+ @implements IDisposable
1314
1415@inject IHomeService HomeService
1516@inject ISnackbar Snackbar
175176 private int ? CurrentToSet { get ; set ; }
176177 private int ? ManualSocToSet { get ; set ; }
177178 private bool _isCommandLoading ;
179+ private IDisposable ? _subscription ;
180+ private int ? _lastSubscribedCarId ;
178181
179182 protected override async Task OnParametersSetAsync ()
180183 {
@@ -185,21 +188,28 @@ else
185188 {
186189 return ;
187190 }
188- await SignalRStateService .Subscribe <DtoCarOverviewState >(
189- DataTypeConstants .CarOverviewState ,
190- async void (state ) =>
191- {
192- try
191+
192+ if (_lastSubscribedCarId != CarId )
193+ {
194+ _subscription ? .Dispose ();
195+ _lastSubscribedCarId = CarId ;
196+
197+ _subscription = await SignalRStateService .Subscribe <DtoCarOverviewState >(
198+ DataTypeConstants .CarOverviewState ,
199+ async void (state ) =>
200+ {
201+ try
193202 {
194203 CarState = state ;
195204 await InvokeAsync (StateHasChanged );
196205 }
197- catch (Exception e )
198- {
199- Logger .LogError (e , " Failed to update car state for CarId: {CarId}" , CarId );
200- }
201- },
202- CarId .Value .ToString ());
206+ catch (Exception e )
207+ {
208+ Logger .LogError (e , " Failed to update car state for CarId: {CarId}" , CarId );
209+ }
210+ },
211+ CarId .Value .ToString ());
212+ }
203213
204214 CarState = await SignalRStateService .GetStateAsync <DtoCarOverviewState >(
205215 DataTypeConstants .CarOverviewState ,
387397
388398 private string Format (string key , params object ? [] arguments ) =>
389399 string .Format (CultureInfo .CurrentCulture , T (key ), arguments );
400+
401+ public void Dispose ()
402+ {
403+ _subscription ? .Dispose ();
404+ }
390405}
0 commit comments