Ejemplo n.º 1
0
        /// <summary>
        /// Helper method to check options.
        /// </summary>
        /// <param name="app"></param>
        /// <returns>True if options are OK.</returns>
        private bool CheckOptions(CommandLineApplication app)
        {
            if (Property.Length > 0)
            {
                if (!Netatmo.IsProperty(Property))
                {
                    _logger?.LogError($"The property '{Property}' has not been found.");
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetNetatmoData(string name, bool update = false)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"GetNetatmoData() invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid."));
            }

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

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

                    if (update)
                    {
                        var status = await _netatmo.ReadAllAsync();

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

                    return(Ok(_netatmo.GetPropertyValue(name)));
                }
                else
                {
                    _logger?.LogDebug($"GetNetatmoData('{name}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Ejemplo n.º 3
0
 public void TestNetatmoReadProperty(string property)
 {
     Assert.True(Netatmo.IsProperty(property));
     Assert.NotNull(_netatmo.GetPropertyValue(property));
 }
Ejemplo n.º 4
0
 public void TestProperty(string property)
 {
     Assert.True(Netatmo.IsProperty(property));
 }