Exemple #1
0
        public async Task TestWallboxReadProperty(string property)
        {
            Assert.True(Wallbox.IsProperty(property));
            var status = await _wallbox.ReadPropertyAsync(property);

            Assert.True(status.IsGood);
        }
Exemple #2
0
        public async Task <IActionResult> GetWallboxData(string name, bool update = false)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"GetWallboxData() invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid."));
            }

            try
            {
                _logger?.LogDebug($"GetWallboxData({name})...");

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

                    if (update)
                    {
                        var status = await _wallbox.ReadPropertyAsync(name);

                        if (!status.IsGood)
                        {
                            return(StatusCode(StatusCodes.Status502BadGateway, status));
                        }
                    }

                    return(Ok(_wallbox.GetPropertyValue(name)));
                }
                else
                {
                    _logger?.LogDebug($"GetWallboxData('{name}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }