예제 #1
0
        public NetatmoFixture()
        {
            // Set the default culture.
            CultureInfo.CurrentCulture = new CultureInfo("en-US");

            var loggerFactory = new LoggerFactory();
            var logger        = loggerFactory.CreateLogger <Netatmo>();

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(AppContext.BaseDirectory)
                                .AddJsonFile("appsettings.json", false, false)
                                .AddUserSecrets <Startup>(true)
                                .Build();

            configuration.GetSection("AppSettings").Bind(Settings);

            var client = new NetatmoClient(new HttpClient()
            {
                BaseAddress = new Uri(Settings.BaseAddress),
                Timeout     = TimeSpan.FromSeconds(Settings.Timeout)
            }, loggerFactory.CreateLogger <NetatmoClient>());

            Netatmo = new Netatmo(logger, client, Settings);

            Netatmo.ReadAllAsync().Wait();
        }
예제 #2
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);
        }
예제 #3
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));
            }
        }
예제 #4
0
 public void TestNetatmoReadProperty(string property)
 {
     Assert.True(Netatmo.IsProperty(property));
     Assert.NotNull(_netatmo.GetPropertyValue(property));
 }
예제 #5
0
 public void TestProperty(string property)
 {
     Assert.True(Netatmo.IsProperty(property));
 }