Update ToVeproperty function. cleaner way.Comment need to be deleted in the futur
This commit is contained in:
parent
94c1324f06
commit
a602fc5eac
|
@ -18,39 +18,37 @@ public record Signal(Func<Iem3KGridMeterRegisters, object> Source, ObjectPath Pa
|
||||||
using InnovEnergy.Lib.Devices.IEM3kGridMeter;
|
using InnovEnergy.Lib.Devices.IEM3kGridMeter;
|
||||||
using InnovEnergy.Lib.Protocols.DBus.Protocol.DataTypes;
|
using InnovEnergy.Lib.Protocols.DBus.Protocol.DataTypes;
|
||||||
using InnovEnergy.Lib.Victron.VeDBus;
|
using InnovEnergy.Lib.Victron.VeDBus;
|
||||||
using System;
|
|
||||||
|
|
||||||
|
|
||||||
namespace InnovEnergy.App.SchneiderDriver
|
namespace InnovEnergy.App.SchneiderDriver
|
||||||
{
|
{
|
||||||
public record Signal(Func<Iem3KGridMeterRegisters, object> Source, ObjectPath Path, string Format = "")
|
public record Signal(Func<Iem3KGridMeterRegisters, Object> Source, ObjectPath Path, String Format = "")
|
||||||
{
|
{
|
||||||
// Converts the status object to a VeProperty, handling null status gracefully
|
// Converts the status object to a VeProperty, handling null status gracefully
|
||||||
public VeProperty ToVeProperty(Iem3KGridMeterRegisters status)
|
public VeProperty ToVeProperty(Iem3KGridMeterRegisters status)
|
||||||
{
|
{
|
||||||
// Check if status is null and log a message
|
// Check if status is null and log a message
|
||||||
if (status == null)
|
// if (status == null)
|
||||||
{
|
// {
|
||||||
Console.WriteLine($"Status is null for path: {Path}");
|
// Console.WriteLine($"Status is null for path: {Path}");
|
||||||
// Return a default VeProperty if status is null
|
// // Return a default VeProperty if status is null
|
||||||
return new VeProperty(Path, default(double), string.Format($"{{0:{Format}}}", default(double)));
|
// return new VeProperty(Path, default(double), string.Format($"{{0:{Format}}}", default(double)));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// // Retrieve the value using the provided source function
|
||||||
|
var value = Source(status);
|
||||||
|
//
|
||||||
|
// // Handle the case where the value itself might be null
|
||||||
|
// if (value == null)
|
||||||
|
// {
|
||||||
|
// Console.WriteLine($"Value is null for path: {Path}");
|
||||||
|
// // Return a default VeProperty if value is null
|
||||||
|
// return new VeProperty(Path, default(double), string.Format($"{{0:{Format}}}", default(double)));
|
||||||
|
// }
|
||||||
|
|
||||||
// Retrieve the value using the provided source function
|
if (value is Single floatValue)
|
||||||
var value = Source(status);
|
{
|
||||||
|
value = (Double)floatValue;
|
||||||
// Handle the case where the value itself might be null
|
}
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Value is null for path: {Path}");
|
|
||||||
// Return a default VeProperty if value is null
|
|
||||||
return new VeProperty(Path, default(double), string.Format($"{{0:{Format}}}", default(double)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value is float floatValue)
|
|
||||||
{
|
|
||||||
value = (double)floatValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and return the VeProperty with the actual value and format
|
// Create and return the VeProperty with the actual value and format
|
||||||
return new VeProperty(Path, value, string.Format($"{{0:{Format}}}", value));
|
return new VeProperty(Path, value, string.Format($"{{0:{Format}}}", value));
|
||||||
|
|
Loading…
Reference in New Issue