コード例 #1
0
        public async Task TestReadData()
        {
            var status = await _wallbox.ReadReport1Async();

            Assert.True(status.IsGood);
            Assert.True(_wallbox.Report1.Status.IsGood);
            status = await _wallbox.ReadReport2Async();

            Assert.True(status.IsGood);
            Assert.True(_wallbox.Report2.Status.IsGood);
            status = await _wallbox.ReadReport3Async();

            Assert.True(status.IsGood);
            Assert.True(_wallbox.Report3.Status.IsGood);
            status = await _wallbox.ReadReport100Async();

            Assert.True(status.IsGood);
            Assert.True(_wallbox.Report100.Status.IsGood);
            status = await _wallbox.ReadReportsAsync();

            Assert.True(status.IsGood);

            foreach (var report in _wallbox.Reports)
            {
                Assert.True(report.Status.IsGood);
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetReport1Data(bool update = false)
        {
            try
            {
                _logger?.LogDebug("GetReport1Data()...");

                if (!_wallbox.IsLocked)
                {
                    return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished."));
                }

                if (update)
                {
                    await _wallbox.ReadReport1Async();

                    if (!_wallbox.Report1.IsGood)
                    {
                        return(StatusCode(StatusCodes.Status502BadGateway, _wallbox.Report1.Status));
                    }
                }

                return(Ok(_wallbox.Report1));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
コード例 #3
0
        /// <summary>
        /// Executes the update operation every minute.
        /// </summary>
        protected override async Task DoWorkAsync()
        {
            try
            {
                // Update the report data.
                _logger?.LogDebug("WallboxMonitor: DoWork...");
                await _wallbox?.ReadReport1Async();

                await _wallbox?.ReadReport2Async();

                await _wallbox?.ReadReport3Async();

                await _wallbox?.ReadReport100Async();

                await _hub.Clients.All.SendAsync("UpdateReport1", _wallbox.Report1);

                await _hub.Clients.All.SendAsync("UpdateReport2", _wallbox.Report2);

                await _hub.Clients.All.SendAsync("UpdateReport3", _wallbox.Report3);

                await _hub.Clients.All.SendAsync("UpdateReport100", _wallbox.Report100);

                // Check for new day and update all report data.
                if (_currentdate.Date != DateTime.Now.Date)
                {
                    _currentdate = DateTime.Now;
                    await _wallbox?.ReadAllAsync();

                    await _hub.Clients.All.SendAsync("UpdateData", _wallbox.Data);
                }
            }
            catch (Exception ex)
            {
                _logger?.LogWarning(ex, "DoWorkAsync: Exception");
            }
        }