コード例 #1
0
        public async Task TestFroniusReadProperty(string property)
        {
            Assert.True(Fronius.IsProperty(property));
            var status = await _fronius.ReadPropertyAsync(property);

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

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

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

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

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

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