|
88 | 88 | <button class="btn btn-secondary dropdown-toggle" type="button" id="combinedcurrent" data-bs-toggle="dropdown"> |
89 | 89 | @Sanitize(settings.MaxCombinedChargeCurrent) A |
90 | 90 | </button> |
91 | | - <ul class="dropdown-menu dropdown-menu"> |
92 | | - @foreach (var val in chargeAmpereValues!.CombinedAmpereValues) |
| 91 | + @if (chargeAmpereValues != null) |
93 | 92 | { |
94 | | - <li> |
95 | | - <a |
96 | | - class="dropdown-item @(settings.MaxCombinedChargeCurrent == val ? "active" : "")" |
97 | | - @onclick="()=>SetSetting(Setting.CombinedChargeCurrent,val)" |
98 | | - > |
99 | | - @Sanitize(val) A |
100 | | - </a> |
101 | | - </li> |
| 93 | + <ul class="dropdown-menu dropdown-menu"> |
| 94 | + @foreach (var val in chargeAmpereValues!.CombinedAmpereValues) |
| 95 | + { |
| 96 | + <li> |
| 97 | + <a |
| 98 | + class="dropdown-item @(settings.MaxCombinedChargeCurrent == val ? "active" : "")" |
| 99 | + @onclick="()=>SetSetting(Setting.CombinedChargeCurrent,val)" |
| 100 | + > |
| 101 | + @Sanitize(val) A |
| 102 | + </a> |
| 103 | + </li> |
| 104 | + } |
| 105 | + </ul> |
102 | 106 | } |
103 | | - </ul> |
104 | 107 | </div> |
105 | 108 | } |
106 | 109 | </div> |
|
123 | 126 | @Sanitize(settings.MaxACChargeCurrent) A |
124 | 127 | </button> |
125 | 128 | <ul class="dropdown-menu dropdown-menu"> |
126 | | - @foreach (var val in chargeAmpereValues!.UtilityAmpereValues) |
| 129 | + @if (chargeAmpereValues != null) |
127 | 130 | { |
128 | | - <li> |
129 | | - <a |
130 | | - class="dropdown-item @(settings.MaxACChargeCurrent == val ? "active" : "")" |
131 | | - @onclick="()=>SetSetting(Setting.UtilityChargeCurrent,val)" |
132 | | - > |
133 | | - @Sanitize(val) A |
134 | | - </a> |
135 | | - </li> |
| 131 | + @foreach (var val in chargeAmpereValues!.UtilityAmpereValues) |
| 132 | + { |
| 133 | + <li> |
| 134 | + <a |
| 135 | + class="dropdown-item @(settings.MaxACChargeCurrent == val ? "active" : "")" |
| 136 | + @onclick="()=>SetSetting(Setting.UtilityChargeCurrent,val)" |
| 137 | + > |
| 138 | + @Sanitize(val) A |
| 139 | + </a> |
| 140 | + </li> |
| 141 | + } |
136 | 142 | } |
137 | 143 | </ul> |
138 | 144 | </div> |
|
291 | 297 |
|
292 | 298 | @code{ |
293 | 299 | private static ChargeAmpereValues? chargeAmpereValues; |
294 | | - private static CurrentSettings? settings; |
| 300 | + private CurrentSettings? settings; |
295 | 301 | private Button currentButton = Button.None; |
296 | 302 | private bool isSuccess; |
297 | 303 | private string inProgressSetting = ""; |
298 | 304 |
|
299 | | - public static async Task RetrieveChargeAmpereValues(string basePath) |
| 305 | + protected override async Task OnInitializedAsync() |
300 | 306 | { |
301 | | - using var client = new HttpClient |
302 | | - { |
303 | | - BaseAddress = new Uri(basePath), |
304 | | - Timeout = TimeSpan.FromSeconds(10) |
305 | | - }; |
306 | | - |
307 | | - var retryDelay = (int)TimeSpan.FromSeconds(1).TotalMilliseconds; |
308 | | - var maxDelay = (int)TimeSpan.FromMinutes(1).TotalMilliseconds; |
| 307 | + settings = await Http.GetFromJsonAsync<CurrentSettings>("api/settings/get-setting-values"); |
| 308 | + StateHasChanged(); |
309 | 309 |
|
310 | | - while (true) |
| 310 | + _ = Task.Run(async () => |
311 | 311 | { |
312 | | - try |
| 312 | + if (chargeAmpereValues is null) |
313 | 313 | { |
| 314 | + using var client = new HttpClient |
| 315 | + { |
| 316 | + BaseAddress = new Uri(Http.BaseAddress?.ToString() ?? "/"), |
| 317 | + Timeout = TimeSpan.FromSeconds(10) |
| 318 | + }; |
| 319 | + |
314 | 320 | chargeAmpereValues = await client.GetFromJsonAsync<ChargeAmpereValues>("api/settings/get-charge-ampere-values"); |
315 | 321 |
|
316 | 322 | // some inverters only seem to support one of the two commands over usb |
317 | | - if(chargeAmpereValues?.CombinedAmpereValues.Any() is true && |
318 | | - chargeAmpereValues?.UtilityAmpereValues.Any() is false) |
| 323 | + if (chargeAmpereValues?.CombinedAmpereValues.Any() is true && |
| 324 | + chargeAmpereValues?.UtilityAmpereValues.Any() is false) |
319 | 325 | { |
320 | 326 | chargeAmpereValues.UtilityAmpereValues = chargeAmpereValues.CombinedAmpereValues; |
321 | 327 | } |
322 | | - if(chargeAmpereValues?.CombinedAmpereValues.Any() is false && |
323 | | - chargeAmpereValues?.UtilityAmpereValues.Any() is true) |
| 328 | + if (chargeAmpereValues?.CombinedAmpereValues.Any() is false && |
| 329 | + chargeAmpereValues?.UtilityAmpereValues.Any() is true) |
324 | 330 | { |
325 | 331 | chargeAmpereValues.CombinedAmpereValues = chargeAmpereValues.UtilityAmpereValues; |
326 | 332 | } |
327 | | - |
328 | | - break; |
329 | | - } |
330 | | - catch (Exception) |
331 | | - { |
332 | | - if (retryDelay > maxDelay) |
333 | | - break; |
334 | | - |
335 | | - await Task.Delay(retryDelay); |
336 | | - retryDelay += 250; |
| 333 | + StateHasChanged(); |
337 | 334 | } |
338 | | - } |
339 | | - } |
340 | | - |
341 | | - protected override async Task OnInitializedAsync() |
342 | | - { |
343 | | - settings = await Http.GetFromJsonAsync<CurrentSettings>("api/settings/get-setting-values"); |
344 | | - StateHasChanged(); |
| 335 | + }); |
345 | 336 | } |
346 | 337 |
|
347 | 338 | private async Task SetChargePriority(string priority) |
|
0 commit comments