public ILivePower LiveData() { string url = $@"http://{hostname}/production.json?details=0"; ILivePower power = new ILivePower(); try { HttpClient c = GetClient(); var responseMsg = c.GetAsync(url); var response = responseMsg.Result; if (response.IsSuccessStatusCode) { var content = response.Content; string json = content.ReadAsStringAsync().Result; dynamic data = JsonConvert.DeserializeObject(json); int readingTime = data.production[1].readingTime; power.timestamp = DateTimeOffset.FromUnixTimeSeconds(readingTime).LocalDateTime; power.wattsProduced = data.production[1].wNow; power.wattsConsumed = data.consumption[0].wNow; power.wattsNet = data.consumption[1].wNow; } } catch (Exception) { if (client != null) { client.Dispose(); client = null; } } return(power); }
public ILivePower EnphaseSummary(int systemId) { ILivePower power = new ILivePower(); string url = $@"https://api.enphaseenergy.com/api/v2/systems/{systemId}/summary?key={apiKey}&user_id={userId}"; try { HttpClient c = GetClient(); var responseMsg = c.GetAsync(url); var response = responseMsg.Result; if (response.IsSuccessStatusCode) { var content = response.Content; string json = content.ReadAsStringAsync().Result; dynamic data = JsonConvert.DeserializeObject(json); } } catch (Exception) { if (client != null) { client.Dispose(); client = null; } } return(power); }