public async Task <IActionResult> GetWallboxData(bool update = false) { try { _logger?.LogDebug("GetWallboxData()..."); if (!_wallbox.IsLocked) { return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished.")); } if (update) { var status = await _wallbox.ReadAllAsync(); if (!status.IsGood) { return(StatusCode(StatusCodes.Status502BadGateway, status)); } } return(Ok(_wallbox.Data)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
/// <summary> /// Executes the start operation just once. /// </summary> protected override async Task DoStartAsync() { try { _logger?.LogDebug("WallboxMonitor: DoStart..."); // Run ReadAllAsync only once. await _wallbox?.ReadAllAsync(); await _hub.Clients.All.SendAsync("UpdateData", _wallbox.Data); } catch (Exception ex) { _logger?.LogWarning(ex, "DoStartAsync: Exception"); } }
public async Task TestWallboxRead() { await _wallbox.ReadAllAsync(); Assert.True(_wallbox.Data.Status.IsGood); Assert.True(_wallbox.Report1.Status.IsGood); Assert.True(_wallbox.Report2.Status.IsGood); Assert.True(_wallbox.Report3.Status.IsGood); Assert.True(_wallbox.Report100.Status.IsGood); foreach (var report in _wallbox.Reports) { Assert.True(report.Status.IsGood); } _logger?.LogInformation($"Wallbox: {JsonConvert.SerializeObject(_wallbox, Formatting.Indented)}"); }