|
5 | 5 |
|
6 | 6 | <PageTitle>JK BMS Status</PageTitle> |
7 | 7 |
|
8 | | -<Loader Enabled=@(status is null)/> |
| 8 | +<Loader Enabled=@(status is null) /> |
9 | 9 |
|
10 | 10 | @if (status is not null) |
11 | 11 | { |
|
24 | 24 | <div class="fs-1 my-1 mx-5 border-top"> |
25 | 25 | @status.CapacityPct% |
26 | 26 | </div> |
27 | | - <div class="fs-5 m-0 border-top"> |
28 | | - @Math.Round(status.AvailableCapacity, 1) Ah / @status.PackCapacity Ah |
| 27 | + <div class="fs-5 m-0 border-top" style="cursor: pointer;" @onclick="_ => ShowCapacityKwh = !ShowCapacityKwh"> |
| 28 | + @(GetPackCapacity()) |
29 | 29 | </div> |
30 | 30 | </div> |
31 | 31 | <div class="col bg-light"> |
|
41 | 41 | <div class="fw-bold fs-6 text-secondary"> |
42 | 42 | @($"{status.CRate:0.00} C") / @($"{status.AvgPowerWatts:0} W") |
43 | 43 | </div> |
44 | | - <div class="fw-normal fs-6 m-0 p-0"> |
45 | | - @status.TimeHrs Hrs @status.TimeMins Mins |
| 44 | + <div class="fw-normal fs-6 m-0 p-0" style="cursor: pointer;" @onclick="_ => ShowEndDateAndTime = !ShowEndDateAndTime"> |
| 45 | + @(GetTimeLeft()) |
46 | 46 | </div> |
47 | 47 | } |
48 | 48 | @if (status.AvgCurrentAmps == 0) |
49 | 49 | { |
50 | 50 | <div class="fs-5 m-0 p-0 text-muted"> |
51 | | - Holding<br/>Voltage |
| 51 | + Holding<br />Voltage |
52 | 52 | </div> |
53 | 53 | } |
54 | 54 | @if (status.IsWarning) |
|
127 | 127 | private static event Action<BMSStatus?>? onStatusUpdated; |
128 | 128 | private static event Action? onStatusRetrievalError; |
129 | 129 | private static BMSStatus? status; |
| 130 | + private static bool ShowEndDateAndTime; |
| 131 | + private static bool ShowCapacityKwh; |
130 | 132 |
|
131 | 133 | protected override void OnInitialized() |
132 | 134 | { |
|
146 | 148 | StateHasChanged(); |
147 | 149 | } |
148 | 150 |
|
| 151 | + private string GetTimeLeft() |
| 152 | + { |
| 153 | + if (ShowEndDateAndTime) |
| 154 | + { |
| 155 | + return status!.GetTimeString(); |
| 156 | + } |
| 157 | + return $"{status!.TimeHrs} Hrs {status.TimeMins} Mins"; |
| 158 | + } |
| 159 | + |
| 160 | + private string GetPackCapacity() |
| 161 | + { |
| 162 | + if (ShowCapacityKwh) |
| 163 | + { |
| 164 | + var avlCap = Math.Round((status!.AvailableCapacity * status.PackNominalVoltage) / 1000, 1); |
| 165 | + var packCap = Math.Round((status!.PackCapacity * status.PackNominalVoltage) / 1000, 1); |
| 166 | + return $"{avlCap} kWh / {packCap} kWh"; |
| 167 | + } |
| 168 | + return $"{Math.Round(status!.AvailableCapacity, 1)} Ah / {status!.PackCapacity} Ah"; |
| 169 | + } |
| 170 | + |
149 | 171 | public void Dispose() |
150 | 172 | { |
151 | 173 | onStatusUpdated -= UpdateState; |
|
160 | 182 | // which leads to a memory leak/ connection exhaustion. |
161 | 183 |
|
162 | 184 | using var client = new HttpClient |
163 | | - { |
164 | | - BaseAddress = new(basePath), |
165 | | - Timeout = TimeSpan.FromSeconds(5) |
166 | | - }; |
| 185 | + { |
| 186 | + BaseAddress = new(basePath), |
| 187 | + Timeout = TimeSpan.FromSeconds(5) |
| 188 | + }; |
167 | 189 |
|
168 | 190 | var retryDelay = 1000; |
169 | 191 |
|
|
183 | 205 | JsonSerializer.DeserializeAsyncEnumerable<BMSStatus>( |
184 | 206 | stream, |
185 | 207 | new JsonSerializerOptions |
186 | | - { |
187 | | - PropertyNameCaseInsensitive = true, |
188 | | - DefaultBufferSize = 64 |
189 | | - })) |
| 208 | + { |
| 209 | + PropertyNameCaseInsensitive = true, |
| 210 | + DefaultBufferSize = 64 |
| 211 | + })) |
190 | 212 | { |
191 | 213 | onStatusUpdated?.Invoke(s); |
192 | 214 | retryDelay = 1000; |
|
0 commit comments