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(); }
/// <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); }
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)); } }
public void TestNetatmoReadProperty(string property) { Assert.True(Netatmo.IsProperty(property)); Assert.NotNull(_netatmo.GetPropertyValue(property)); }
public void TestProperty(string property) { Assert.True(Netatmo.IsProperty(property)); }