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)); }
/// <summary> /// Method to run when command is executed. /// </summary> /// <returns>Zero if ok.</returns> public async Task <int> OnExecuteAsync(CommandLineApplication app) { try { if (CheckOptions(app)) { // Overriding Netatmo options. _netatmo.BaseAddress = Parent.BaseAddress; _netatmo.Timeout = Parent.Timeout; if (Property.Length == 0) { Console.WriteLine($"Reading all data from Netatmo weather station."); var status = await _netatmo.ReadAllAsync(); if (status != DataValue.Good) { Console.WriteLine($"Error reading property '{Property}' from Netatmo weather station."); Console.WriteLine($"Reason: {status.Explanation}."); } else { Console.WriteLine($"Netatmo: {JsonConvert.SerializeObject(_netatmo, Formatting.Indented)}"); } } else { Console.WriteLine($"Reading property '{Property}' from Netatmo weather station."); var status = await _netatmo.ReadAllAsync(); if (status != DataValue.Good) { Console.WriteLine($"Error reading property '{Property}' from Netatmo weather station."); Console.WriteLine($"Reason: {status.Explanation}."); } else { Console.WriteLine($"Value of property '{Property}' = {JsonConvert.SerializeObject(_netatmo.GetPropertyValue(Property), Formatting.Indented)}"); } } } } catch (Exception ex) { _logger?.LogError(ex, $"Exception ReadCommand."); return(-1); } return(0); }