Пример #1
0
        public IActionResult GetHomeData(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"GetHomeData() invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid."));
            }

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

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

                    if (!_homedata.Data.IsGood)
                    {
                        return(StatusCode(StatusCodes.Status502BadGateway, _homedata.Data.Status));
                    }

                    return(Ok(_homedata.GetPropertyValue(name)));
                }
                else
                {
                    _logger?.LogDebug($"GetHomeData('{name}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Пример #2
0
        /// <summary>
        /// Method to run when command is executed.
        /// </summary>
        /// <returns>Zero if ok.</returns>
        public async Task <int> OnExecute(CommandLineApplication app)
        {
            try
            {
                if (CheckOptions(app))
                {
                    // Overriding EM300LR options.
                    _homedata.Meter1Address = Parent.Meter1Address;
                    _homedata.Meter2Address = Parent.Meter2Address;

                    await _homedata.ReadAllAsync(OptionU);

                    if (_homedata.Data.IsGood)
                    {
                        if (Property.Length > 0)
                        {
                            Console.WriteLine($"Reading property '{Property}' from home control system.");
                            Console.WriteLine($"Value of property '{Property}' = {JsonConvert.SerializeObject(_homedata.GetPropertyValue(Property), Formatting.Indented)}");
                        }
                        else
                        {
                            Console.WriteLine($"HomeData: {JsonConvert.SerializeObject(_homedata.Data, Formatting.Indented)}");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Error getting updated data from home control system.");
                        Console.WriteLine($"Reason: {_homedata.Data.Status.Explanation}.");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, $"Exception ReadCommand.");
                return(-1);
            }

            return(0);
        }
Пример #3
0
 public void TestProperty(string property)
 {
     Assert.True(HomeData.IsProperty(property));
     Assert.NotNull(_home.GetPropertyValue(property));
 }