private async Task <DomoticzKwhValuesClientModel> GetDomoticzKwhValuesClientModel(Device device)
        {
            using (var client = new HttpClient())
            {
                var url      = $"http://{_domoticzSettings.Host}:{_domoticzSettings.Port}/json.htm?type=graph&sensor=counter&idx={device.DomoticzKwhIdx}&range=year";
                var response = await client.GetStringAsync(url);

                var    data       = JsonConvert.DeserializeObject <dynamic>(response);
                JArray resultList = data.result;

                // Cast resultList to objects
                var values = resultList.ToObject <List <DomoticzKwhUsage> >();

                var clientModel = new DomoticzKwhValuesClientModel
                {
                    Device            = device,
                    DomoticzKwhUsages = values
                };

                return(clientModel);
            }
        }
Exemple #2
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='clientModel'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task ExporterInsertDomoticzKwhValuesPostAsync(this IHouseDBAPI operations, DomoticzKwhValuesClientModel clientModel = default(DomoticzKwhValuesClientModel), CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.ExporterInsertDomoticzKwhValuesPostWithHttpMessagesAsync(clientModel, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
Exemple #3
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='clientModel'>
 /// </param>
 public static void ExporterInsertDomoticzKwhValuesPost(this IHouseDBAPI operations, DomoticzKwhValuesClientModel clientModel = default(DomoticzKwhValuesClientModel))
 {
     operations.ExporterInsertDomoticzKwhValuesPostAsync(clientModel).GetAwaiter().GetResult();
 }