mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-02-09 09:42:37 -05:00
Update power message sent to hub
This commit is contained in:
11
Power/Service/Models/PowerStatus.cs
Normal file
11
Power/Service/Models/PowerStatus.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace ChrisKaczor.HomeMonitor.Power.Service.Models
|
||||||
|
{
|
||||||
|
[PublicAPI]
|
||||||
|
public class PowerStatus
|
||||||
|
{
|
||||||
|
public long Generation { get; set; }
|
||||||
|
public long Consumption { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -45,8 +46,17 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
|
|||||||
|
|
||||||
var sample = JsonSerializer.Deserialize<PowerSample>(response.Content);
|
var sample = JsonSerializer.Deserialize<PowerSample>(response.Content);
|
||||||
|
|
||||||
Console.WriteLine(sample.Channels[2].Type + " " + sample.Channels[2].RealPower);
|
var generation = sample.Channels.FirstOrDefault(c => c.Type == "GENERATION");
|
||||||
Console.WriteLine(sample.Channels[3].Type + " " + sample.Channels[3].RealPower);
|
var consumption = sample.Channels.FirstOrDefault(c => c.Type == "CONSUMPTION");
|
||||||
|
|
||||||
|
if (generation == null || consumption == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var status = new PowerStatus { Generation = generation.RealPower, Consumption = consumption.RealPower };
|
||||||
|
|
||||||
|
var json = JsonSerializer.Serialize(status);
|
||||||
|
|
||||||
|
Console.WriteLine(json);
|
||||||
|
|
||||||
if (_hubConnection == null)
|
if (_hubConnection == null)
|
||||||
return;
|
return;
|
||||||
@@ -56,7 +66,7 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
|
|||||||
if (_hubConnection.State == HubConnectionState.Disconnected)
|
if (_hubConnection.State == HubConnectionState.Disconnected)
|
||||||
_hubConnection.StartAsync().Wait();
|
_hubConnection.StartAsync().Wait();
|
||||||
|
|
||||||
_hubConnection.InvokeAsync("SendLatestSample", response.Content).Wait();
|
_hubConnection.InvokeAsync("SendLatestSample", json).Wait();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user